简单的 Xpath 过滤器
Simple Xpath filter
我有一个简单的 XML,其中包含一个图书列表:
<catalog>
<book id="bk101">
<author>Gambardella, Matthew</author>
<title>XML Developer's Guide</title>
<genre>Computer</genre>
<price>9.95</price>
<publish_date>2000-10-01</publish_date>
<description>An in-depth look at creating applications
with XML.</description>
</book>
. . .
</catalog>
我想列出所有价格 <10 的图书。所以我构建了以下表达式:
/catalog/book//price < 10
当输入 XPath 测试器 window 时,返回 "True"。我希望有书单。
我该如何调整我的 XPath 表达式来修复它?
谢谢!
您的表达式是正确的,但它的计算结果为 布尔值,如您所见,该值要么为真,要么为假。您需要的是一个计算出一组节点的表达式:
/catalog/book[price < 10]
[
和]
之间的部分称为谓词,实际上是"filter"。
我有一个简单的 XML,其中包含一个图书列表:
<catalog>
<book id="bk101">
<author>Gambardella, Matthew</author>
<title>XML Developer's Guide</title>
<genre>Computer</genre>
<price>9.95</price>
<publish_date>2000-10-01</publish_date>
<description>An in-depth look at creating applications
with XML.</description>
</book>
. . .
</catalog>
我想列出所有价格 <10 的图书。所以我构建了以下表达式:
/catalog/book//price < 10
当输入 XPath 测试器 window 时,返回 "True"。我希望有书单。
我该如何调整我的 XPath 表达式来修复它?
谢谢!
您的表达式是正确的,但它的计算结果为 布尔值,如您所见,该值要么为真,要么为假。您需要的是一个计算出一组节点的表达式:
/catalog/book[price < 10]
[
和]
之间的部分称为谓词,实际上是"filter"。