如何使用 shellscript 解析 XML? [英] How to parse XML using shellscript?

查看:20
本文介绍了如何使用 shellscript 解析 XML?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道使用 shellscript 解析 XML 文件的最佳方法是什么?

  • 应该用手做吗?
  • 是否存在第三层库?

如果你已经做到了,请告诉我你是如何做到的

解决方案

你可以试试 xmllint<块引用>

xmllint 程序解析一个或多个XML 文件,在命令中指定作为 xmlfile 的行.它打印各种输出类型,取决于选择的选项.它适用于检测 XML 代码和在 XML 解析器中

它允许您通过 xpath 选择 XML 文档中的元素,使用 --pattern 选项.

在 Mac OS X (Yosemite) 上,它是默认安装的.
在 Ubuntu 上,如果尚未安装,您可以运行 apt-get install libxml2-utils

I would like to know what would be the best way to parse an XML file using shellscript ?

  • Should one do it by hand ?
  • Does third tiers library exist ?

If you already made it if you could let me know how did you manage to do it

解决方案

You could try xmllint

The xmllint program parses one or more XML files, specified on the command line as xmlfile. It prints various types of output, depending upon the options selected. It is useful for detecting errors both in XML code and in the XML parser itse

It allows you select elements in the XML doc by xpath, using the --pattern option.

On Mac OS X (Yosemite), it is installed by default.
On Ubuntu, if it is not already installed, you can run apt-get install libxml2-utils

这篇关于如何使用 shellscript 解析 XML?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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