0

XPath noob here again. I am getting this response from a Web Server. As you can see, all elements are true.

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns="urn:enterprise.soap.sforce.com">
   <soapenv:Header>
      <LimitInfoHeader>
         <limitInfo>
            <current>284</current>
            <limit>5000000</limit>
            <type>API REQUESTS</type>
         </limitInfo>
      </LimitInfoHeader>
   </soapenv:Header>
   <soapenv:Body>
      <createResponse>
         <result>
            <id>a05e00000042oZ1AAI</id>
            <success>true</success>
         </result>
         <result>
            <id>a06e0000008TWdlAAG</id>
            <success>true</success>
         </result>
         <result>
            <id>a06e0000008TWdmAAG</id>
            <success>true</success>
         </result>
      </createResponse>
   </soapenv:Body>
</soapenv:Envelope>

My question is, how would I be able to write a function, what would return a boolean variable based on if one or more of the success variables are false. Sort of like an AND gate.

I currently have:

//[contains(text(),'false')])

But this always returns false.

Any help would be appreciated.

user1472409
  • 397
  • 1
  • 7
  • 20
  • 3
    Before asking new questions, please take care of your previous ones. Some of your older questions have answers that you have not accepted or otherwise reacted to: e.g. http://stackoverflow.com/a/29500727/1987598, http://stackoverflow.com/a/28267699/1987598, http://stackoverflow.com/a/28116997/1987598, http://stackoverflow.com/a/26283752/1987598, http://stackoverflow.com/a/28544510/1987598 and http://stackoverflow.com/a/25146106/1987598. – Mathias Müller Apr 08 '15 at 17:23

1 Answers1

1

First of all, there is a namespace in this document that you need to take into account. But ignoring the namespace issue for now,

not(//*[local-name() = 'success'] = 'false')

is an XPath expression that returns a Boolean value. It returns true if there is no success element in the input document with a textual content of false. As soon as there is one element that looks like

<success>false</success>

the path expression returns false.

If you meant to test for the inverse condition, i.e. return true if there is at least one <success>false</success>, use

//*[local-name() = 'success'] = 'false'

Taking into account a namespace means to redeclare it in whatever programming language you are using, and prefix element names in XPath expressions.

Mathias Müller
  • 22,203
  • 13
  • 58
  • 75