ofXml problem, not closing tag

Hi, I’m new to xml. I am trying this code:

        string j = "jugador"+ofToString(numeroDeJugadores);
        scoresXml.addValue("nombre", nombreS);
        scoresXml.addValue("puntos", p);

And I get this:


The tag is not properly created, or is it? Shouldn’t it be:


What am I doing wrong?

By looking at http://openframeworks.cc/documentation/utils/ofXml/#show_setTo it seems like it should be scoresXml.setTo("jugador") so the last two addValue end up inside it. Why adding numeroDeJugadores?

I addd numeroDeJugadores because, eventually, it will be an array where I will store multiple “jugadores” (players) with “nombre” (name) and “puntos” (score), so I want to append to the xml file each time the game ends, and then I will display the highest scores. Thanks.

I see. My point is that you need to use the same tag name in both places: where you addChild, and where you setTo. If your child is jugador, but you try setTo with jugador7, then probably the setTo fails because there is no jugador7, and the next addValues end up next to jugador, not inside.

Could that be the reason?

Thank you very much for pointing me to the solution. I was missing some brackets:

string num = ofToString(numeroDeJugadores);
string j = “jugador[”+ num +"]";
scoresXml.addValue(“nombre”, nombreS);
scoresXml.addValue(“puntos”, p);