Search code examples
xmlparsingxquerylibxml2libxml-js

Wierd XML not being parsed


I'm facing a strange problem with parsing xml with libxmljs. It's not my first XML to parse and I've done quite a number of them, but this one acts really strange.

I'm having these namespaces:

var nsUri = {
        "xmlns:SOAP-ENV": "http://schemas.xmlsoap.org/soap/envelope/",
        "xmlns:SIG": "https://sigtest.tais.ru/SIG/"
    };

And doing this:

var xmlDoc = xmljs.parseXml(providerResponse);
var ShopOptions = xmlDoc.find('//ShopOptions/ShopOption',self.provider.nsUri);

Which results in zero length array. I'm trying to go for different xquery stings: */ShopOption, //ShopOption etc. But nothing works out.


Solution

  • The <ShopOption/> element inherits the namespace of its <SIG_Response/> ancestor, https://sigtest.tais.ru/SIG/. You already declared that namespace, but also have to use it.

    //SIG:ShopOptions/SIG:ShopOption
    

    The other two queries you tried also don't use namespaces. */ShopOption looks for all second-level <ShopOption/> children starting at the current context, probably the root here; //ShopOption also searches for elements without namespace.