Parsing a XML atribute with JQuery -
i have been trying parse xml response web service. example of returning.
var xml = "<?xml version='1.0' encoding='utf-8'?><campaign guid='799223b1-24a7-4f01-8dae-632e6f68f845'><leaderboard><target rank='1' totalscore='138000' firstname='shane' lastname='foster' targetcompanyname='[acme]' displayname=''>hello world</target></leaderboard></campaign>", xmldoc = $.parsexml(xml), $xml = $(xmldoc), $title = $xml.find("target"); alert($title.text());
this works, want values of attributes. try adding:
$title = $xml.find("target").attr("totalscore");
but nothing back. ideas?
you trying element's value instead of attribute's value added var when .attr();
try this:
<script> var xml = "<?xml version='1.0' encoding='utf-8'?><campaign guid='799223b1-24a7-4f01-8dae-632e6f68f845'><leaderboard><target rank='1' totalscore='138000' firstname='shane' lastname='foster' targetcompanyname='[acme]' displayname=''>hello world</target></leaderboard></campaign>", xmldoc = $.parsexml(xml), $xml = $(xmldoc), $title = $xml.find("target").attr("totalscore"); alert($title); </script>
Comments
Post a Comment