I'm parsing an xml using jQuery (app in cordova/phonegap). To do so, I'm following this tutorial.
It all works fine but when it comes to nested tags. I have this example XML:
.....
<preguntas numero="2">
<pregunta tipo="TF" id="xxx" resta="false">
<enunciado>El cielo es azul?</enunciado>
<respuesta1>SI</respuesta1>
<respuesta2>NO</respuesta2>
<retro-pos>Eso esta bien</retro-pos>
<retro-neg>No esta bien</retro-neg>
</pregunta>
<pregunta tipo="DE" id="zzz" resta="false">
<enunciado>Desarrolla por favor:</enunciado>
<respuesta1>PUEDE</respuesta1>
<retro-pos>Gracias por participar</retro-pos>
<retro-neg>Gracias por participar una vez mas</retro-neg>
</pregunta>
</preguntas>
....
As you can see, I have 2 elements nested, and they can have different number of tags. When I try this in my js:
....
x=xmlhttp.response;
xmlDoc = $.parseXML( x );
$(xmlDoc).find("preguntas").each(function()
{
alert($(this).text()); // This shows contents of all "pregunta" correctly
alert($(this).find("enunciado").text()); // This shows ALL "enunciado" as one single string
}
....
How can I make it so it selects one "respuesta" at a time so I can get contents separately?
Thanks
Tiada ulasan:
Catat Ulasan