Freitag, 6. Juni 2014

Using Saxon-HE as a XPath command line tool

Subversion can print the repository information in XML format.

svn info --xml

This makes it easy to extract the interesting parts in a Shell script, if an XPath tool is available. Newer versions of xmllint provide such a functionality. On those Systems which do not provide any suitable xmllint but provide a Java RE it is possible to use Saxon-HE. But the command line options are not very intuitive. The following example shows how to get the URL for the repository root.

saxon () { java -cp Saxon-HE-9.5.1-5.jar net.sf.saxon.Query "$@" ; }
xpath () { saxon '!method=text' -s:- -qs:"$1" ; }
svn info --xml | xpath '/info/entry/repository/root/text()'

The Saxon-HE JAR can be found in the Maven repository.

Keine Kommentare: