XMLStarlet is a set of command line utilities to query, transform, validate, and edit XML documents and files using a simple set of shell commands in a way similar to how it is done with UNIX grep, sed, awk, diff, patch, join, etc commands. This set of command line utilities can be used by those who want to test XPath query or execute commands on the fly as well as deal with many XML documents or for automated XML processing with shell scripts. To run XMLStarlet utility you can download it from the official site, then simply type '' on the command line with the corresponding commands or queries to execute.
Features
The toolkit's feature set includes the following options:
Check or validate XML files
Calculate values of XPath expressions on XML files
Search XML files for matches to given XPath expressions
The XMLStarlet command line utility is written in C and uses libxml2 and libxslt from http://xmlsoft.org/. Implementation of extensive choice of options for XMLStarlet utility was only possible because of rich feature set of both libraries: libxml2 and libxslt. XMLStarlet is linked statically to both libxml2 and libxslt, so generally all you need to process XML documents is one executable file. XMLStarlet is open sourcefree software released under an MIT License which allows free use and distribution for both commercial and non-commercial projects.
Examples
Consider the following XML document 'xmlfile1.xml' example:
On a command prompt the following five XPath queries are executed on the above XML file 'xmlfile1.xml'.
Example 1: The XPath expression to select all name attributes for all projects.
$ xml sel -t -v "//wikimedia/projects/project/@name" xmlfile1.xml Wikipedia Wiktionary Wikileaks
Example 2: The XPath expression to select all attributes of the last Wikimedia project.
$ xml sel -t -v "/wikimedia/projects/project/@*" xmlfile1.xml Wikileaks 2006-10-04
Example 3: The XPath expression to select addresses of all Wiktionary editions.
$ xml sel -t -v "/wikimedia/projects/project/editions/edition" xmlfile1.xml en.wiktionary.org fr.wiktionary.org vi.wiktionary.org tr.wiktionary.org es.wiktionary.org
Example4: The XPath expression to select addresses of all Wikimedia Wiktionary editions that have languages different from Turkish and Spanish.
$ xml sel -t -v "/wikimedia/projects/project/editions/edition" xmlfile1.xml en.wiktionary.org fr.wiktionary.org vi.wiktionary.org
Example 5: The XPath expression to select all attributes of editions whose position is greater or equal to 3 in the list of editions.
$ xml sel -t -v "/wikimedia/projects/project/editions/edition/@*" xmlfile1.xml French Polish Spanish Vietnamese Turkish Spanish
An XML document can be validated against an XSD schema saved in file 'xsdfile.xsd' as follows: $ xml val -e -s xsdfile.xsd xmlfile1.xml xmlfile1.xml - valid