jquery unable to get XML attribute value [duplicate]




This question already has an answer here:




Edit: This question is not a duplicate. Before posting I found the tried the methods mentioned in the "duplicated" question, without success. I find this very strange, because the structure of the XML code is essentially identical. However, neither gd\\:email nor [nodeName="gd:email"] have worked for me.


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>");


So far I am able to successfully get the name of each contact as defined in the name variable. However, I am unable to get the email address from the gd:email node. The email variable displays text of "undefined".


How can I get the data from the address attribute of the gd:email node?


No comments:

Post a Comment