Note: I posted another question about this recently, but it was marked as duplicate because I didn't specify what I had tried clearly enough. I'll try to explain what I did better this time around.
Here's part of the XML file I'm trying to parse:
<entry>
<id>http://ift.tt/1s3DNQ0;
<updated>2010-04-11T12:47:03.281Z</updated>
<category scheme='http://ift.tt/qkaDoc' term='http://ift.tt/1aAtS8N'/>
<title type='text'>Name</title>
<link rel='http://ift.tt/1ajYb9K' type='image/*' href='http://ift.tt/1qnssXW'/>
<link rel='self' type='application/atom+xml' href='http://ift.tt/1qnsrTU'/>
<link rel='edit' type='application/atom+xml' href='http://ift.tt/1qnsteh'/>
<gd:email rel='http://ift.tt/1ajYb9O' address='email@email.com' primary='true'/>
</entry>
Here is my JavaScript code:
$("#importData").append("<ul>");
xmlDoc = $.parseXML(data);
$xml = $(xmlDoc);
$xml.find('entry').each(function () {
var name = $(this).find("title").text();
var email = $(this).find('[nodeName="gd:email"]').attr('address');
$("#importData").append("<li>" + name + " - " + email + "</li>");
});
//$(this).text() + " - " + $xml.find("gd:email[address]").index(i)
$("#importData").append("</ul>");
Here is a jsfiddle that attempts (unsuccessfully) to parse the XML: http://ift.tt/1pGbAKo
Here is another jsfiddle that successfully parses the XML with gd:email
replaced by gdemail
(no colon): http://ift.tt/1tu1jYb
I have tried various ways to parse my XML with namespaces, including [nodeName=gd:email]
, [nodeName="gd:email"]
, and gd\\:email
as all suggested by this StackOverflow question. However, none of them have worked successfully.
I don't know how I should approach this next. Other people with XML similar in structure to mine have claimed that the aforementioned methods work properly. However, the best I have gotten is an outputted value of "undefined". What am I doing wrong?
No comments:
Post a Comment