nXML mode is an Emacs major-mode for editing XML documents. It supports
editing well-formed XML documents, and provides schema-sensitive editing
using RELAX NG Compact Syntax. To get started, visit a file containing an
XML document, and, if necessary, use M-x nxml-mode to switch to nXML
mode. By default, auto-mode-alist
and magic-fallback-alist
put buffers in nXML mode if they have recognizable XML content or file
extensions. You may wish to customize the settings, for example to
recognize different file extensions.
Once in nXML mode, you can type C-h m for basic information on the mode.
The etc/nxml directory in the Emacs distribution contains some data files used by nXML mode, and includes two files (test-valid.xml and test-invalid.xml) that provide examples of valid and invalid XML documents.
To get validation and schema-sensitive editing, you need a RELAX NG Compact Syntax (RNC) schema for your document (see Locating a schema). The etc/schema directory includes some schemas for popular document types. See https://relaxng.org/ for more information on RELAX NG. You can use the ‘Trang’ program from http://www.thaiopensource.com/relaxng/trang.html to automatically create RNC schemas. This program can:
To convert a RELAX NG XML syntax (‘.rng’) schema to a RNC one, you can also use the XSLT stylesheet from https://github.com/oleg-pavliv/emacs/tree/master/xsl.
To convert a W3C XML Schema to an RNC schema, you need first to convert it
to RELAX NG XML syntax using the RELAX NG converter tool rngconv
(built on top of MSV). See https://github.com/kohsuke/msv
and https://msv.dev.java.net/.
For historical discussions only, see the mailing list archives at http://groups.yahoo.com/group/emacs-nxml-mode/. Please make all new discussions on the ‘help-gnu-emacs’ and ‘emacs-devel’ mailing lists. Report any bugs with M-x report-emacs-bug.