Parse XML info within a parent tag

Atottarty

New Member
I got an XML that looked like this:\[code\]<state1><county><villager>John Smith</villager><income>3000</income></county><county><villager>John Smith</villager><income>3500</income></county><county><villager>Peter Smith</villager><income>3100</income></county><county><villager>Paul Smith</villager><income>3200</income></county></state1><state2>. .</state2>\[/code\]I use these codes to parse the info now to HTML table:\[code\]<script>$(document).ready(function(){ $.ajax({ type: "GET", url: "election2008.xml", dataType: "xml", success: function(xml) { $(xml).find('county').each(function(){ var Col0 = $(this).find('villager').text(); var Col1 = $(this).find('income').text(); $('<tr></tr>').html('<td>'+Col0+'</td><td>'+Col1+'</td><td>'+Col2+'</td>').appendTo('#chart'); }); } });});</script>\[/code\]I wanted to only retrieve data inside State1 and output them to HTML. How do i do that? Currently my script parse ALL the info and put them together inside one big HTML table, but I wanted to only read state1 data. is it possible? thanks
 
Back
Top