Xmlstarlet: Difference between revisions

Created page with '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</t...'
 
No edit summary
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 shall 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 141: Line 141:
Delimited by spaces:
Delimited by spaces:
<code>xml sel -t -m //\*\[not\(\*\)\] -v . -o ' '</code>
<code>xml sel -t -m //\*\[not\(\*\)\] -v . -o ' '</code>
==Querying==
[[XPath]] can be used to programmatically explore XML.
===Counting===
Count all nodes in a document:<code>xml sel -t -v "count(//node())"
Count all occurrences of <tt>somenode</tt> nodes:<code>xml sel -t -v "count(//somenode)"</code>