微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何检查xml中是否存在元素使用xpath?

下面是我的元素层次结构。如何检查(使用xpath)AttachedXml元素存在于主消费者的CreditReport下
<Consumers xmlns="http://xml.mycompany.com/XMLSchema">
       <Consumer subjectIdentifier="Primary">
          <DataSources>
               <Credit>
                   <CreditReport>
                      <AttachedXml><![CDATA[ blah blah]]>
使用 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

如果主消费者的CreditReport中有AttachedXml,那么它将返回true()。

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

原文地址:https://www.jb51.cc/xml/293628.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。