ravun
ravun

Reputation: 1520

Parsing XML containing namespaces with jQuery (or JavaScript)

I've been working on a big jQuery project for a while and everything was going smoothly until I tried parsing XML with namespaces. I'm using jQuery 1.4.2 and I've tried a few different solutions:

$(xml).find('[nodeName=ns:blah]')...
$(xml).find('ns\\:blah')...

And I tried the jQuery.xmlns.js plugin but it doesn't seem to be working either.

The XML is formatted similar to:

<response xmlns:ns='http://example.com/ex/'>
  <response>SUCCESS</response>
  <action>QUERY</action>
  <data>
    <ns:blah>Trying to reach me!</ns:blah>
  </data>
</response>

Does anyone know of a solution, preferably using jQuery or a cross-browser Javascript implementation?

EDIT: Whoops, I was escaping the correctly in the code, just not in here. I've corrected it.

Upvotes: 1

Views: 697

Answers (1)

user113716
user113716

Reputation: 322492

Your escaping should look like this (backslashes):

$(xml).find('ns\\:blah')...

Example: http://jsfiddle.net/cUhZH/

Upgrade to the latest version of jQuery. I believe there some fixes in 1.4.3 with regard to selecting namespaced attributes.

Upvotes: 1

Related Questions