C ++ quickxml node_iterator example?

I just started using rapidXML, as I was recommended. Right now, to sort through a few brothers and sisters, I am doing this:

//get the first texture node    
xml_node<>* texNode = rootNode->first_node("Texture");
if(texNode != 0){
    string test = texNode->first_attribute("path")->value();
    cout << test << endl;
}
//get all its siblings
while(texNode->next_sibling() != 0){
    string test = texNode->first_attribute("path")->value();
    cout << test << endl;
    texNode = texNode->next_sibling();
}

as a basic test, and it works great. Anyway, I came across a node_iterator, which seems to be an additional iterator class, to do this for me. Anyway, I could not find any example on how to use it, so I was wondering if anyone could show me :)

thanks!

+5
source share
3 answers

, node_iterator. iterator , , .

, API , , , .

+2
#include "rapidxml/rapidxml.hpp"
#include "rapidxml/rapidxml_utils.hpp"
#include "rapidxml/rapidxml_iterators.hpp"

...

rapidxml::xml_document<wchar_t> doc;
doc.parse<0>(xmlFile.data());

rapidxml::node_iterator< wchar_t > begIt( doc.first_node());
rapidxml::node_iterator< wchar_t > endIt;

...

std::for_each( begIt, endIt, [] (rapidxml::xml_node< wchar_t >& node)
{
    std::wcout << node.name() << std::endl;
} );
+2

RapidXml . - , ... first_node, next_sibling ..... RapidXml , ... - , :)

+1

All Articles