gpt4 book ai didi

xml - 需要用 xmlpath/xmlsearch 提取数据

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

我有这个 XML:

<?xml version="1.0" encoding="utf-8"?> 
<xml>
<site>
<id>123</id>
<po>BT123</po>
</site>
<order>
<shipping>
<shippingmethod>1</shippingmethod>
<firstname>Test</firstname>
<lastname>User</lastname>
<address>1234 My Place</address>
<address2>Apt 101</address2>
<city>Anytown</city>
<state>AL</state>
<zip>12345</zip>
</shipping>
<orderitems>
<item>
<isbn>9780752419930</isbn>
<rentalterm>1</rentalterm>
</item>
<item>
<isbn>0495599336</isbn>
<rentalterm>3</rentalterm>
</item>
<item>
<isbn>0743500210</isbn>
<rentalterm>2</rentalterm>
</item>
</orderitems>
</order>
</xml>

我想要做的是获取所有租期不是 2 的 ISBN
我知道如何获取所有 ISBN:
//item/isbn/text()

和具体的租赁条款:
//item[rentalterm!=2]

但我不确定如何将它们组合在一起。有什么建议么?

最佳答案

使用这个表达式:

//item[not(rentalterm='2')]/isbn/text()

英文:获取任意 isbn的文本节点其父元素是 item 的元素没有 rentalterm 的元素值等于 2 的 child

与此表达式对比:
//item[rentalterm!=2]/isbn/text()

...转换为:获取任何 isbn 的文本节点其父元素是 item 的元素具有至少一个 rentalterm 的元素值不等于 2 的 child .

换句话说,第二个表达式将不匹配 item没有 rentalterm 的元素 child ,但会匹配 item具有多个 rentalterm 的元素只要至少有一个不具有等于 2 的字符串值的 child .

换句话说,谓词 [not(rentalterm='2')]可以读为不包含 rentalterm字符串值等于 2 的 child , 而 [rentalterm!=2]应读作包含 rentalchild其字符串值不等于 2 .

spec describes it like this :

If one object to be compared is a node-set and the other is a string, then the comparison will be true if and only if there is a node in the node-set such that the result of performing the comparison on the string-value of the node and the other string is true.

关于xml - 需要用 xmlpath/xmlsearch 提取数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8522555/

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