Skip to content Skip to sidebar Skip to footer

Parse Xml With Namespaces Using Jquery And Working For All Browser ..

I'm trying to parse an XML response from a service using JQuery 1.11 At the moment my code works but only in Chrome, not for IE or Firefox and I need it works for all 'modern' brow

Solution 1:

You have to be careful with namespaces... if you work with XML that has some namespaces declaration you have to keep it in mind and build appropriate selectors.

For example:

$features = $('gml\\:featureMember, featureMember', $xmlData),

Please take a look on update fiddle. Now it works in FF and IE as well.

Solution 2:

This didn't worked for me, but I've found a working solution here:

http://jamesmcdonald.id.au/it-tips/google-chrome-xml-namespaces On above page we can find this:

$(xml).find('ns1\\:ld_det, ld_det');

Where 'ns1' is namespace such as gml, and 'ld_let' is node name.

And it works in Google Chrome too.

Solution 3:

In case if someone is facing issues parsing XML with namespaces in MS Edge browser, here is the workaround:

$.fn.filterNodeByPrefix = function(prefix) {
    returnthis.filter(function() {
        returnthis.prefix === prefix;
    });
};

We can use this function as:

$('gml\\:featureMember, featureMember', $xmlData).filterNodeByPrefix('gml');

Tried and tested in Chrome, FF, IE and MS Edge.

Post a Comment for "Parse Xml With Namespaces Using Jquery And Working For All Browser .."