How to use jQuery for XML parsing with namespaces

后端 未结 20 1661
隐瞒了意图╮
隐瞒了意图╮ 2020-11-22 10:17

I\'m new to jQuery and would like to parse an XML document.

I\'m able to parse regular XML with the default namespaces but with XML such as:



        
20条回答
  •  孤城傲影
    2020-11-22 10:27

    jQuery 1.7 doesn't work with the following:

    $(xml).find("[nodeName=a:IndexField2]")
    

    One solution which I did get to work in Chrome, Firefox, and IE is to use selectors which work in IE AND selectors which work in Chrome, based on the fact that one way works in IE and the other in Chrome:

    $(xml).find('a\\\\:IndexField2, IndexField2')
    

    In IE, this returns nodes using the namespace (Firefox and IE require the namespace), and in Chrome, the selector returns nodes based on the non-namespace selector. I have not tested this in Safari, but it should work because it's working in Chrome.

提交回复
热议问题