ofXml problem, not closing tag

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

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

And I get this:

<database>
    <jugador/>
	<nombre>6TTUF3</nombre>
	<puntos>16439</puntos>
</database>

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

<database>
    <jugador>
	<nombre>6TTUF3</nombre>
	<puntos>16439</puntos>
   </jugador>
</database>

What am I doing wrong?
Thanks.

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:

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