Reputation: 3
I've got the following below XML and would like to parse this with JQuery in Safari web browser. I just want to print out the userName and need some assistance with how the function would be written.
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ns3:Account xmlns:ns2="http://oec.api.opsource.net/schemas/organization" .. >
<ns3:userName>rdyer</ns3:userName>
<ns3:fullName>Joe Public</ns3:fullName>
<ns3:firstName>Joe</ns3:firstName>
<ns3:lastName>Public</ns3:lastName>
<ns3:emailAddress>[email protected]</ns3:emailAddress>
<ns3:orgId>1831c1a9-9c03-44df-a5a4-f2a4662d6bde</ns3:orgId>
<ns3:roles>
<ns3:role>
<ns3:name>primary administrator</ns3:name>
</ns3:role>
</ns3:roles>
</ns3:Account>
Upvotes: 0
Views: 1308
Reputation: 106322
Apparently $('ns3\\:userName',xml)
breaks down in jQuery 1.3.2 under webkit, but never fear, Sizzle has the power still, just filter on the attribute 'nodeName' try $('[nodeName=ns3:userName]',xml)
Example:
<div id='username'></div>
<script>
$(function() {
// When the DOM is ready - perform AJAX to get the XML:
$.get('/myxml.xml', {}, function(xml) {
var $username = $("[nodeName=ns3:userName]", xml);
// put the text from our node into the text of the empty div:
$("#username").text($username.text());
}, "xml");
});
</script>
Upvotes: 1