Cant' read inside the xml structure (2 levels/2 for's) correctly with ofxXmlSettings

Hi,
i am having problems make work my code to read an xml like this:

<combo>
        <subCombo>
            <NUMsubCombo>0</NUMsubCombo>
            <LISTENsubComboStepNum>0</LISTENsubComboStepNum>
        </subCombo>
        <subCombo>
            <NUMsubCombo>1</NUMsubCombo>
            <LISTENsubComboStepNum>1</LISTENsubComboStepNum>
        </subCombo>
    </combo>
    <combo>
        <subCombo>
            <NUMsubCombo>0</NUMsubCombo>
            <LISTENsubComboStepNum>0</LISTENsubComboStepNum>
        </subCombo>
    </combo>
    <combo></combo>

As you can see, I want to explore (2 levels) all the subCombos inside a Combo. I am doing it like this, but i can’t make it work:

for (int i=0; i < 5; i++) { // i = comboPos
int logComboTAG = kitPresetsXML.pushTag(“combo”, i); // cd “combo”[i]

        for (int j=0; j < kitPresetsXML.getNumTags("subCombo"); j++) { // j = subComboPos
            int logSubComboTAG = kitPresetsXML.pushTag("subCombo", j); //cd "subCombo"[presetPos][comboPos/i][subComboPos/j]

            LISTENsubComboStepNum = kitPresetsXML.getValue("LISTENsubComboStepNum", 0);
            LISTENgenSubcombo = kitPresetsXML.getValue("LISTENgenSubcombo", 0);
            LISTENmutateREF = kitPresetsXML.getValue("LISTENmutateREF", 0);
            LISTENmutateMIN = kitPresetsXML.getValue("LISTENmutateMIN", 0);
            LISTENmutateMAX = kitPresetsXML.getValue("LISTENmutateMAX", 0);
            
            kitPresetsXML.popTag(); // test: sale del subCombo!
        }
        kitPresetsXML.popTag(); // test: sale del combo!

}
EDIT

In your snippet you are only pushing into combo once, but popping out repeatedly inside the for loop. If you you push into subCombo at the beginning of the loop it should work better.

Thanks theborg. Yes, i forgot to paste the push line, sorry. It was like this now, i edited the snippet.
So should work fine like thit i suppose… (Maybe it was working fine then, and my problem was in another place)

In other project i used the other ofxXml library and I remember it was easier for me.
Any idea of the differences or which one is better or recommended to use?

ofxXmlSettings is older. It was a simple way to put config values outside hard coded #define statements (people still do that?)

As such it works fine, but the ofXml is a more modern xml parser based on POCO. If you need to manipulate the XML DOM it is better suited.

1 Like