📅  最后修改于: 2023-12-03 14:48:39.413000             🧑  作者: Mango
在XPath中,运算符用于在表达式中执行操作。XPath提供了以下类型的运算符:
以下是XPath中可用的算术运算符:
|运算符|描述| |-----|---| |+|加| |-|减| |*|乘| |/|除| |%|取模|
示例:
<bookstore>
<book>
<title>Harry Potter</title>
<price>29.99</price>
</book>
<book>
<title>Learning XML</title>
<price>39.95</price>
</book>
</bookstore>
/bookstore/book/price + 5
/bookstore/book[1]/price - 5
/bookstore/book/price * 2
/bookstore/book/price div 2
/bookstore/book[1]/price mod 13 = 0
以下是XPath中可用的关系运算符:
|运算符|描述| |-----|---| |=|等于| |!=|不等于| |<|小于| |>|大于| |<=|小于或等于| |>=|大于或等于|
示例:
<bookstore>
<book>
<title>Harry Potter</title>
<price>29.99</price>
</book>
<book>
<title>Learning XML</title>
<price>39.95</price>
</book>
</bookstore>
/bookstore/book[price > 30]
count(/bookstore/book[price = 29.99])
以下是XPath中可用的逻辑运算符:
|运算符|描述| |-----|---| |and|逻辑与| |or|逻辑或| |not|逻辑非|
示例:
<bookstore>
<book>
<title>Harry Potter</title>
<price>29.99</price>
</book>
<book>
<title>Learning XML</title>
<price>39.95</price>
</book>
</bookstore>
/bookstore/book[price < 30 or price > 40]
/bookstore/book[not(price = 30)]