drewfrisk
drewfrisk

Reputation: 461

Using XPath to Check if Soap Envelope Contains Child Node

I'm trying to determine if a soap envelope body contains a particular node.

An example of the envelope I'm working with:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
    <soapenv:Body>
        <Response>
            <Result>Failure</Result>
            <Error id="40020" value="">An Unkown Error Occured</Error>
        <Response>
    </soapenv:Body>
</soapenv:Envelope>

I want to check if the contains the node "Response" so I can perform conditional operations on it as a result. I'm relatively new to XPath, so I'm not sure what the full expression should be.

The XPath expression I currently have is

[name(//soapenv:Body/*[1]) = 'Response']

I know name(//soapenv:Body/*[1]) will return the value of "Response", I just don't know how to compare that result to another value and return true/false.

Maybe something like this as an alternative expression?

//soapenv:Body/*[contains(Name, "Response")]

Upvotes: 2

Views: 3296

Answers (1)

Sten Petrov
Sten Petrov

Reputation: 11040

Try these:

//soapenv:Body/*[name()='Response']

Or if Response can be deeper than just child of Body (should not be the case)

//soapenv:Body/descendant::*[name()='Response']

Upvotes: 1

Related Questions