Xml XPath,返回包含特定元素的所有元素

Xml XPath,返回包含特定元素的所有元素,xml,xpath,Xml,Xpath,这是XML <?xml version="1.0" encoding="UTF-8"?> <bookstore> <book> <title lang="eng">Harry Potter</title> <price>29.99</price> <discount>3%</discount> </book> <book> <title

这是XML

<?xml version="1.0" encoding="UTF-8"?>

<bookstore>

<book>
  <title lang="eng">Harry Potter</title>
  <price>29.99</price>
  <discount>3%</discount>
</book>

<book>
  <title lang="eng">Learning XML</title>
  <price>39.95</price>
</book>

</bookstore>

哈利·波特
29.99
3%
学习XML
39.95

我无法计算XPath表达式,该表达式返回所有打折出售的书籍。

您想要任何打折的书籍:

//book[discount]

但是这个表单并不意味着折扣是一个属性?您的示例数据不显示折扣属性。如果你想得到更好的答案,请更新规范。如果我把@放在第一位,也许我能找到解决方案。是吗?@Tres:基本上是的。确切的XPath表达式取决于属性所在的位置。