A new XML-editing mode for Emacs

by Jason McIntosh

Related link: http://groups.yahoo.com/group/emacs-nxml-mode/

Long-time XML pioneer James Clark last month unveiled the alpha of nXML-mode, a new XML-editing major mode for Emacs. (Apparently no homepage yet, but it has a discussion group and a download site.) I've been using it for about a week, and it feels quite robust and featureful despite its early status. More importantly, it seems much more lightweight and "clean" than PSGML-mode, heretofore one of the best options for XML editing in Emacs, but one that carries the weight of years behind it, treating XML more as a variant of SGML than a markup language unto itself.

I feel that nXML's winningest feature is on-the-fly validation; feed it a schema, and the Emacs status bar will inform you whether or not the document is valid, and continuously update this information while you work. If it's invalid, the troublemaking characters get underlined in red, and the mode offers keystrokes to quickly browse through all the errorsome parts, with a description of each error appearing in the minibuffer as a tooltip. (If you don't load a schema, then the mode instead uses a built-in "vacuous schema" that simply checks for well-formedness.)

Loading a schema also gives you a context-sensitive auto-completion key binding. Like every other auto-completion tool in Emacs, one tap fills in as much as it can, and (if things are still ambiguous) two taps brings a Completion buffer containing every word that's legal at this point. Performing the latter action after typing "<" will give you a list of every legal element at the cursor's position. Very handy!

Interestingly, it validates only against RelaxNG schemas, and not DTDs. This sounds like it should be a deal-breaker (have you ever worked with anything other than DTDs before? Oh... well, I haven't), but the mode's README directs the user to trang, a Java-based conversion engine (and another Clark invention) that can easily turn DTD files into RelaxNG schema files. I've confirmed that it works great in the Mac OS X terminal, so it meets my needs, at least. I find this a very interesting and subversive way to draw people away from the crusty DTD spec ("Namespaces? What are those?") for document validation. (On the other hand, the mode already ships with RelaxNG files for both DocBook and XHTML, which is exactly I wanted to use it for.)

(Clark is best known to me as the developer of expat, the venerable XML-parsing library, nearly as old as XML itself but still quite popular; it's the core of the XML::Parser Perl module, for one thing. For more thoughts on XML::Parser, consult the green monkeys.)

Hacked XML with GNU lately?


2003-10-28 14:41:32
Warning: No XEmacs
When Mike Smith covered this for xmlhack (http://xmlhack.com/read.php?item=2061) I excitedly went to go see and hopefully play. No luck. I'm an XEmacs user and nXML is only available under GNU Emacs. See, for instance:


Still looking for a great RELAX NG-driven XML editor here, and still ready to pay for one (Topologi and Oxygen are somewhat close, but not close enough)


2003-10-29 03:23:40
James Clark
Has probably written more widely used software than any other person. When you type in "man foo" on pretty much any free Unix, or Mac OSX, you're using his groff suite of tools. When you visit the W3 validator, you're using his nsgmls parser. There's expat that you mention, which is embedded everywhere, including modern versions of apache.

In addition, he was one of the people who designed XSLT, and wrote one of the first implementations. He also wrote an implentation of its SGML predecessor, DSSSL (the package is called openjade these days).

Coming back to nxml-mode, I think Tim Bray had a very nice summary of why it's so impressive: