You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 4 Next »

Author: ~blee

Introduction

nXML Mode is a major mode for GNU Emacs which provides guided editing of XML documents based on an associated schema. Like other major modes (e.g. c-mode, etc.) it also provides features like syntax highlighting and automatic indentation.

Installation

nXML mode is not available in the centralized Emacs site-lisp configuration at the moment, so you'll need to install it into your home directory. Once it's a part of Central Unix, we'll update these instructions so you can use the managed installation.

  • Download the distribution. Windows users can retrieve nxml-mode-20041004.zip, which already includes the pipeline schema.
  • Unpack the tarball to a convenient directory, such as the one where you keep your other Emacs extensions. In these instructions, we'll use ~/site-lisp as the installation path.
  • For ease of upgrading, symlink the version-specific directory name to the generic name 'nxml'
  • Add the following lines to your .emacs file:
;; Add the nxml files to the search path for loading
(setq load-path
      (append load-path
              '("~/site-lisp/nxml/")))

;; make sure that nxml-mode can auto-load
(load "~/site-lisp/nxml/rng-auto.el")

;; load nxml-mode for files ending in .xml, .xsl, .xsd, .rng, .xhtml
(setq auto-mode-alist
      (cons '("\\.\\(xml\\|xsl\\|xsd\\|rng\\|xhtml\\)\\'" . nxml-mode)
            auto-mode-alist))

Configure the Pipeline Schema

nXML mode requires that the schema associated with a document instance be expressed in the Relax NG Compact Syntax. Relax NG is a schema language for XML that is in the final stages of ISO standardization. I've transformed the XSD-notation pipeline schema into Relax NG Compact notation and attached it to this page. The following procedure will allow nXML mode to associate the pipeline schema with your pipeline configuration files:

  • Place this pipeline.rnc file in the directory ~/site-lisp/nxml/schema.
  • Replace ~/site-lisp/nxml/schema/schemas.xml with this modified schemas.xml.

Usage

nXML mode continuously validates your document against the schema as you type, highlighting portions of the document that are invalid. Use the 'C-Enter' or 'M-Tab' keystrokes to complete the current element or attribute you are typing. If more than one possible completion is available, you will be presented with a list. This site provides more detailed documentation.

  • No labels