Xmlstarlet: Difference between revisions
| (2 intermediate revisions by the same user not shown) | |||
| Line 1: | Line 1: | ||
XMLStarlet is a command line tool for manipulation of XML. It exposes XPath, XSLT, and validation among many other capabilities. On FreeBSD, it is generally invoked as <tt>xml</tt> and is available from the Ports Collection in <tt>textproc/xmlstarlet</tt>; on Linux, it is generally invoked as <tt>xmlstarlet</tt> (throughout the rest of this article, I will use <tt>xml</tt>). XMLstarlet invocations take the form: <tt>xml command [command options] [filename]</tt>. It is intended for use within pipelines; any diagnostic output generated will be placed on stderr. To get help on a command, run <tt>xml command --help</tt>.<br> | XMLStarlet is a command line tool for manipulation of [[XML]]. It exposes XPath, XSLT, and validation among many other capabilities. On FreeBSD, it is generally invoked as <tt>xml</tt> and is available from the Ports Collection in <tt>textproc/xmlstarlet</tt>; on Linux, it is generally invoked as <tt>xmlstarlet</tt> (throughout the rest of this article, I will use <tt>xml</tt>). XMLstarlet invocations take the form: <tt>xml command [command options] [filename]</tt>. It is intended for use within pipelines; any diagnostic output generated will be placed on stderr. To get help on a command, run <tt>xml command --help</tt>.<br> | ||
<br> | <br> | ||
As more and more tools generate XML-based output ([[subversion]], [http://insecure.org/nmap nmap], etc), xmlstarlet becomes a useful and flexible tool for working with XML in a stream-editing context. | As more and more tools generate XML-based output ([[subversion]], [http://insecure.org/nmap nmap], etc), xmlstarlet becomes a useful and flexible tool for working with XML in a stream-editing context. | ||
| Line 146: | Line 146: | ||
===Counting=== | ===Counting=== | ||
Count all nodes in a document:<code>xml sel -t -v "count(//node())" | * Count all nodes in a document:<code>xml sel -t -v "count(//node())"</code> | ||
Count all occurrences of <tt>somenode</tt> nodes:<code>xml sel -t -v "count(//somenode)"</code> | * Count all occurrences of <tt>somenode</tt> nodes:<code>xml sel -t -v "count(//somenode)"</code> | ||
==See Also== | ==See Also== | ||
* [http://xmlstar.sourceforge.net/doc/UG/index.html XmlStarlet reference] | * [http://xmlstar.sourceforge.net/doc/UG/index.html XmlStarlet reference] | ||