How to use jQuery for XML parsing with namespaces

后端 未结 20 1658
隐瞒了意图╮
隐瞒了意图╮ 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:42

    As mentioned above, there are problems with the above solution with current browsers/versions of jQuery - the suggested plug-in doesn't completely work either because of case issues (nodeName, as a property, is sometimes in all upper case). So, I wrote the following quick function:

    $.findNS = function (o, nodeName)
    {
        return o.children().filter(function ()
        {
            if (this.nodeName)
                return this.nodeName.toUpperCase() == nodeName.toUpperCase();
            else
                return false;
        });
    };
    

    Example usage:

    $.findNS($(xml), 'x:row');
    

提交回复
热议问题