简体   繁体   中英

pugixml - iterating over specific nodes

I have a xml document with a node which has children nodes but I want to iterate over specific nodes which names are stored in the array, for example:

const char* childrenNodes[]={"childNodeA", "childNodeC", "childNodeK"};

I can use next_sibling function which takes as an argument the element of the above array. Do you have any idea how to implement such loop using pugixml?

There are two overrides of next_sibling

xml_node next_sibling() const;
xml_node next_sibling(const char_t* name) const;

You're concentrating on the second one. Rather use the first one that doesn't take a parameter, and then just check if the node name is in the array

pugi::xml_node node = root.first_child();
for (; node; node = node.next_sibling()
{
    if (std::find(std::begin(childrenNodes), std::end(childrenNodes), node.name()) != std::end(childrenNodes))
    {
        // ...
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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