gpt4 book ai didi

xml - 如何使用 Xpath 选择具有多个类的元素?

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

在上面的 xml 示例中,我想使用 xpath 选择属于 foo 类而不属于 bar 类的所有书籍。

<?xml version="1.0" encoding="ISO-8859-1"?>
<bookstore>
<book class="foo">
<title lang="en">Harry Potter</title>
<author>J K. Rowling</author>
<year>2005</year>
<price>29.99</price>
</book>
<book class="foo bar">
<title lang="en">Harry Potter</title>
<author>J K. Rowling</author>
<year>2005</year>
<price>29.99</price>
</book>
<book class="foo bar">
<title lang="en">Harry Potter</title>
<author>J K. Rowling</author>
<year>2005</year>
<price>29.99</price>
</book>
</bookstore>

最佳答案

通过用前导和尾随空格填充 @class 值,您可以测试“foo”和“bar”的存在,而不用担心它是第一个、中间还是最后一个,以及对“食物”或“贫瘠”@class 值的任何误报:

/bookstore/book[contains(concat(' ',@class,' '),' foo ')
and not(contains(concat(' ',@class,' '),' bar '))]

关于xml - 如何使用 Xpath 选择具有多个类的元素?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5662404/

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