src/XMLDocumentConstructor.h
branchv_0
changeset 19 90f2b8ca32bf
parent 18 45c06bdf9045
child 26 80e129ec3408
equal deleted inserted replaced
18:45c06bdf9045 19:90f2b8ca32bf
    65 		xmlpp::Element* entry = currentSection->add_child(nameCodec.encode(event.fullKey));
    65 		xmlpp::Element* entry = currentSection->add_child(nameCodec.encode(event.fullKey));
    66 		entry->set_attribute("type", "entry");
    66 		entry->set_attribute("type", "entry");
    67 		entry->set_attribute("key", event.key);
    67 		entry->set_attribute("key", event.key);
    68 		entry->set_attribute("full-key", event.fullKey);
    68 		entry->set_attribute("full-key", event.fullKey);
    69 		if (event.subKey.size()) entry->set_attribute("sub-key", event.subKey);
    69 		if (event.subKey.size()) entry->set_attribute("sub-key", event.subKey);
    70 		if (event.comment.size()) currentSection->set_attribute("comment", event.comment);
    70 		if (event.comment.size()) entry->set_attribute("comment", event.comment);
    71 		if (event.lineNumber >= 0) currentSection->set_attribute("line-number", std::to_string(event.lineNumber));
    71 		if (event.lineNumber >= 0) entry->set_attribute("line-number", std::to_string(event.lineNumber));
    72 		if (event.eventNumber >= 0) currentSection->set_attribute("event-number", std::to_string(event.eventNumber));
    72 		if (event.eventNumber >= 0) entry->set_attribute("event-number", std::to_string(event.eventNumber));
    73 		entry->add_child_text(event.value);
    73 		entry->add_child_text(event.value);
    74 	};
    74 	};
       
    75 
       
    76 	void comment(const CommentEvent& event) override {
       
    77 		xmlpp::Element* comment = currentSection->add_child("comment");
       
    78 		comment->set_attribute("type", "comment");
       
    79 		if (event.lineNumber >= 0) comment->set_attribute("line-number", std::to_string(event.lineNumber));
       
    80 		if (event.eventNumber >= 0) comment->set_attribute("event-number", std::to_string(event.eventNumber));
       
    81 		comment->add_child_text(event.comment);
       
    82 	}
       
    83 
       
    84 	void whitespace(const WhitespaceEvent& event) override {
       
    85 		xmlpp::Element* comment = currentSection->add_child("whitespace");
       
    86 		comment->set_attribute("type", "whitespace");
       
    87 		if (event.lineNumber >= 0) comment->set_attribute("line-number", std::to_string(event.lineNumber));
       
    88 		if (event.eventNumber >= 0) comment->set_attribute("event-number", std::to_string(event.eventNumber));
       
    89 		comment->add_child_text(event.whitespace);
       
    90 	}
    75 
    91 
    76 };
    92 };
    77 
    93 
    78 // TODO: support also other styles/mappings e.g. <section/> and <entry/> with INI names only in the XML attributes (and thus without @type="section|entry")
    94 // TODO: support also other styles/mappings e.g. <section/> and <entry/> with INI names only in the XML attributes (and thus without @type="section|entry")
       
    95 // or map INI comments and whitespace to native XML comments and text nodes (but there will be no metadata like line/event numbers)
       
    96 // TODO: optional namespaces (xmlns)
    79 
    97 
    80 class XMLDocumentConstructor {
    98 class XMLDocumentConstructor {
    81 private:
    99 private:
    82 	std::istream* input = nullptr;
   100 	std::istream* input = nullptr;
    83 	xmlpp::DomParser* parser = nullptr;
   101 	xmlpp::DomParser* parser = nullptr;