c++ rapidxml node_iterator 示例?

发布于 2024-08-18 17:43:24 字数 632 浏览 15 评论 0原文

我刚刚开始使用rapidXML,因为它是别人推荐给我的。现在,为了迭代多个兄弟姐妹,我这样做:

//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();
}

作为基本测试,它工作得很好。不管怎样,我遇到了node_iterator,它似乎是一个额外的迭代器类来为我做这件事。无论如何,我找不到任何有关如何使用它的示例,所以我想知道是否有人可以告诉我:)

谢谢!

I just started using rapidXML since it was recommended to me. 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. anyways, I could not find any example on how to use it, so I was wondering if some one could show me :)

thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

无人问我粥可暖 2024-08-25 17:43:24

我可以找到的 文档 没有 node_iterator 类型的文档。除了引用输出迭代器之外,我什至在该页面上找不到“迭代器”这个词,而您显然不想要它。

它可能是一个内部 API,或者是一个正在开发的 API,所以您现在最好不要使用它。

The documentation that I could find documents no node_iterator type. I can't even find the word iterator on that page except in reference to output iterators, which you clearly don't want.

It could be that it's an internal API, or one under development, so you're probably best not to use it right now.

爱你是孤单的心事 2024-08-25 17:43:24
#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;
} );
#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;
} );
伪装你 2024-08-25 17:43:24

没有RapidXml不提供任何迭代器。您的解决方案是要遵循的解决方案...手动使用函数first_node、next_sibling等...RapidXml被设计得轻巧而快速...即使程序员肯定会欣赏一些语法来帮助他:)

No RapidXml does not provide any iterator. 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 :)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文