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.
- 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; it looks like this:
default namespace = "http://glast-ground.slac.stanford.edu/pipeline" namespace xsi = "http://www.w3.org/2001/XMLSchema-instance" start = pipeline pipeline = element pipeline { attribute xsi:schemaLocation { xsd:string }, name, type, dataset-base-path, run-log-path, executable+, batch-job-configuration+, file*, foreign-input-file*, processing-step+ } name = element name { xsd:string { minLength="1" maxLength="30" } } type = element type { xsd:NMTOKEN "SimReconDigi" | xsd:NMTOKEN "test" | xsd:NMTOKEN "Analysis" | xsd:NMTOKEN "Reconstruction" | xsd:NMTOKEN "Digitization" | xsd:NMTOKEN "Report" | xsd:NMTOKEN "SystemTest" | xsd:NMTOKEN "Simulation" | xsd:NMTOKEN "Reprocessing" | xsd:NMTOKEN "Conversion" } dataset-base-path = element dataset-base-path { xsd:string { minLength = "0" maxLength = "200" } } run-log-path = element run-log-path { xsd:string { minLength = "1" maxLength = "200" } } executable = element executable { xsd:string { minLength = "1" maxLength = "200" } , attribute name { xsd:string { minLength = "1" maxLength = "20" } }, attribute version { xsd:string { minLength = "1" maxLength = "20" } } } batch-job-configuration = element batch-job-configuration { element working-directory { xsd:string { minLength = "0" maxLength = "200" } }, element log-file-path { xsd:string { minLength = "1" maxLength = "200" } }, attribute name { xsd:string }, attribute queue { xsd:NMTOKEN "long" | xsd:NMTOKEN "short" | xsd:NMTOKEN "xlong" | xsd:NMTOKEN "medium" | xsd:NMTOKEN "xxl" | xsd:NMTOKEN "express" }, attribute group { xsd:NMTOKEN "none" | xsd:NMTOKEN "glastgrp" | xsd:NMTOKEN "glastdata" } } file = element file { xsd:string, attribute name { xsd:string { minLength = "1" maxLength = "30" } }, attribute type { xsd:NMTOKEN "MC" | xsd:NMTOKEN "Analysis" | xsd:NMTOKEN "text" | xsd:NMTOKEN "LDF" | xsd:NMTOKEN "DIGI" | xsd:NMTOKEN "RAW" | xsd:NMTOKEN "rcReport" | xsd:NMTOKEN "merit" | xsd:NMTOKEN "svac" | xsd:NMTOKEN "histogram" | xsd:NMTOKEN "script" | xsd:NMTOKEN "log" | xsd:NMTOKEN "ntuple" | xsd:NMTOKEN "tree" | xsd:NMTOKEN "RECON" }, attribute file-type { xsd:NMTOKEN "jobOpt" | xsd:NMTOKEN "root" | xsd:NMTOKEN "txt" | xsd:NMTOKEN "fits" | xsd:NMTOKEN "pl" | xsd:NMTOKEN "csh" | xsd:NMTOKEN "tgz" | xsd:NMTOKEN "xml" | xsd:NMTOKEN "sh" | xsd:NMTOKEN "tar" | xsd:NMTOKEN "gz" | xsd:NMTOKEN "tar.gz" | xsd:NMTOKEN "pdf" | xsd:NMTOKEN "ps" | xsd:NMTOKEN "html" | xsd:NMTOKEN "tex" } } foreign-input-file = element foreign-input-file { xsd:string, attribute name { xsd:string { minLength = "1" maxLength = "30" } }, attribute pipeline { xsd:string { minLength = "1" maxLength = "30" } }, attribute file { xsd:string { minLength = "1" maxLength = "30" } } } processing-step = element processing-step { element input-file { attribute name { xsd:string } }*, element output-file { attribute name { xsd:string } }*, attribute name { xsd:string }, attribute executable { xsd:string }, attribute batch-job-configuration { xsd:string } }
To ensure that nXML mode can find and associate the proper schema with your pipeline configuration files, place the 'pipeline.rnc' file attached to this page in the directory ~/site-lisp/nxml/schema, and replace ~/site-lisp/nxml/schema/schemas.xml with the modified version also attached to this page.