Monday, 8 December 2014

Find a line (and column) of xml_node in rapidxml



From what I could understand in the docs I deducted every xml_node knows it's position in the source text. What I'd like to do is to retrieve LINE and COLUMN for given xml_node<>*:



rapidxml::file<> xmlFile("generators.xml"); // Open file, default template is char

xml_document<> doc; // character type defaults to char
doc.parse<0>(xmlFile.data());; // 0 means default parse flags
xml_node<> *main = doc.first_node(); //Get the main node that contains everything
cout << "My first node is: <" << main->name() << ">\n";
cout << " located at line " << main->?????() << ", column " << main->?????() << "\n";


How should I retrieve those offsets? Could I somehow crawl from the main->name() pointer back to the beginning of the document? But how can I access the document string from xml_document<> doc to compare offsets?


No comments:

Post a Comment