为什么xmlstarlet没有选择所有节点?

sim*_*ico 3 xpath command-line-interface xmlstarlet exist-db

从w3schools考虑这个例子:

<?xml version="1.0" encoding="ISO-8859-1"?>

<bookstore>

<book category="COOKING">
  <title lang="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>

<book category="WEB">
  <title lang="en">XQuery Kick Start</title>
  <author>James McGovern</author>
  <author>Per Bothner</author>
  <author>Kurt Cagle</author>
  <author>James Linn</author>
  <author>Vaidyanathan Nagarajan</author>
  <year>2003</year>
  <price>49.99</price>
</book>

<book category="WEB">
  <title lang="en">Learning XML</title>
  <author>Erik T. Ray</author>
  <year>2003</year>
  <price>39.95</price>
</book>

</bookstore>
Run Code Online (Sandbox Code Playgroud)

xmlstarlet sel -t -v"// @ category"books.xml

仅返回COOKING.如何获取所有属性命名类别?

奖励问题:我如何评估XML文件的XPath查询,而无需在编辑器或程序中打开它(我想要一个快速工具).问题是将大文件加载到内存会导致编辑器崩溃.不要告诉我eXist是我最好的选择吗?

cor*_*sen 8

这是你需要的吗?

xml sel -t -m "//@category" -v "." -o " " books.xml
Run Code Online (Sandbox Code Playgroud)

或者在每一行分开结果

xml sel -t -m "//@category" -v "." -n books.xml
Run Code Online (Sandbox Code Playgroud)

更新

你是对的,你的XPath很好,你只需要不同的参数.