jQuery not parsing nested XML correctly -


i'm parsing data xml looks this:

<departuresdata>  <station>    <id>29411</id>    <name>kúpalisko matador</name>    <distance>182</distance>    <vehicle>      <number>180</number>      <time>10:26</time>      <time>10:56</time>      <target>holíčska</target>      <lineid>289</lineid>      <type>bus</type>    </vehicle>    <vehicle>      <number>180</number>      <time>10:17</time>      <time>10:47</time>      <target>cintorín petržalka</target>      <lineid>288</lineid>      <type>bus</type>    </vehicle>  </station>  <station>    <id>30122</id>    <name>kúpalisko matador</name>    <distance>201</distance>    <vehicle>      <number>80</number>      <time>10:09</time>      <time>10:33</time>      <target>kollárovo nám.</target>      <lineid>220</lineid>      <type>bus</type>    </vehicle>    <vehicle>      <number>80</number>      <time>10:02</time>      <time>10:26</time>      <target>kúpalisko matador</target>      <lineid>222</lineid>      <type>bus</type>    </vehicle>  </station>  <departuresdata> 

and parsing jquery looks like:

success: function(xml) {  $(xml).find("station").each(function()   {      //vydolovanie hodnot     var name = $(this).find("name").text();     var distance = $(this).find("distance").text();     $("#response").append("zastavka:" + name + "<br />vzdialenost:" + distance + "<br />");  //vypis      $(this).find("vehicle").each(function(){          var number = $(this).find("number").text();         var target = $(this).find("target").text();         var type = $(this).find("type").text();              $("#response").append("linka cislo: " + number + "<br />smer: " + target + "<br />druh: " + type + "<br />Časy:<br />");         $(this).find("time").each(function()         {             $("#response").append($(this).text() + "<br />"); //vypis         });          $("#response").append("1<br /><br />"); //vypis      });      $("#response").append("<br />");   }); 

}

but comes distance, , when has each vehicle part reason can't info in number, time , on. , not loops through vehicle tags in 1 station tag.

output looks like:

zastavka:kúpalisko matador vzdialenost:198 linka cislo:  smer:  druh:  Časy:  1   zastavka:kúpalisko matador vzdialenost:201 linka cislo:  smer:  druh:  Časy:  1 

actually, on looking closer, first output:

vzdialenost:198  

states distance 198. however, xml not have distance of 198. there's

<distance>182</distance>  

and

<distance>201</distance>  

so either you've pasted wrong question or you're not reading right xml.


Comments

Popular posts from this blog

python - Scipy curvefit RuntimeError:Optimal parameters not found: Number of calls to function has reached maxfev = 1000 -

c# - How to add a new treeview at the selected node? -

java - netbeans "Please wait - classpath scanning in progress..." -