简体   繁体   English

c ++ rapidxml node_iterator示例?

[英]c++ rapidxml node_iterator example?

I just started using rapidXML since it was recommended to me. 我刚开始使用rapidXML,因为它被推荐给我。 Right now to iterate over multiple siblings i do 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 fine. 作为基本测试,它工作正常。 Anyways, I came across node_iterator which seems to be an extra iterator class to do this for me. 无论如何,我遇到了node_iterator,这对我来说似乎是一个额外的迭代器类。 anyways, I could not find any example on how to use it, so I was wondering if some one could show me :) 无论如何,我找不到任何关于如何使用它的例子,所以我想知道是否有人可以告诉我:)

thanks! 谢谢!

The documentation that I could find documents no node_iterator type. 文件是我能找到的文档没有node_iterator类型。 I can't even find the word iterator on that page except in reference to output iterators, which you clearly don't want. 我甚至不能在该页面上找到iterator这个词,除非引用输出迭代器,你显然不想要它。

It could be that it's an internal API, or one under development, so you're probably best not to use it right now. 它可能是一个内部API,或者正在开发中的API,因此您最好不要立即使用它。

#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;
} );

No RapidXml does not provide any iterator. 没有RapidXml不提供任何迭代器。 Your solution is the one to be followed... manually using function first_node, next_sibling and so on... RapidXml is made to be light and fast... Even if a programmer would sure appreciate some syntax to help him :) 您的解决方案是要遵循的解决方案...手动使用函数first_node,next_sibling等等...... RapidXml变得轻巧快速...即使程序员肯定会欣赏一些语法来帮助他:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM