How to make an XPath expression in an XML with multiple namespaces?

3

I have the following xml:

<root xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
    <body xmlns="http://www.foo.com/bar">
        <checkCredit>
            <CheckCreditOut>
                <nomeSerasa />
                <addresses>
                    <id>9-CAZ7QCU</id>
                    <decision>ACCEPT</decision>
                </addresses>
            </CheckCreditOut>
        </checkCredit>
    </body>
</root>

I want to validate the value of the decision element, for this I use the expression:

string(//decision) = 'ACCEPT'

And the expression works, if I remove any of the namespaces of the document, as it is, the expression always returns false because it can not reach the value of the element.

How do I correct the expression to work with 2 or more namespaces?

P.S: I also tested using XPath /root/body/checkCredit/CheckCreditOut/addresses/decision

    
asked by anonymous 27.07.2015 / 20:06

1 answer

0

You can use the local-name function of XPath:

/*[local-name() = 'checkCredit']/*[local-name() = 'CheckCreditOut']/*[local-name() = 'addresses']/*[local-name() = 'decision']
    
27.07.2015 / 20:31