samedi 18 avril 2015

Modify std:cout - Renaming non standard tags

My program spits out XML nodes from a file. This is the bit of the code which does this:



for (auto& ea: mapa) {
std::cout << "Removed:" << std::endl;
ea.second.print(std::cout);
}

for (auto& eb: mapb) {
std::cout << "Added:" << std::endl;
eb.second.print(std::cout);
}


All nodes spat out should have this format (from filea.xml):



<entry>
<id><![CDATA[9]]></id>
<description><![CDATA[Dolce 27 Speed]]></description>
</entry>


However what is spat out depends on how the input data is formatted. Sometimes the tags are called different things and I could end up with this (from fileb.xml):



<entry>
<id><![CDATA[9]]></id>
<mycontent><![CDATA[Dolce 27 Speed]]></mycontent>
</entry>


Is it possible to define any non standard mappings (names of nodes) like this description = mycontent; so that, no matter what the names of the nodes are on the input file, I always std:cout it in the same format.


Effectively, before I std:cout the node, can I rename the tag based on a definition.


I'm new to C++ so any suggestions on how to implement this would be appreciated. I have to run this on tens of thousands of fields so performance is key.


Aucun commentaire:

Enregistrer un commentaire