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

Question:

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 that I use the expression:

string(//decision) = 'ACCEPT'

And the expression works, if I remove any of the namespaces from the document, the way it is, the expression always returns false because it can't get to the element's value.

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

PS: I've also tested it using XPath /root/body/checkCredit/CheckCreditOut/addresses/decision

Answer:

You can use the XPath local-name function:

/*[local-name() = 'checkCredit']/*[local-name() = 'CheckCreditOut']/*[local-name() = 'addresses']/*[local-name() = 'decision']
Scroll to Top
AllEscort