*** empty log message ***
[bpt/emacs.git] / doc / emacs / nxml-mode.texi
CommitLineData
8cd39fb3
MH
1\input texinfo @c -*- texinfo -*-
2@c %**start of header
3@setfilename nxml-mode.info
4@settitle nXML Mode
5@c %**end of header
6
7@dircategory Emacs
8@direntry
9* nXML Mode: (nxml-mode.info).
10@end direntry
11
12@node Top
13@top nXML Mode
14
15This manual documents nxml-mode, an Emacs major mode for editing
16XML with RELAX NG support. This manual is not yet complete.
17
18@menu
19* Completion::
20* Inserting end-tags::
21* Paragraphs::
22* Outlining::
23* Locating a schema::
24* DTDs::
25* Limitations::
26@end menu
27
28@node Completion
29@chapter Completion
30
31Apart from real-time validation, the most important feature that
32nxml-mode provides for assisting in document creation is "completion".
33Completion assists the user in inserting characters at point, based on
34knowledge of the schema and on the contents of the buffer before
35point.
36
37The traditional GNU Emacs key combination for completion in a
38buffer is @kbd{M-@key{TAB}}. However, many window systems
39and window managers use this key combination themselves (typically for
40switching between windows) and do not pass it to applications. It's
41hard to find key combinations in GNU Emacs that are both easy to type
42and not taken by something else. @kbd{C-@key{RET}} (i.e.
43pressing the Enter or Return key, while the Ctrl key is held down) is
44available. It won't be available on a traditional terminal (because
45it is indistinguishable from Return), but it will work with a window
46system. Therefore we adopt the following solution by default: use
47@kbd{C-@key{RET}} when there's a window system and
48@kbd{M-@key{TAB}} when there's not. In the following, I
49will assume that a window system is being used and will therefore
50refer to @kbd{C-@key{RET}}.
51
52Completion works by examining the symbol preceding point. This
53is the symbol to be completed. The symbol to be completed may be the
54empty. Completion considers what symbols starting with the symbol to
55be completed would be valid replacements for the symbol to be
56completed, given the schema and the contents of the buffer before
57point. These symbols are the possible completions. An example may
58make this clearer. Suppose the buffer looks like this (where @point{}
59indicates point):
60
61@example
62<html xmlns="http://www.w3.org/1999/xhtml">
63<h@point{}
64@end example
65
66@noindent
67and the schema is XHTML. In this context, the symbol to be completed
68is @samp{h}. The possible completions consist of just
69@samp{head}. Another example, is
70
71@example
72<html xmlns="http://www.w3.org/1999/xhtml">
73<head>
74<@point{}
75@end example
76
77@noindent
78In this case, the symbol to be completed is empty, and the possible
79completions are @samp{base}, @samp{isindex},
80@samp{link}, @samp{meta}, @samp{script},
81@samp{style}, @samp{title}. Another example is:
82
83@example
84<html xmlns="@point{}
85@end example
86
87@noindent
88In this case, the symbol to be completed is empty, and the possible
89completions are just @samp{http://www.w3.org/1999/xhtml}.
90
91When you type @kbd{C-@key{RET}}, what happens depends
92on what the set of possible completions are.
93
94@itemize @bullet
95@item
96If the set of completions is empty, nothing
97happens.
98@item
99If there is one possible completion, then that completion is
100inserted, together with any following characters that are
101required. For example, in this case:
102
103@example
104<html xmlns="http://www.w3.org/1999/xhtml">
105<@point{}
106@end example
107
108@noindent
109@kbd{C-@key{RET}} will yield
110
111@example
112<html xmlns="http://www.w3.org/1999/xhtml">
113<head@point{}
114@end example
115@item
116If there is more than one possible completion, but all
117possible completions share a common non-empty prefix, then that prefix
118is inserted. For example, suppose the buffer is:
119
120@example
121<html x@point{}
122@end example
123
124@noindent
125The symbol to be completed is @samp{x}. The possible completions
126are @samp{xmlns} and @samp{xml:lang}. These share a
127common prefix of @samp{xml}. Thus, @kbd{C-@key{RET}}
128will yield:
129
130@example
131<html xml@point{}
132@end example
133
134@noindent
135Typically, you would do @kbd{C-@key{RET}} again, which would
136have the result described in the next item.
137@item
138If there is more than one possible completion, but the
139possible completions do not share a non-empty prefix, then Emacs will
140prompt you to input the symbol in the minibuffer, initializing the
141minibuffer with the symbol to be completed, and popping up a buffer
142showing the possible completions. You can now input the symbol to be
143inserted. The symbol you input will be inserted in the buffer instead
144of the symbol to be completed. Emacs will then insert any required
145characters after the symbol. For example, if it contains:
146
147@example
148<html xml@point{}
149@end example
150
151@noindent
152Emacs will prompt you in the minibuffer with
153
154@example
155Attribute: xml@point{}
156@end example
157
158@noindent
159and the buffer showing possible completions will contain
160
161@example
162Possible completions are:
163xml:lang xmlns
164@end example
165
166@noindent
167If you input @kbd{xmlns}, the result will be:
168
169@example
170<html xmlns="@point{}
171@end example
172
173@noindent
174(If you do @kbd{C-@key{RET}} again, the namespace URI will
175be inserted. Should that happen automatically?)
176@end itemize
177
178@node Inserting end-tags
179@chapter Inserting end-tags
180
181The main redundancy in XML syntax is end-tags. nxml-mode provides
182several ways to make it easier to enter end-tags. You can use all of
183these without a schema.
184
185You can use @kbd{C-@key{RET}} after @samp{</}
186to complete the rest of the end-tag.
187
188@kbd{C-c C-f} inserts an end-tag for the element containing
189point. This command is useful when you want to input the start-tag,
190then input the content and finally input the end-tag. The @samp{f}
191is mnemonic for finish.
192
193If you want to keep tags balanced and input the end-tag at the
194same time as the start-tag, before inputting the content, then you can
195use @kbd{C-c C-i}. This inserts a @samp{>}, then inserts
196the end-tag and leaves point before the end-tag. @kbd{C-c C-b}
197is similar but more convenient for block-level elements: it puts the
198start-tag, point and the end-tag on successive lines, appropriately
199indented. The @samp{i} is mnemonic for inline and the
200@samp{b} is mnemonic for block.
201
202Finally, you can customize nxml-mode so that @kbd{/}
203automatically inserts the rest of the end-tag when it occurs after
204@samp{<}, by doing
205
206@display
207@kbd{M-x customize-variable @key{RET} nxml-slash-auto-complete-flag @key{RET}}
208@end display
209
210@noindent
211and then following the instructions in the displayed buffer.
212
213@node Paragraphs
214@chapter Paragraphs
215
216Emacs has several commands that operate on paragraphs, most
217notably @kbd{M-q}. nXML mode redefines these to work in a way
218that is useful for XML. The exact rules that are used to find the
219beginning and end of a paragraph are complicated; they are designed
220mainly to ensure that @kbd{M-q} does the right thing.
221
222A paragraph consists of one or more complete, consecutive lines.
223A group of lines is not considered a paragraph unless it contains some
224non-whitespace characters between tags or inside comments. A blank
225line separates paragraphs. A single tag on a line by itself also
226separates paragraphs. More precisely, if one tag together with any
227leading and trailing whitespace completely occupy one or more lines,
228then those lines will not be included in any paragraph.
229
230A start-tag at the beginning of the line (possibly indented) may
231be treated as starting a paragraph. Similarly, an end-tag at the end
232of the line may be treated as ending a paragraph. The following rules
233are used to determine whether such a tag is in fact treated as a
234paragraph boundary:
235
236@itemize @bullet
237@item
238If the schema does not allow text at that point, then it
239is a paragraph boundary.
240@item
241If the end-tag corresponding to the start-tag is not at
242the end of its line, or the start-tag corresponding to the end-tag is
243not at the beginning of its line, then it is not a paragraph
244boundary. For example, in
245
246@example
247<p>This is a paragraph with an
248<emph>emphasized</emph> phrase.
249@end example
250
251@noindent
252the @samp{<emph>} start-tag would not be considered as
253starting a paragraph, because its corresponding end-tag is not at the
254end of the line.
255@item
256If there is text that is a sibling in element tree, then
257it is not a paragraph boundary. For example, in
258
259@example
260<p>This is a paragraph with an
261<emph>emphasized phrase that takes one source line</emph>
262@end example
263
264@noindent
265the @samp{<emph>} start-tag would not be considered as
266starting a paragraph, even though its end-tag is at the end of its
267line, because there the text @samp{This is a paragraph with an}
268is a sibling of the @samp{emph} element.
269@item
270Otherwise, it is a paragraph boundary.
271@end itemize
272
273@node Outlining
274@chapter Outlining
275
276nXML mode allows you to display all or part of a buffer as an
277outline, in a similar way to Emacs' outline mode. An outline in nXML
278mode is based on recognizing two kinds of element: sections and
279headings. There is one heading for every section and one section for
280every heading. A section contains its heading as or within its first
281child element. A section also contains its subordinate sections (its
282subsections). The text content of a section consists of anything in a
283section that is neither a subsection nor a heading.
284
285Note that this is a different model from that used by XHTML.
286nXML mode's outline support will not be useful for XHTML unless you
287adopt a convention of adding a @code{div} to enclose each
288section, rather than having sections implicitly delimited by different
289@code{h@var{n}} elements. This limitation may be removed
290in a future version.
291
292The variable @code{nxml-section-element-name-regexp} gives
293a regexp for the local names (i.e. the part of the name following any
294prefix) of section elements. The variable
295@code{nxml-heading-element-name-regexp} gives a regexp for the
296local names of heading elements. For an element to be recognized
297as a section
298
299@itemize @bullet
300@item
301its start-tag must occur at the beginning of a line
302(possibly indented);
303@item
304its local name must match
305@code{nxml-section-element-name-regexp};
306@item
307either its first child element or a descendant of that
308first child element must have a local name that matches
309@code{nxml-heading-element-name-regexp}; the first such element
310is treated as the section's heading.
311@end itemize
312
313@noindent
314You can customize these variables using @kbd{M-x
315customize-variable}.
316
317There are three possible outline states for a section:
318
319@itemize @bullet
320@item
321normal, showing everything, including its heading, text
322content and subsections; each subsection is displayed according to the
323state of that subsection;
324@item
325showing just its heading, with both its text content and
326its subsections hidden; all subsections are hidden regardless of their
327state;
328@item
329showing its heading and its subsections, with its text
330content hidden; each subsection is displayed according to the state of
331that subsection.
332@end itemize
333
334In the last two states, where the text content is hidden, the
335heading is displayed specially, in an abbreviated form. An element
336like this:
337
338@example
339<section>
340<title>Food</title>
341<para>There are many kinds of food.</para>
342</section>
343@end example
344
345@noindent
346would be displayed on a single line like this:
347
348@example
349<-section>Food...</>
350@end example
351
352@noindent
353If there are hidden subsections, then a @code{+} will be used
354instead of a @code{-} like this:
355
356@example
357<+section>Food...</>
358@end example
359
360@noindent
361If there are non-hidden subsections, then the section will instead be
362displayed like this:
363
364@example
365<-section>Food...
366 <-section>Delicious Food...</>
367 <-section>Distasteful Food...</>
368</-section>
369@end example
370
371@noindent
372The heading is always displayed with an indent that corresponds to its
373depth in the outline, even it is not actually indented in the buffer.
374The variable @code{nxml-outline-child-indent} controls how much
375a subheading is indented with respect to its parent heading when the
376heading is being displayed specially.
377
378Commands to change the outline state of sections are bound to
379key sequences that start with @kbd{C-c C-o} (@kbd{o} is
380mnemonic for outline). The third and final key has been chosen to be
381consistent with outline mode. In the following descriptions
382current section means the section containing point, or, more precisely,
383the innermost section containing the character immediately following
384point.
385
386@itemize @bullet
387@item
388@kbd{C-c C-o C-a} shows all sections in the buffer
389normally.
390@item
391@kbd{C-c C-o C-t} hides the text content
392of all sections in the buffer.
393@item
394@kbd{C-c C-o C-c} hides the text content
395of the current section.
396@item
397@kbd{C-c C-o C-e} shows the text content
398of the current section.
399@item
400@kbd{C-c C-o C-d} hides the text content
401and subsections of the current section.
402@item
403@kbd{C-c C-o C-s} shows the current section
404and all its direct and indirect subsections normally.
405@item
406@kbd{C-c C-o C-k} shows the headings of the
407direct and indirect subsections of the current section.
408@item
409@kbd{C-c C-o C-l} hides the text content of the
410current section and of its direct and indirect
411subsections.
412@item
413@kbd{C-c C-o C-i} shows the headings of the
414direct subsections of the current section.
415@item
416@kbd{C-c C-o C-o} hides as much as possible without
417hiding the current section's text content; the headings of ancestor
418sections of the current section and their child section sections will
419not be hidden.
420@end itemize
421
422When a heading is displayed specially, you can use
423@key{RET} in that heading to show the text content of the section
424in the same way as @kbd{C-c C-o C-e}.
425
426You can also use the mouse to change the outline state:
427@kbd{S-mouse-2} hides the text content of a section in the same
428way as@kbd{C-c C-o C-c}; @kbd{mouse-2} on a specially
429displayed heading shows the text content of the section in the same
430way as @kbd{C-c C-o C-e}; @kbd{mouse-1} on a specially
431displayed start-tag toggles the display of subheadings on and
432off.
433
434The outline state for each section is stored with the first
435character of the section (as a text property). Every command that
436changes the outline state of any section updates the display of the
437buffer so that each section is displayed correctly according to its
438outline state. If the section structure is subsequently changed, then
439it is possible for the display to no longer correctly reflect the
440stored outline state. @kbd{C-c C-o C-r} can be used to refresh
441the display so it is correct again.
442
443@node Locating a schema
444@chapter Locating a schema
445
446nXML mode has a configurable set of rules to locate a schema for
447the file being edited. The rules are contained in one or more schema
448locating files, which are XML documents.
449
450The variable @samp{rng-schema-locating-files} specifies
451the list of the file-names of schema locating files that nXML mode
452should use. The order of the list is significant: when file
453@var{x} occurs in the list before file @var{y} then rules
454from file @var{x} have precedence over rules from file
455@var{y}. A filename specified in
456@samp{rng-schema-locating-files} may be relative. If so, it will
457be resolved relative to the document for which a schema is being
458located. It is not an error if relative file-names in
459@samp{rng-schema-locating-files} do not not exist. You can use
460@kbd{M-x customize-variable @key{RET} rng-schema-locating-files
461@key{RET}} to customize the list of schema locating
462files.
463
464By default, @samp{rng-schema-locating-files} list has two
465members: @samp{schemas.xml}, and
466@samp{@var{dist-dir}/schema/schemas.xml} where
467@samp{@var{dist-dir}} is the directory containing the nXML
468distribution. The first member will cause nXML mode to use a file
469@samp{schemas.xml} in the same directory as the document being
470edited if such a file exist. The second member contains rules for the
471schemas that are included with the nXML distribution.
472
473@menu
474* Commands for locating a schema::
475* Schema locating files::
476@end menu
477
478@node Commands for locating a schema
479@section Commands for locating a schema
480
481The command @kbd{C-c C-s C-w} will tell you what schema
482is currently being used.
483
484The rules for locating a schema are applied automatically when
485you visit a file in nXML mode. However, if you have just created a new
486file and the schema cannot be inferred from the file-name, then this
487will not locate the right schema. In this case, you should insert the
488start-tag of the root element and then use the command @kbd{C-c
489C-a}, which reapplies the rules based on the current content of
490the document. It is usually not necessary to insert the complete
491start-tag; often just @samp{<@var{name}} is
492enough.
493
494If you want to use a schema that has not yet been added to the
495schema locating files, you can use the command @kbd{C-c C-s C-f}
496to manually select the file contaiing the schema for the document in
497current buffer. Emacs will read the file-name of the schema from the
498minibuffer. After reading the file-name, Emacs will ask whether you
499wish to add a rule to a schema locating file that persistently
500associates the document with the selected schema. The rule will be
501added to the first file in the list specified
502@samp{rng-schema-locating-files}; it will create the file if
503necessary, but will not create a directory. If the variable
504@samp{rng-schema-locating-files} has not been customized, this
505means that the rule will be added to the file @samp{schemas.xml}
506in the same directory as the document being edited.
507
508The command @kbd{C-c C-s C-t} allows you to select a schema by
509specifying an identifier for the type of the document. The schema
510locating files determine the available type identifiers and what
511schema is used for each type identifier. This is useful when it is
512impossible to infer the right schema from either the file-name or the
513content of the document, even though the schema is already in the
514schema locating file. A situation in which this can occur is when
515there are multiple variants of a schema where all valid documents have
516the same document element. For example, XHTML has Strict and
517Transitional variants. In a situation like this, a schema locating file
518can define a type identifier for each variant. As with @kbd{C-c
519C-s C-f}, Emacs will ask whether you wish to add a rule to a schema
520locating file that persistently associates the document with the
521specified type identifier.
522
523The command @kbd{C-c C-s C-l} adds a rule to a schema
524locating file that persistently associates the document with
525the schema that is currently being used.
526
527@node Schema locating files
528@section Schema locating files
529
530Each schema locating file specifies a list of rules. The rules
531from each file are appended in order. To locate a schema each rule is
532applied in turn until a rule matches. The first matching rule is then
533used to determine the schema.
534
535Schema locating files are designed to be useful for other
536applications that need to locate a schema for a document. In fact,
537there is nothing specific to locating schemas in the design; it could
538equally well be used for locating a stylesheet.
539
540@menu
541* Schema locating file syntax basics::
542* Using the document's URI to locate a schema::
543* Using the document element to locate a schema::
544* Using type identifiers in schema locating files::
545* Using multiple schema locating files::
546@end menu
547
548@node Schema locating file syntax basics
549@subsection Schema locating file syntax basics
550
551There is a schema for schema locating files in the file
552@samp{locate.rnc} in the schema directory. Schema locating
553files must be valid with respect to this schema.
554
555The document element of a schema locating file must be
556@samp{locatingRules} and the namespace URI must be
557@samp{http://thaiopensource.com/ns/locating-rules/1.0}. The
558children of the document element specify rules. The order of the
559children is the same as the order of the rules. Here's a complete
560example of a schema locating file:
561
562@example
563<?xml version="1.0"?>
564<locatingRules xmlns="http://thaiopensource.com/ns/locating-rules/1.0">
565 <namespace ns="http://www.w3.org/1999/xhtml" uri="xhtml.rnc"/>
566 <documentElement localName="book" uri="docbook.rnc"/>
567</locatingRules>
568@end example
569
570@noindent
571This says to use the schema @samp{xhtml.rnc} for a document with
572namespace @samp{http://www.w3.org/1999/xhtml}, and to use the
573schema @samp{docbook.rnc} for a document whose local name is
574@samp{book}. If the document element had both a namespace URI
575of @samp{http://www.w3.org/1999/xhtml} and a local name of
576@samp{book}, then the matching rule that comes first will be
577used and so the schema @samp{xhtml.rnc} would be used. There is
578no precedence between different types of rule; the first matching rule
579of any type is used.
580
581As usual with XML-related technologies, resources are identified
582by URIs. The @samp{uri} attribute identifies the schema by
583specifying the URI. The URI may be relative. If so, it is resolved
584relative to the URI of the schema locating file that contains
585attribute. This means that if the value of @samp{uri} attribute
586does not contain a @samp{/}, then it will refer to a filename in
587the same directory as the schema locating file.
588
589@node Using the document's URI to locate a schema
590@subsection Using the document's URI to locate a schema
591
592A @samp{uri} rule locates a schema based on the URI of the
593document. The @samp{uri} attribute specifies the URI of the
594schema. The @samp{resource} attribute can be used to specify
595the schema for a particular document. For example,
596
597@example
598<uri resource="spec.xml" uri="docbook.rnc"/>
599@end example
600
601@noindent
602specifies that that the schema for @samp{spec.xml} is
603@samp{docbook.rnc}.
604
605The @samp{pattern} attribute can be used instead of the
606@samp{resource} attribute to specify the schema for any document
607whose URI matches a pattern. The pattern has the same syntax as an
608absolute or relative URI except that the path component of the URI can
609use a @samp{*} character to stand for zero or more characters
610within a path segment (i.e. any character other @samp{/}).
611Typically, the URI pattern looks like a relative URI, but, whereas a
612relative URI in the @samp{resource} attribute is resolved into a
613particular absolute URI using the base URI of the schema locating
614file, a relative URI pattern matches if it matches some number of
615complete path segments of the document's URI ending with the last path
616segment of the document's URI. For example,
617
618@example
619<uri pattern="*.xsl" uri="xslt.rnc"/>
620@end example
621
622@noindent
623specifies that the schema for documents with a URI whose path ends
624with @samp{.xsl} is @samp{xslt.rnc}.
625
626A @samp{transformURI} rule locates a schema by
627transforming the URI of the document. The @samp{fromPattern}
628attribute specifies a URI pattern with the same meaning as the
629@samp{pattern} attribute of the @samp{uri} element. The
630@samp{toPattern} attribute is a URI pattern that is used to
631generate the URI of the schema. Each @samp{*} in the
632@samp{toPattern} is replaced by the string that matched the
633corresponding @samp{*} in the @samp{fromPattern}. The
634resulting string is appended to the initial part of the document's URI
635that was not explicitly matched by the @samp{fromPattern}. The
636rule matches only if the transformed URI identifies an existing
637resource. For example, the rule
638
639@example
640<transformURI fromPattern="*.xml" toPattern="*.rnc"/>
641@end example
642
643@noindent
644would transform the URI @samp{file:///home/jjc/docs/spec.xml}
645into the URI @samp{file:///home/jjc/docs/spec.rnc}. Thus, this
646rule specifies that to locate a schema for a document
647@samp{@var{foo}.xml}, Emacs should test whether a file
648@samp{@var{foo}.rnc} exists in the same directory as
649@samp{@var{foo}.xml}, and, if so, should use it as the
650schema.
651
652@node Using the document element to locate a schema
653@subsection Using the document element to locate a schema
654
655A @samp{documentElement} rule locates a schema based on
656the local name and prefix of the document element. For example, a rule
657
658@example
659<documentElement prefix="xsl" localName="stylesheet" uri="xslt.rnc"/>
660@end example
661
662@noindent
663specifies that when the name of the document element is
664@samp{xsl:stylesheet}, then @samp{xslt.rnc} should be used
665as the schema. Either the @samp{prefix} or
666@samp{localName} attribute may be omitted to allow any prefix or
667local name.
668
669A @samp{namespace} rule locates a schema based on the
670namespace URI of the document element. For example, a rule
671
672@example
673<namespace ns="http://www.w3.org/1999/XSL/Transform" uri="xslt.rnc"/>
674@end example
675
676@noindent
677specifies that when the namespace URI of the document is
678@samp{http://www.w3.org/1999/XSL/Transform}, then
679@samp{xslt.rnc} should be used as the schema.
680
681@node Using type identifiers in schema locating files
682@subsection Using type identifiers in schema locating files
683
684Type identifiers allow a level of indirection in locating the
685schema for a document. Instead of associating the document directly
686with a schema URI, the document is associated with a type identifier,
687which is in turn associated with a schema URI. nXML mode does not
688constrain the format of type identifiers. They can be simply strings
689without any formal structure or they can be public identifiers or
690URIs. Note that these type identifiers have nothing to do with the
691DOCTYPE declaration. When comparing type identifiers, whitespace is
692normalized in the same way as with the @samp{xsd:token}
693datatype: leading and trailing whitespace is stripped; other sequences
694of whitespace are normalized to a single space character.
695
696Each of the rules described in previous sections that uses a
697@samp{uri} attribute to specify a schema, can instead use a
698@samp{typeId} attribute to specify a type identifier. The type
699identifier can be associated with a URI using a @samp{typeId}
700element. For example,
701
702@example
703<locatingRules xmlns="http://thaiopensource.com/ns/locating-rules/1.0">
704 <namespace ns="http://www.w3.org/1999/xhtml" typeId="XHTML"/>
705 <typeId id="XHTML" typeId="XHTML Strict"/>
706 <typeId id="XHTML Strict" uri="xhtml-strict.rnc"/>
707 <typeId id="XHTML Transitional" uri="xhtml-transitional.rnc"/>
708</locatingRules>
709@end example
710
711@noindent
712declares three type identifiers @samp{XHTML} (representing the
713default variant of XHTML to be used), @samp{XHTML Strict} and
714@samp{XHTML Transitional}. Such a schema locating file would
715use @samp{xhtml-strict.rnc} for a document whose namespace is
716@samp{http://www.w3.org/1999/xhtml}. But it is considerably
717more flexible than a schema locating file that simply specified
718
719@example
720<namespace ns="http://www.w3.org/1999/xhtml" uri="xhtml-strict.rnc"/>
721@end example
722
723@noindent
724A user can easily use @kbd{C-c C-s C-t} to select between XHTML
725Strict and XHTML Transitional. Also, a user can easily add a catalog
726
727@example
728<locatingRules xmlns="http://thaiopensource.com/ns/locating-rules/1.0">
729 <typeId id="XHTML" typeId="XHTML Transitional"/>
730</locatingRules>
731@end example
732
733@noindent
734that makes the default variant of XHTML be XHTML Transitional.
735
736@node Using multiple schema locating files
737@subsection Using multiple schema locating files
738
739The @samp{include} element includes rules from another
740schema locating file. The behavior is exactly as if the rules from
741that file were included in place of the @samp{include} element.
742Relative URIs are resolved into absolute URIs before the inclusion is
743performed. For example,
744
745@example
746<include rules="../rules.xml"/>
747@end example
748
749@noindent
750includes the rules from @samp{rules.xml}.
751
752The process of locating a schema takes as input a list of schema
753locating files. The rules in all these files and in the files they
754include are resolved into a single list of rules, which are applied
755strictly in order. Sometimes this order is not what is needed.
756For example, suppose you have two schema locating files, a private
757file
758
759@example
760<locatingRules xmlns="http://thaiopensource.com/ns/locating-rules/1.0">
761 <namespace ns="http://www.w3.org/1999/xhtml" uri="xhtml.rnc"/>
762</locatingRules>
763@end example
764
765@noindent
766followed by a public file
767
768@example
769<locatingRules xmlns="http://thaiopensource.com/ns/locating-rules/1.0">
770 <transformURI pathSuffix=".xml" replacePathSuffix=".rnc"/>
771 <namespace ns="http://www.w3.org/1999/XSL/Transform" typeId="XSLT"/>
772</locatingRules>
773@end example
774
775@noindent
776The effect of these two files is that the XHTML @samp{namespace}
777rule takes precedence over the @samp{transformURI} rule, which
778is almost certainly not what is needed. This can be solved by adding
779an @samp{applyFollowingRules} to the private file.
780
781@example
782<locatingRules xmlns="http://thaiopensource.com/ns/locating-rules/1.0">
783 <applyFollowingRules ruleType="transformURI"/>
784 <namespace ns="http://www.w3.org/1999/xhtml" uri="xhtml.rnc"/>
785</locatingRules>
786@end example
787
788@node DTDs
789@chapter DTDs
790
791nxml-mode is designed to support the creation of standalone XML
792documents that do not depend on a DTD. Although it is common practice
793to insert a DOCTYPE declaration referencing an external DTD, this has
794undesirable side-effects. It means that the document is no longer
795self-contained. It also means that different XML parsers may interpret
796the document in different ways, since the XML Recommendation does not
797require XML parsers to read the DTD. With DTDs, it was impractical to
798get validation without using an external DTD or reference to an
799parameter entity. With RELAX NG and other schema languages, you can
800simulataneously get the benefits of validation and standalone XML
801documents. Therefore, I recommend that you do not reference an
802external DOCTYPE in your XML documents.
803
804One problem is entities for characters. Typically, as well as
805providing validation, DTDs also provide a set of character entities
806for documents to use. Schemas cannot provide this functionality,
807because schema validation happens after XML parsing. The recommended
808solution is to either use the Unicode characters directly, or, if this
809is impractical, use character references. nXML mode supports this by
810providing commands for entering characters and character references
811using the Unicode names, and can display the glyph corresponding to a
812character reference.
813
814@node Limitations
815@chapter Limitations
816
817nXML mode has some limitations:
818
819@itemize @bullet
820@item
821DTD support is limited. Internal parsed general entities declared
822in the internal subset are supported provided they do not contain
823elements. Other usage of DTDs is ignored.
824@item
825The restrictions on RELAX NG schemas in section 7 of the RELAX NG
826specification are not enforced.
827@item
828Unicode support has problems. This stems mostly from the fact that
829the XML (and RELAX NG) character model is based squarely on Unicode,
830whereas the Emacs character model is not. Emacs 22 is slated to have
831full Unicode support, which should improve the situation here.
832@end itemize
833
834@bye