Xmlstarlet: Difference between revisions

No edit summary
 
(4 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 99: Line 99:
[diaconicon](0) $</pre>
[diaconicon](0) $</pre>


===Subversion===
===[[Subversion]]===
<tt>svn log</tt> and <tt>svn status</tt> both accept the --xml command line option.<pre>[diaconicon](0) $ svn status --xml
<tt>svn log</tt> and <tt>svn status</tt> both accept the --xml command line option. See the [[subversion]] page for some recipes.<pre>[diaconicon](0) $ svn status --xml
&lt;?xml version="1.0"?&gt;
&lt;?xml version="1.0"?&gt;
&lt;status&gt;
&lt;status&gt;
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==
* [http://xmlstar.sourceforge.net/doc/UG/index.html XmlStarlet reference]