XML Editing Shell
Nifty line editor for XML.
I stumbled upon the XML Editing Shell (xsh) a couple of weeks ago. As a command-line kind of guy, I was immediately intrigued. According to the author, Petr Pajas:
XSH is a powerfull command-line tool for querying, processing and editing XML documents. It features a shell-like interface with auto-completion for comfortable interactive work, but can be as well used for off-line (batch) processing of XML data. XSH makes extensive use of the XPath language, but system shell and the Perl programming language are both accessible from XSH as well, in a very natural way.
I stuck it in my tool belt thinking that I might one day use it for some batch editing, but I didn't really think I'd be using it all that frequently. I'm happy to do most of my XML editing in emacs.
Then this morning I got a useless error message from
xep. Something about fo:inline
not being
allowed in the context of fo:flow
. Yeah, well, of course it
isn't, but the message didn't provide any sort of clue about
where the offending fo:inline
actually
occurred. I took a quick peek at the FO file and the prospect of digging
through it looking for the error didn't fill me with joy.
Then I remembered xsh.
$ xsh
$scratch/> $f := open "nwn-uri.fo"
parsing nwn-uri.fo
done.
$f/> register-namespace fo "http://www.w3.org/1999/XSL/Format"
$f/> ls //fo:flow/fo:inline
<fo:inline id="bottom"/>
Found 1 node(s).
Problem solved. Well, found anyway. I'm sure some of the XML editors out there let you find things with XPath. And there are no doubt other tools that I could have used. And I could certainly have banged together an XSL stylesheet to find the error. But xsh was quick and easy. Well worth having in your tool belt.
Note to self: this is, of course, functionality I should have in emacs.
Comments
Alex Schroeder wrote an XPath tool for Emacs. You can find it here along with some other things.
P.S. Here's one way how it can be used from an editor:
howto/vimxml/moretasks.xml#questions
Other tools are xmlclitool or HTML-XML-utils.