在XPath中选择筛选节点集的属性

在XPath中选择筛选节点集的属性,xpath,Xpath,我正在尝试学习XPath语法。我在这里使用w3schools示例: …它基于以下XML: <?xml version="1.0" encoding="UTF-8""?> <bookstore> <book category="COOKING"> <title la="en">Everyday Italian</title> <author>Giada De Laurentiis</author>

我正在尝试学习XPath语法。我在这里使用w3schools示例:

…它基于以下XML:

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

<bookstore>

<book category="COOKING">
  <title la="en">Everyday Italian</title>
  <author>Giada De Laurentiis</author>
  <year>2005</year>
  <price>30.00</price>
</book>

<book category="CHILDREN">
  <title lang="en">Harry Potter</title>
  <author>J K. Rowling</author>
  <year>2005</year>
  <price>29.99</price>
</book>

</bookstore> 
而且,正如您在该站点上亲自测试所看到的,它不会产生任何输出。我做错了什么


谢谢您的时间。

查询没有问题。但由于您处理的是属性节点而不是元素,因此必须调整打印结果的代码。换行

document.write(nodes[i].childNodes[0].nodeValue);
document.write(result.childNodes[0].nodeValue);


您将得到预期的结果。

您的示例中没有价格>35的书籍。那是打字错误吗?啊哈!我差一点把头发拔了出来,没能用这么简单的例子!谢谢
document.write(nodes[i].childNodes[0].nodeValue);
document.write(result.childNodes[0].nodeValue);
document.write(nodes[i].nodeValue);
document.write(result.nodeValue);