I need to parse an XML response from a web service using JQuery
http://code.jquery.com/jquery-1.11.0.min.js
Here you are a sample of my XM
You can iterate through the XML elements using jQuery and find(), just like with HTML. When specifying tag names to select, you need to omit the namespace prefix in the selector.
var xmlText = $('#featureData').text(),
$xmlData = $.parseXML(xmlText),
$features = $('featureMember', $xmlData),
extractedFeatures = [];
$features.each(function () {
var $this = $(this),
feature = {},
items = [
'nome',
'civico',
'istat',
'cap',
'comune'
],
item;
for (var i = 0; i < items.length; i++) {
item = items[i];
feature[item] = $this.find(item).text();
}
extractedFeatures.push(feature);
});
$('#output').text(JSON.stringify(extractedFeatures));
See the jsFiddle reproduction here