Can XML be parsed reliably using jQuery's $(responseXML) syntax?

前端 未结 3 1939
有刺的猬
有刺的猬 2020-12-02 02:52

I\'m currently looking for an easy way to extract information from server XML responses using JavaScript. jQuery seems like a good candidate for this.

When it comes

3条回答
  •  星月不相逢
    2020-12-02 02:57

    I do not know if my experience can be generalized, but I had my share of problems parsing SOAP messages with jQuery. This is probably not down to jQuery (as you point out the documentation disrecommends it).

    Anyway, you asked for specifics: I found everything with namespaces to be problematic. Of course, for genuine namespace awareness, you'd need something that can resolve namespace prefixes to a namespace URI. I never expected jQuery to be able to do that, but even matching only prefixes didn't work out for me. This is especially problematic for me because the SOAP messages I am dealing with easily mix 4 or 5 namespaces. So I went back to doing DOM traversal myself to tackle this problem (which has its own set of problems)

    That said, I do expect jQuery to be able to handle xhtml documents (as long as the tag names aren't prefixed), and I would expect it to work too for other xml documents that do not use namespace prefixes.

提交回复
热议问题