Back to: SuomenKielipankki:Helpdesk

Helpdesk Item: Using nXML mode with GNU Emacs

Description of the Problem

The nXML mode is a mode for Emacs for editing text files in XML format. The nXML support includes proper indenting, completion of tag names etc. and constant validation of the file being edited. The user sees the document text where tags are shown with some highlighting but otherwise the tags are editable as text.

These instructions intend to be applicable to the CSC Corpus server, other similar Linux servers and Windows XP workstations of the users. Please, correct and add as necessary.

The Answer(s)

Files or packages needed

Settings needed

Configuration file ~/.emacs

In order to help the Emacs recognize when to enter the nxml-mode you can use the auto-mode-alist which decides the mode of files according to their suffixes:

(setq auto-mode-alist
      (append
       (list
        '("\\.rst" . rst-mode)
        '("\\.xhtml" . nxml-mode)
        '("\\.xml" . nxml-mode)
        '("\\.xsl" . nxml-mode)
        '("\\.shtml" . sgml-mode)
        '("\\.html" . sgml-mode))
       auto-mode-alist))

Customizing Emacs

The nxml-mode needs to locate an appropriate schema for each file. The nxml-mode uses Relax Schemas and the mode needs a file for deciding what schema to use for each XML file. For most users, one common file is sufficient, but Emacs must know where the file is, eg.

Options > Customize Emacs > Browse customizing groups > Wp > Relax Ng

The following contains a schema for XHTML files:

   /usr/share/emacs/site-lisp/nxml-mode/schema/schemas.xml

Creating a Relax schema (.rng)

If you are designing a new XML structure for a paticular application, you probably prefer to write the .rng schema directly, as it is as easy as writing a DTD if not easier. See instructions at the nXML site.

If you already have a DTD you need to convert it into a .rng file using a simple Java program trang from the nXML site.

-- KimmoKoskenniemi - 02 May 2006 -- AnssiYliJyra - 21 Aug 2006 (moved)

HelpdeskForm
HelpdeskProblemName nXML mode in Emacs
HelpdeskProblemAbstract I want to edit XML with Emacs. How I can use the nXML mode?
HelpdeskUrgency FullyResponded
HelpdeskNumberOfUsers 40
HelpdeskDateIssued 2006-05-02
Topic revision: r2 - 2007-02-23 - KimmoKoskenniemi
 
This site is powered by the TWiki collaboration platform Powered by PerlCopyright © 2008-2018 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback