xml | skybert.net



XML development in Emacs

I will on this page describe how I use GNU Emacs as a powerful XML editor using the excellent nxml-mode.

On this page, you'll learn how you can:

Auto completion of elements and attributes

Out of the box,nxml-mode will do auto completion for XHTML and Docbook documents. It can support any other XML format, as long as it can find anRNC file to describe it. Here, I'm getting auto completion of elements in a Mavenpom.xml file:

auto complete

On the fly syntax checking

Emacs will also give you on the fly syntax checking. Here, I am editing an Ant build file, where I've added an illegal attribute:

ant and nxml-mode

Setting it all up

Installing trang & rngconv

nxml-mode instists on using the RNC format. Hence, you need to convert your XSDs and DTDs to RNC, whichnxml-mode can use.

You need two pieces of software, rngconv to convert fromXSD to RNG and trang to convert fromRNG (or DTD) to RNC. As you might have guessed, rngconv is only needed if you've got an XSD as Trang can deal with DTDs.

Trang & RNGConv might be available in your system's software repository, such as Debian SID, if not, this is how to install it manually:

$ cd /tmp/
$ wget http://jing-trang.googlecode.com/files/trang-20081028.zip
$ wget https://msv.dev.java.net/files/documents/61/31333/rngconv.20060319.zip
$ cd /opt/
$ unzip /tmp/trang-20081028.zip
$ ln -s trang-20081028 trang
$ unzip /tmp/rngconv.20060319.zip
$ ln -s rngconv.20060319 rngconv

Creating RNCs from W3C XML Schemas

This is how I convert the Maven POM XML Schema to RNC:

$ cd ~/library/xml/
$ wget http://maven.apache.org/maven-v4_0_0.xsd
$ java -jar /opt/rngconv/rngconv.jar maven-v4_0_0.xsd > maven-v4_0_0.rnc
$ java -jar  /opt/trang/trang.jar \
  -I rng \
  -O rnc \
  maven-v4_0_0.rng maven-v4_0_0.rnc

Converting DTDs to RNCs

This is how I created an RNC for Antbuild.xml files. First, I created a DTD from wiki.apache.org

$ java -jar  /opt/trang/trang.jar -I dtd -O rnc ant-1.6.dtd ant-1.6.rnc

Download my RNC files

To save you some hassle, you may download my RNC files here.

Make nxml-mode use these RNC files

This is my ~/.emacs.d/schemas.xml which nxml-mode will look in to find schema mappings outside its standard set (which includes Docbook, XHTML).

gmail torstein.k.johansen @ gmail ~ twitter @torsteinkrause ~