Is there a way to iterate over XML and only take the data between te tags you need? Now I have a XML file like this
<root>
<update country='Belgium'>
<new>
<id>484373</id>
<location>
<city>Antwerp</city>
<streetName>somewhere</streetName>
</location>
</new>
</update>
<update country='Netherland'>
<new>
<id>484323</id>
<location>
<city>Amsterdam</city>
<streetName>somewhere</streetName>
</location>
</new>
</update>
</root>
But I only want the data between <update country='Belgium'></update> for example.
Now i'm using following code. But it take all the tags.
<script>
$(xml).find('update').each(function(){
if($(this).attr('country') == 'Belgium'){
$(this).find('new').each(function(){
var id = $(this).find('id').text();
var city = $(this).find('city').text();
var streetName = $(this).find('streetName').text();
$('#content').append('<p>id = '+id+'</p>');
$('#content').append('<p>city = '+city+'</p>');
$('#content').append('<p>streetName = '+streetName+'</p><br/>');
});
}
});
</script>
Result
id = 484373
city = Antwerp
streetName = somewhere
id = 484323
city = Amsterdam
streetName = somewhere
No comments:
Post a Comment