Reputation: 232
Hello I'm a noob and practicing getting XML and parsing it.
The problem is that I think I am thinking too much in "JSON".
Can anyone show me how to make it work? Thanks.
http://jsfiddle.net/NJMyD/1066/
var xmlString = "<note><to>Tove</to><from>Jani</from><heading>Reminder</heading><body>Don't forget me this weekend!</body></note>';
var myXmlData = $.parseXML(xmlString);
$(document).ready(function() {
$.each(myXmlData, function() {
$('<li>' + this.from + '</li>').appendTo("#groups");
});
});
Upvotes: 0
Views: 35
Reputation: 5402
You are not parsing your XML
variable correctly. Here is the Solution for fiddle 1:
var xmlString = "<note><to>Tove</to><from>Jani</from><heading>Reminder</heading><body>Don't forget me this weekend!</body></note>";
var myXmlData = $.parseXML(xmlString),
$xml = $(myXmlData),
$title = $xml.find( "from" );
$.each($xml, function(index) {
$('<li>' + $title.text() + '</li>').appendTo("#groups");
});
Demo: http://jsfiddle.net/NJMyD/1069/
Upvotes: 1