【发布时间】:2011-08-05 11:11:08
【问题描述】:
在上面的 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>
【问题讨论】:
-
好问题,+1。请参阅我对两种不同 XPath 2.0 解决方案的回答,其中第一种可能是最有效的,尤其是使用非优化的 XPath 2.0 引擎时。