然后转到 XMLStarlet 主页下载最新的构建包(请参阅 参考资料)。运行 ./configure 脚本以便设置构建脚本,然后运行 make install 构建包并安装。如果您不是超级用户,应该使用 sudo make install 以便将命令安装到 system 目录中。
可能还需要访问 XML、XSLT 和 XML Path Language (XPath) 页面以便及时更新这三个标准,这对于充分利用 XMLStarlet 非常重要(请参阅 参考资料)。
安装完成后,现在可以对 XMLStarlet 做一番漫游了。首先不带参数运行 xml 命令(参见清单 1)。
% xml
XMLStarlet Toolkit: command-line utilities for XML
Usage: xml [] []
where is one of:
ed (or edit) - Edit/Update XML document(s)
sel (or select) - Select data or query XML document(s) (XPATH, etc)
tr (or transform) - Transform XML document(s) using XSLT
val (or validate) - Validate XML document(s) (well-formed/DTD/XSD/RelaxNG)
fo (or format) - Format XML document(s)
el (or elements) - Display element structure of XML document
c14n (or canonic) - XML canonicalization
ls (or list) - List directory as XML
esc (or escape) - Escape special XML characters
unesc (or unescape) - Unescape special XML characters
pyx (or xmln) - Convert XML into PYX format (based on ESIS - ISO 8879)
p2x (or depyx) - Convert PYX into XML
are:
--version - show version
--help - show help
Wherever file name mentioned in command help it is assumed
that URL can be used instead as well.
Type: xml --help for command help
XMLStarlet is a command line toolkit to query/edit/check/transform
XML documents (for more information see )
所有命令的基本格式为 xml ,后面跟一些选项。了解每个选项可以使用 xml --help 命令。比如,清单 2 显示了编辑(ed)命令的帮助。
% xml ed --help
XMLStarlet Toolkit: Edit XML document(s)
Usage: xml ed {} [ ... ]
where
- global options for editing
- input XML document file name/uri (stdin otherwise)
are:
-P (or --pf) - preserve original formatting
-S (or --ps) - preserve non-significant spaces
-O (or --omit-decl) - omit XML declaration ()
-N = - predefine namespaces (name without 'xmlns:')
ex: xsql=urn:oracle-xsql
Multiple -N options are allowed.
-N options must be last global options.
--help or -h - display help
where
-d or --delete
-i or --insert -t (--type) elem|text|attr -n -v (--value)
-a or --append -t (--type) elem|text|attr -n -v (--value)
-s or --subnode -t (--type) elem|text|attr -n -v (--value)
-m or --move
-r or --rename -v
-u or --update -v (--value)
-x (--expr) (-x is not implemented yet)
XMLStarlet is a command line toolkit to query/edit/check/transform
XML documents (for more information see )
这份帮助文件看起来很复杂,但最重要的部分在下面,可以看到如何删除、插入 XML 节点或者改变节点的值,等等。