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.

Posted by Nikolas Coukouma on 13 Jun 2005 @ 06:57pm UTC #
XMLStarlet is another tool:
$ xmlstar sel -N "f=http://www.w3.org/1999/XSL/Format" -t -v "//f:flow/f:inline/@id" foo.xml
bottom
$
Posted by Tobi on 20 Jun 2005 @ 12:07pm UTC #

P.S. Here's one way how it can be used from an editor:

howto/vimxml/moretasks.xml#questions

Posted by Tobi on 20 Jun 2005 @ 12:09pm UTC #

Other tools are xmlclitool or HTML-XML-utils.

Posted by Ismael Olea on 29 Dec 2006 @ 12:05am UTC #
Add a comment or subscribe to (existing and future) comments on this essay.
Name:
Email*:
 *Please provide your real email address; it will not be displayed as part of the comment.
Homepage:
Comment**:
 **The following markup may be used in the body of the comment: a, abbr, b, br, code, em, i, p, pre, strong, and var. You can also use character entities. Any other markup will be discarded, including all attributes (except href on a). Your tag soup will be sanitized...