gpt4 book ai didi

匹配属性值 "true"的 XPATH 表达式

转载 作者:行者123 更新时间:2023-12-03 15:28:49 24 4
gpt4 key购买 nike

我有一些这样的 XML:

<engine-set>
<engine host-ref="blah1.com">
<property name="foo" value="true"/>
<property name="bar" value="true"/>
</engine>
<engine host-ref="blah2.com">
<property name="foo" value="true"/>
<property name="bar" value="false"/>
</engine>
</engine-set>

我想匹配所有具有名称等于“bar”且值等于“true”的子节点属性的引擎元素。我发现“true”出现在我的 XML 中的事实导致我的条件在 XPath 表达式中总是评估为真。有办法吗?我正在使用 Python 和 lxml。

编辑:

我的 xpath 表达式是(不起作用)是:
//engine[(property/@name='bar' and property/@value="true")]

谢谢,

最佳答案

I want to match on all engine elements



这是:
//engine

that have a child node property



现在这变成了:
//engine[property]

with a name equal to "bar"



更具体的:
//engine[property[@name = 'bar']] 

and and value equal to "true".



最后:
//engine[property[@name = 'bar' and @value = 'true']] 

关于匹配属性值 "true"的 XPATH 表达式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9520870/

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