views:

256

answers:

1

Hi there.

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>
+1  A: 

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>
gnarf
What if I didn't use jQuery? Any other options?
Simon
That method works with jQuery just fine (sizzle is a part of it) sorry if that was confusing... I'm unsure about non-jQuery ways of parsing it.
gnarf