How to check if an element exists in the xml using xpath?

后端 未结 6 1199
野性不改
野性不改 2020-12-08 18:47

Below is my element hierarchy. How to check (using xpath) that AttachedXml element is present under CreditReport of Primary

6条回答
  •  生来不讨喜
    2020-12-08 19:02

    Use the boolean() XPath function

    The boolean function converts its argument to a boolean as follows:

    • a number is true if and only if it is neither positive or negative zero nor NaN

    • a node-set is true if and only if it is non-empty

    • a string is true if and only if its length is non-zero

    • an object of a type other than the four basic types is converted to a boolean in a way that is dependent on that type

    If there is an AttachedXml in the CreditReport of primary Consumer, then it will return true().

    boolean(/mc:Consumers
              /mc:Consumer[@subjectIdentifier='Primary']
                //mc:CreditReport/mc:AttachedXml)
    

提交回复
热议问题