在上面的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”的存在,而不必担心它是第一个,中间还是最后,以及对“食物”的任何假阳性点击“barren”@class值:
/bookstore/book[contains(concat(' ',@class,' '),' foo ') and not(contains(concat(' ',' bar '))]
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。