简体   繁体   中英

Validate if the XML has a tag "string" using XQuery

I need to check if the xml has a "OperationResponse" in it and if yes, i need to perform some actions using XQuery. I tried few things and was not successfull. Below is an example of something that i tried.

Sample XML

<s:Envelope xmlns:s="http://examplens/soap/envelope/">
   <s:Body>
      <ns0:OperationResponse xmlns:ns0="urn:abcd:efgh:bc:1">
         <ns0:DocumentHeader>
            <ns0:Timestamp>2022-12-07T09:30:51+01:00</ns0:Timestamp>
            <ns0:MessageID>abcd</ns0:MessageID>
         </ns0:DocumentHeader>

Sample Code

let $response = xmlMessage.xml
if ( $response[Response[contains(text(),'OperationaResponse')]]  = 'true')
then
"SomeActions"

Expected Output A boolean value

Why not build the test into your XQuery:

if (.//ns0:OperationResponse)
then (: do your query :)
else () (: return nothing :)

You can try the following.

/s:Envelope/s:Body/ns0:*[local-name()="OperationResponse"]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM