diff options
-rw-r--r-- | Makefile.am | 1 | ||||
-rw-r--r-- | src/node.cc | 17 | ||||
-rw-r--r-- | src/node.h | 4 | ||||
-rw-r--r-- | src/textual.cc | 16 |
4 files changed, 21 insertions, 17 deletions
diff --git a/Makefile.am b/Makefile.am index 35144b8f..d99c2538 100644 --- a/Makefile.am +++ b/Makefile.am @@ -124,7 +124,6 @@ pkginclude_HEADERS = \ src/tuples.hpp \ src/utils.h \ src/value.h \ - src/xml.h \ src/xpath.h ############################################################################### diff --git a/src/node.cc b/src/node.cc index 390ef988..f19b5989 100644 --- a/src/node.cc +++ b/src/node.cc @@ -60,17 +60,22 @@ void output_xml_string(std::ostream& out, const string& str) } } -void parent_node_t::print(std::ostream& out) const +void node_t::print_attributes(std::ostream& out) const { - out << '<' << name(); if (attributes) { typedef attributes_t::nth_index<0>::type attributes_by_order; foreach (const attr_pair& attr, attributes->get<0>()) - out << ' ' << document().lookup_name(attr.first) + out << ' ' << *document().lookup_name(attr.first) << "=\"" << attr.second << "\""; } IF_VERIFY() out << " type=\"parent_node_t\""; +} + +void parent_node_t::print(std::ostream& out) const +{ + out << '<' << name(); + print_attributes(out); out << '>'; foreach (node_t * child, *this) @@ -83,13 +88,11 @@ void terminal_node_t::print(std::ostream& out) const { if (data.empty()) { out << '<' << name(); - IF_VERIFY() - out << " type=\"terminal_node_t\""; + print_attributes(out); out << " />"; } else { out << '<' << name(); - IF_VERIFY() - out << " type=\"terminal_node_t\""; + print_attributes(out); out << '>'; output_xml_string(out, text()); out << "</" << name() << '>'; @@ -102,8 +102,9 @@ public: return *polymorphic_downcast<const parent_node_t *>(this); } - virtual value_t to_value() const = 0; + virtual value_t to_value() const = 0; virtual void print(std::ostream& out) const = 0; + virtual void print_attributes(std::ostream& out) const; const char * name() const; nameid_t name_id() const { @@ -168,6 +169,7 @@ public: T * create_child(nameid_t _name_id) { T * child = new T(_name_id, document(), *this); children.push_back(child); + return child; } void delete_child(node_t * child) { diff --git a/src/textual.cc b/src/textual.cc index 82c8fcbf..ba720187 100644 --- a/src/textual.cc +++ b/src/textual.cc @@ -104,14 +104,14 @@ void parse_transaction(builder_t& builder, *e = '\0'; } - builder.begin_node(ACCOUNT_PATH_NODE); + builder.begin_node(ACCOUNT_PATH_NODE, true); builder.append_text(account_path); builder.end_node(ACCOUNT_PATH_NODE); // Parse the optional amount if (amount) { - builder.begin_node(AMOUNT_EXPR_NODE); + builder.begin_node(AMOUNT_EXPR_NODE, true); builder.append_text(amount); builder.end_node(AMOUNT_EXPR_NODE); } @@ -119,7 +119,7 @@ void parse_transaction(builder_t& builder, // Parse the optional note if (note) { - builder.begin_node(NOTE_NODE); + builder.begin_node(NOTE_NODE, true); builder.append_text(note); builder.end_node(NOTE_NODE); } @@ -246,7 +246,7 @@ void parse_entry(std::istream& in, builder.begin_node(ENTRY_NODE); - builder.begin_node(PAYEE_NODE); + builder.begin_node(PAYEE_NODE, true); assert(payee); builder.append_text(*payee != '\0' ? payee : "<Unspecified payee>"); builder.end_node(PAYEE_NODE, end_of_line); @@ -319,7 +319,7 @@ void textual_parser_t::parse(std::istream& in, builder.push_attr(TIME_ATTR, date); builder.push_attr(ACCOUNT_ATTR, p); - builder.begin_node(CHECKIN_NODE); + builder.begin_node(CHECKIN_NODE, true); builder.append_text(n); builder.end_node(CHECKIN_NODE, end_of_line); break; @@ -334,7 +334,7 @@ void textual_parser_t::parse(std::istream& in, builder.push_attr(TIME_ATTR, date); builder.push_attr(ACCOUNT_ATTR, p); - builder.begin_node(CHECKIN_NODE); + builder.begin_node(CHECKIN_NODE, true); builder.append_text(n); builder.end_node(CHECKIN_NODE, end_of_line); break; @@ -430,7 +430,7 @@ void textual_parser_t::parse(std::istream& in, case '=': { // automated entry builder.begin_node(AUTO_ENTRY_NODE); - builder.begin_node(RULE_NODE); + builder.begin_node(RULE_NODE, true); builder.append_text(skip_ws(line + 1)); builder.end_node(RULE_NODE); @@ -445,7 +445,7 @@ void textual_parser_t::parse(std::istream& in, case '~': // period entry builder.begin_node(PERIOD_ENTRY_NODE); - builder.begin_node(PERIOD_NODE); + builder.begin_node(PERIOD_NODE, true); builder.append_text(skip_ws(line + 1)); builder.end_node(PERIOD_NODE); |