开发者

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 tr开发者_如何学Cied 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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜