C++ parsing sub nodes of xml
<p>Well here I am again working on this open source game, anyway I made this parser for an xml file however I am unsure how to parse the vocation's children nodes, here is the code and the xml for the function, I want to be able to loop through its children, I assuming I need to create another for loop, however I am not quite sure how I should would reference vocation's child nodes, I am not concerned with their attributes atm.</p>

<pre><code>bool Game::loadCreatureAdditionalAttributes()
{
    pugi::xml_document data;
    pugi::xml_parse_result result = data.load_file("data/XML/attributes.xml");
    if (!result) {
        printXMLError("Error - Game::loadCreatureAdditionalAttributes", "data/XML/attributes.xml", result);
        return false;
    }
    bool attributesEnabled = false;
    for (auto attributeNode : data.child("attributes").children()) {
        if (strcasecmp(attributeNode.name(), "additionalAttributes") == 0) {
            if (attributeNode.attribute("enabled").as_bool()) {
                if (strcasecmp(attributeNode.name(), "vocation") == 0) {
                    pugi::xml_attribute vocation = attributeNode.attribute("id");
                    uint32_t aNode;
                    pugi::xml_attribute attr = attributeNode.attribute(attributeNode.name());
                    if (attr) {
                        aNode = pugi::cast&lt;uint32_t&gt;(attr.value());
                    }
                    else {
                        aNode = 0;
                    }
                    CreatureAttributes[pugi::cast&lt;uint32_t&gt;(vocation.value())][attributeNode.name()] = aNode;
                }
            }
        }
    }
    return true;
}
</code></pre>

<p>And now the xml</p>

<pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;attributes&gt;
    &lt;additionalAttributes enabled = "0" /&gt;
    &lt;vocation id = "1"&gt;
        &lt;attribute stamina = "1" /&gt;
        &lt;attribute strength = "1" /&gt;
        &lt;attribute intelligence = "1" /&gt;
        &lt;attribute dexterity = "1" /&gt;
        &lt;attribute wisdom = "1" /&gt;
        &lt;attribute luck = "1" /&gt;
        &lt;attribute critical = "1" /&gt;
        &lt;attribute block = "1" /&gt;
        &lt;attribute experienceGain = "1" /&gt;
        &lt;attribute power = "1" /&gt;
        &lt;attribute precision = "1" /&gt;
    &lt;/vocation&gt;
    &lt;vocation id = "2"&gt;
        &lt;attribute stamina = "1" /&gt;
        &lt;attribute strength = "1" /&gt;
        &lt;attribute intelligence = "1" /&gt;
        &lt;attribute dexterity = "1" /&gt;
        &lt;attribute wisdom = "1" /&gt;
        &lt;attribute luck = "1" /&gt;
        &lt;attribute critical = "1" /&gt;
        &lt;attribute block = "1" /&gt;
        &lt;attribute experienceGain = "1" /&gt;
        &lt;attribute power = "1" /&gt;
        &lt;attribute precision = "1" /&gt;
    &lt;/vocation&gt;
&lt;/attributes&gt;
</code></pre>

<p>Edit 1:</p>

<p>Haven't tested this just yet, but I thought I'd show an update based somewhat on the answer given.</p>

<pre><code>bool Game::loadCreatureAdditionalAttributes()
{
    pugi::xml_document data;
    pugi::xml_parse_result result = data.load_file("data/XML/attributes.xml");
    if (!result) {
        printXMLError("Error - Game::loadCreatureAdditionalAttributes", "data/XML/attributes.xml", result);
        return false;
    }

    auto attr = data.child("attributes").child("additionalAttributes");
    bool attributesEnabled = attr.attribute("enabled").as_bool();

    if (attributesEnabled) {
        for (auto vocation : data.child("attributes").children("vocation")) {
            uint32_t id = pugi::cast&lt;uint32_t&gt;(vocation.attribute("id").value());
            for (auto attribute : vocation.children("attribute")) {
                for (auto&amp; a : attribute.attributes()) {
                    CreatureAttributes[id][a.name()] = pugi::cast&lt;uint32_t&gt;(a.value());
                }
            }
        }
    }
    return true;
}
</code></pre>

<p>Not exactly sure if child to child is legal... but just throwing it out there lol</p>

<p>Edit 2:</p>

<p>Still haven't tested it yet, just updating it in case it doesn't work as expected.</p>

<pre><code>bool Game::loadCreatureAdditionalAttributes()
{
    pugi::xml_document data;
    pugi::xml_parse_result result = data.load_file("data/XML/attributes.xml");
    if (!result) {
        printXMLError("Error - Game::loadCreatureAdditionalAttributes", "data/XML/attributes.xml", result);
        return false;
    }

    auto attr = data.child("attributes").child("additionalAttributes");
    if (attr) {

        bool attributesEnabled = attr.attribute("enabled").as_bool();

        if (attributesEnabled) {
            for (auto vocation : data.child("attributes").children("vocation")) {
                uint32_t id = pugi::cast&lt;uint32_t&gt;(vocation.attribute("id").value());
                for (auto attribute : vocation.children("attribute")) {
                    for (auto&amp; a : attribute.attributes()) {
                        CreatureAttributes[id][a.name()] = pugi::cast&lt;uint32_t&gt;(a.value());
                    }
                }
            }
            return true;
        }
    }
    return false;
}
</code></pre>

<p>Just wanted to give an update for those having similar issues, the code works great!</p>

<pre><code>vocation id = 1 attributes = stamina value = 1
vocation id = 1 attributes = strength value = 45
vocation id = 1 attributes = intelligence value = 1
vocation id = 1 attributes = dexterity value = 1
vocation id = 1 attributes = wisdom value = 63
vocation id = 1 attributes = luck value = 1
vocation id = 1 attributes = critical value = 1
vocation id = 1 attributes = block value = 1
vocation id = 1 attributes = experienceGain value = 1
vocation id = 1 attributes = power value = 81
vocation id = 1 attributes = precision value = 1
vocation id = 2 attributes = stamina value = 100
vocation id = 2 attributes = strength value = 1
vocation id = 2 attributes = intelligence value = 20
vocation id = 2 attributes = farfenugen value = 1
vocation id = 2 attributes = stackoverflow value = 1000
</code></pre>

<p>Of course I changed the code a bit to make it work with other code I am working on, but the example code in <code>Edit 2</code> will work fine with an xml file similar in structure.</p>