Question

For example:

<levels>
    <level id="1">
        <somestuff></somestuff>
    </level>
    <level id="2">
        <somestuff></somestuff>
    </level>
</levels>

How do you get the data of level with id 1? Now i am using pugi::xml_node level = levels.child("level") But that return all levels..

Regards, GJJ

Was it helpful?

Solution

levels.find_child_by_attribute("level", "id", "1")

OTHER TIPS

Try it:

for (pugi::xml_node ambil = doc.child("levels").child("level"); ambil; ambil = ambil.next_sibling("level"))
{
    int id = ambil.attribute("id").as_int();
    CCLog("%d",id);
}

foreach children & compare attribute value. e.g.

for (const auto& node : levels.children("level"))
{
    if (node.attribute("id").as_int() == 1)
    {
        // TODO: add ur code here
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top