Apart from real-time validation, the most important feature that nXML mode provides for assisting in document creation is "completion". Completion assists the user in inserting characters at point, based on knowledge of the schema and on the contents of the buffer before point.
nXML mode adapts the standard GNU Emacs command for completion in a
completion-at-point, which is bound to C-M-i and
M-TAB. Note that many window systems and window managers
use M-TAB themselves (typically for switching between
windows) and do not pass it to applications. In that case, you should
type C-M-i or ESC TAB for completion, or bind
completion-at-point to a key that is convenient for you. In
the following, I will assume that you type C-M-i.
nXML mode completion works by examining the symbol preceding point. This is the symbol to be completed. The symbol to be completed may be the empty. Completion considers what symbols starting with the symbol to be completed would be valid replacements for the symbol to be completed, given the schema and the contents of the buffer before point. These symbols are the possible completions. An example may make this clearer. Suppose the buffer looks like this (where ∗ indicates point):
<html xmlns="http://www.w3.org/1999/xhtml"> <h∗
and the schema is XHTML. In this context, the symbol to be completed is ‘h’. The possible completions consist of just ‘head’. Another example, is
<html xmlns="http://www.w3.org/1999/xhtml"> <head> <∗
In this case, the symbol to be completed is empty, and the possible completions are ‘base’, ‘isindex’, ‘link’, ‘meta’, ‘script’, ‘style’, ‘title’. Another example is:
In this case, the symbol to be completed is empty, and the possible completions are just ‘http://www.w3.org/1999/xhtml’.
When you type C-M-i, what happens depends on what the set of possible completions are.
<html xmlns="http://www.w3.org/1999/xhtml"> <∗
C-M-i will yield
<html xmlns="http://www.w3.org/1999/xhtml"> <head∗
The symbol to be completed is ‘x’. The possible completions are ‘xmlns’ and ‘xml:lang’. These share a common prefix of ‘xml’. Thus, C-M-i will yield:
Typically, you would do C-M-i again, which would have the result described in the next item.
Emacs will prompt you in the minibuffer with
and the buffer showing possible completions will contain
Possible completions are: xml:lang xmlns
If you input xmlns, the result will be:
(If you do C-M-i again, the namespace URI will be inserted. Should that happen automatically?)