gpt4 book ai didi

xml - XPath 检查节点为空

转载 作者:行者123 更新时间:2023-12-03 17:02:44 26 4
gpt4 key购买 nike

使用XPath,如何检查节点或标签值是否为空?

给定示例 XML:

问题(以下需要 XPath 表达式):
1.如何检查ExceptionMessage1是否为空。
2.我将如何检查ExceptionMessage2 @nil == true?
3.如果会有ExceptionMessage3怎么办,可以是:
一个。包含异常信息
湾。没有消息,@nil="true"(组合的 ExceptionMessage1 和 ExceptionMessage2 行为)

<Envelope>
<Body>
<SellResponse>
<SellResult>
<ExceptionMessage1>JourneyManager.SellJourney(segment): Segment already booked under different class of service</ExceptionMessage1>
<ExceptionMessage2 nil="true"/>
<NSProcessTime>0</NSProcessTime>
<ProcessTime>0</ProcessTime>
<Booking nil="true"/>
<Success nil="true"/>
<Warning nil="true"/>
<Error nil="true"/>
<OtherServiceInformations nil="true"/>
</SellResult>
</SellResponse>
</Body>
</Envelope>

TIA

最佳答案

"check if ExceptionMessage1 is blank"

如果ExceptionMessage1 有子节点(非空白),则返回true,否则返回false:

not(//ExceptionMessage1/node())

"check if ExceptionMessage2 @nil == true"

我认为这很简单:

boolean(//ExceptionMessage2/@nil = 'true')

"With ExceptionMessage3, I want to check if it is not blank or nil=true"

如果有 ExceptionMessage3 不为空或属性 nil 等于 'true',则以下 XPath 返回 true:

boolean(//ExceptionMessage3[node() or @nil='true'])

如果上下文明确需要一个 bool 值,您也许可以省略 boolean() 调用。在这种情况下,转换将是自动的。

关于xml - XPath 检查节点为空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37158797/

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