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.
精彩评论