gpt4 book ai didi

java - 如何使用 XPath 检查 XML 中是否存在元素?

转载 作者:数据小太阳 更新时间:2023-10-29 01:37:18 25 4
gpt4 key购买 nike

下面是我的元素层次结构。如何检查(使用 XPath)AttachedXml 元素是否存在于 Primary Consumer

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

如果primaryConsumerCreditReport中有AttachedXml,则返回真()

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

关于java - 如何使用 XPath 检查 XML 中是否存在元素?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5689966/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com