XML editing with Emacs.

I’ve been using GNU Emacs ever since I started working with the Fedora documentation team years ago. I wouldn’t call myself a power user by any means, but it handles my modest needs very well. Other people may have different preferences, which is fine. (Holy wars to /dev/null please.)

In the intervening years some really nice tools have evolved for dealing with different kinds of XML documents. I used to use the old psgml-mode to do editing of XML documents, but nowadays things are even more elegant and functional with nxml-mode. In truth, I was probably late to switch, simply because I didn’t have time to fix that which wasn’t broken.

However, ultimately psgml fell out of favor and the switch was necessary. But I discovered an array of helpful configurations that made XML editing even easier than before. I use these tools for editing DocBook XML, but they’re equally powerful for other schemas as well. For instance, you could use nxml-mode to hand-edit libvirt domain files with good confidence on their validity.

You can probably find directions like these (or even better) in a lot of places around the web. What I found difficult about the process was discovering the why as opposed to the what to do. How does all this stuff work, anyhow? None of the pages I read did a great job at explaining that. Admittedly, some of them were parts of much larger works, but I just wanted to get something done, not read an entire book. In writing the above page, I thought to myself, How can I improve this situation for the next person?

The key to solving that problem was this fantastic post by Mel Chua (and her lightning talk at FUDCon Tempe) where she talked about baking croissants. Short summary: it’s not enough to write a recipe and expect people to follow it, if your goal is to get people baking who aren’t bakers by trade. You have to take the time to fill in all the gaps.

So the result is this page I added to the Fedora wiki: How to use Emacs for XML editing.

Thanks, Mel, for the great advice. If anyone finds something wrong with that page, why bother commenting here? Just edit the wiki page if you’re a Fedora contributor (in other words, someone with an account and completed CLA). I’ll get notified when you do and everyone can benefit from your changes.

UPDATE: I revised the page slightly to give some needed background information up front and make it even more Mel-icious. Also I slightly edited this post to eliminate some awkwardness from where I rearranged text.

5 thoughts on “XML editing with Emacs.”

  1. Nice!! I’m using nxml-mode for my editing first steps with Publican. But i didn’t figured how to try the autocompletion of tags.

    I’m pretty sure i’m really going to try more advanced tasks in bugs of our documentation.

    Best regards.

  2. @Jesus: If Publican had its own schema for the DocBook tags it accepts — basically a definition for a subset of DocBook — you’d be able to limit the autocompletion just to valid Publican tags. Maybe this is something you want to ask the Publican upstream developers nicely for?

  3. Hi Paul,

    I had put together a post about using Emacs’ nxml-mode with Docbook5 and Mallard, but I like your tips better (I had people mucking around in the /usr/share… directories). The post is here: //j1m.net/2010/08/29/duck-duck-gnu-mallard-and-docbook-5-support-in-emacs/ , but I like yours better, and will probably link back to the Fedora wiki page that you’ve provided for easier, less-risky instructions.

    As a note, I found this page ( //infohost.nmt.edu/tcc/help/pubs/nxml/ ) helpful for getting started with actually writing XML documents with emacs.

    Thanks for your work on this. : )

  4. @Jim: Thanks for your comments! Remember, Linux is designed so that /usr could be a read-only file system. If you believe you have to muck around in /usr, you might want to try approaching the problem differently. Typically you should only need to do stuff in your home directory, and if you need to make system wide changes, they would go in /etc. Things in /usr are generally managed by system software management tools and not intended for manual tinkering.

Comments are closed.