xmlstarlet为什么不选择所有节点? [英] Why doesn't xmlstarlet select all nodes?

查看:76
本文介绍了xmlstarlet为什么不选择所有节点?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

考虑来自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>




xmlstarlet sel -t -v // @类别
books.xml

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

仅返回烹饪。

BONUS问题:如何在不通过编辑器或程序的情况下不针对XML文件打开XPath查询(我想要一个快速的工具) )。问题是将大文件加载到内存会使编辑器崩溃。

BONUS question: how do I evaluate XPath queries against an XML file without opening it in an editor nor program (I want a quick tool). The issue is that loading the huge file into memory crashes the editor. Don't tell me that eXist is my best bet?

推荐答案

这是您需要的吗?

xml sel -t -m "//@category" -v "." -o " " books.xml

或在每行中分隔结果

xml sel -t -m "//@category" -v "." -n books.xml

更新

您是对的,您的XPath很好,只需要其他参数即可。

You're right, your XPath was good, you just need different parameters.

这篇关于xmlstarlet为什么不选择所有节点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆