Get list of second elements from an XML file using Jquery

gonchan

New Member
I have an xml file and i wanted to read only the second level elements from the list. For example i want to have a list of only the vehicles such as followsVehicle Number: "180", Type : "BUS"Vehicle Number: "190", Type: "BUS"..............This is my xml format\[code\]<departures> <station> <vehicle> <number>180</number> <type>BUS</type> </vehicle> <vehicle> <number>190</number> <type>BUS</type> </vehicle> </station> <station> <vehicle> <number>290</number> <type>BUS</type> </vehicle> <vehicle> <number>380</number> <type>BUS</type> </vehicle> </station> <departures>\[/code\]This is the javascript part\[code\]$(document).ready(function(){ $.ajax({ type: "GET", url: XML_PATH, dataType: "xml", success: function(xml) { $("#update-target").empty(); $(xml).find("station").each(function () { $("#update-target").append('<ul>'); $(this).find("vehicle").each(function () { var number = $(this).find('number').text(); var type = $(this).find('type').text(); $("#update-target ul").append('<li>' + type + number + '</li>'); }); }); }, }); });\[/code\]On running the above code, i'm not getting any output. Please what is the right way to do this. Thanks
 
Back
Top