0

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

1 Answer 1

1

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>
Sign up to request clarification or add additional context in comments.

2 Comments

What if I didn't use jQuery? Any other options?
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.