jQuery's parseXML fails (invalid XML) when using namespaces

1.1k Views Asked by At

If I try the following:

var xmlObject = $($.parseXML('<foo xs:type="one type">bar</foo>'));

jQuery returns a parsing error:

Invalid XML: <foo xs:type="onetype">bar</foo> - { "stack": ".error@http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js:3 .parseXML@http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js:3

But if I try:

var xmlObject = $($.parseXML('<foo xs-type="one type">bar</foo>'));

it works fine. In my current development, I will call a server and get the xml result as a string. And this string will contain namespaces like xs:type. Then I'll have to parse the xml and do some other stuff with the results. Do I have to remove all the colons from the string before parsing it with parseXML? Is there any workaround for this?

0

There are 0 best solutions below