2

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")]
drewfrisk
  • 451
  • 7
  • 17

1 Answers1

1

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']
Sten Petrov
  • 10,943
  • 1
  • 41
  • 61
  • perfect! that did exactly what I needed. the first of the two examples worked -- I should never have the Response node deeper than the first child. – drewfrisk Apr 22 '13 at 20:34
  • was getting around to it, you originally posted within the 10 minute threshold I had to wait to mark as the answer. – drewfrisk Apr 22 '13 at 21:24