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...' |
|||
| (5 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 | 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 | ||
<?xml version="1.0"?> | <?xml version="1.0"?> | ||
<status> | <status> | ||
| 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())"</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] | |||