[go: up one dir, main page]
More Web Proxy on the site http://driver.im/

[Mirrored from: http://www.textuality.com/sgml-erb/WD-xml.html, November 15, 1996]

W3CWD-xml-961114

Extensible Markup Language (XML)

W3C Working Draft 14-Nov-96

This version:
http://www.w3.org/pub/WWW/TR/WD-xml-961114.html
Previous versions:
http://www.w3.org/pub/WWW/TR/WD-xml-961101.html
Latest version:
http://www.textuality.com/sgml-erb/WD-xml.html
Editors:
Tim Bray (Textuality) <tbray@textuality.com>
C. M. Sperberg-McQueen (University of Illinois at Chicago) <cmsmcq@uic.edu>

Status of this memo

This is a W3C Working Draft for review by W3C members and other interested parties. It is a draft document and may be updated, replaced or obsoleted by other documents at any time. It is inappropriate to use W3C Working Drafts as reference material or to cite them as other than "work in progress". A list of current W3C working drafts can be found at http://www.w3.org/pub/WWW/TR.
Note: Since working drafts are subject to frequent change, you are advised to reference the above URL, rather than the URLs for working drafts themselves.
This work is part of the W3C SGML Activity (for current status, see http://www.w3.org/pub/WWW/MarkUp/SGML/Activity).


Abstract

Extensible Markup Language (XML) is an extremely simple dialect of SGML which is completely described in this document. The goal is to enable generic SGML to be served, received, and processed on the Web in the way that is now possible with HTML. For this reason, XML has been designed for ease of implementation, and for interoperability with both SGML and HTML.


Table of Contents

1. Introduction
    1.1 Origin and Goals
    1.2 Relationship to Existing Standards
    1.3 Notation
    1.4 Terminology
    1.5 Common Syntactic Constructs
2. Documents
    2.1 Logical and Physical Structure
    2.2 Well-Formed XML Documents
    2.3 Characters
    2.4 Character Data and Markup
    2.5 Comments
    2.6 Processing Instructions
    2.7 CDATA Sections
    2.8 White Space Handling
    2.9 Prolog and Document Type Declaration
    2.10 Required Markup Declaration
3. Logical Structures
    3.1 Start- and End-Tags
    3.2 Element Declarations
        3.2.1 Mixed Content
        3.2.2 Element Content
    3.3 Attribute-List Declarations
        3.3.1 Attribute Types
        3.3.2 Attribute Defaults
        3.3.3 Attribute-Value Normalization
    3.4 Conditional Sections
4. Physical Structures
    4.1 Character and Entity References
    4.2 Entity Declarations
        4.2.1 Internal Entities
        4.2.2 External Entities
        4.2.3 Character Encoding in Entities
        4.2.4 Document Entity
    4.3 XML Processor Treatment of Entities
    4.4 Notation Declarations
5. Conformance

Appendices

A. XML and SGML
B. References
C. Deterministic Content Models
D. Production note
E. W3C SGML Working Group and Editorial Review Board
    E.1 W3C SGML Working Group
    E.2 W3C SGML Editorial Review Board

1. Introduction

Extensible Markup Language, abbreviated XML, describes a class of data objects called XML documents which are stored on computers, and partially describes the behavior of programs which process these objects. XML is an application profile or restricted form of SGML, the Standard Generalized Markup Language [ISO 8879].

XML documents are made up of storage units called entities, which contain either text or binary data. Text is made up of characters, some of which form the character data in the document, and some of which form markup. Markup encodes a description of the document's storage layout and logical structure. XML provides a mechanism to impose constraints on the storage layout and logical structure.

A software module called an XML processor is used to read XML documents and provide access to their content and structure. It is assumed that an XML processor is doing its work on behalf of another module, referred to as the application. This specification describes the required behavior of an XML processor in terms of how it must read XML data and the information it must provide to the application.

1.1 Origin and Goals

XML was developed by an SGML Editorial Review Board formed under the auspices of the World Wide Web Consortium (W3C) in 1996 and chaired by Jon Bosak of Sun Microsystems, with the very active participation of an SGML Working Group also organized by the W3C. The membership of these groups is given in an appendix. The ERB's contact with the W3 Consortium was Dan Connolly.

The design goals for XML are:

  1. XML shall be straightforwardly usable over the Internet.
  2. XML shall support a wide variety of applications.
  3. XML shall be compatible with SGML.
  4. It shall be easy to write programs which process XML documents.
  5. The number of optional features in XML is to be kept to the absolute minimum, ideally zero.
  6. XML documents should be human-legible and reasonably clear.
  7. The XML design should be prepared quickly.
  8. The design of XML shall be formal and concise.
  9. XML documents shall be easy to create.
  10. Terseness in XML markup is of minimal importance.

This specification, together with the associated standards, provides all the information necessary to understand XML version 1.0 and construct computer programs to process it.

This version of the XML specification (14 November 1996) is for public review and discussion. It may be distributed freely, as long as all text and legal notices remain intact.

1.2 Relationship to Existing Standards

Other standards relevant to users and implementors of XML include:

1.3 Notation

The formal grammar of XML is given using a simple Extended Backus-Naur Form (EBNF) notation. Each rule in the grammar defines one symbol, in the form

symbol ::= expression

Symbols are written with an initial capital letter if they are defined by a regular expression, or with an initial lowercase letter if a recursive grammar is required for recognition. Literal strings are quoted; unless otherwise noted they are case-insensitive. The distinction between symbols which can and cannot be recognized using simple regular expressions may be used to set the boundary between an implementation's lexical scanner and its parser, but this specification neither constrains the placement of that boundary nor presupposes that all implementations will have one.

Within the expression on the right-hand side of a rule, the meaning of symbols is as shown below:

#xNN
where NN is a hexadecimal integer, the expression matches the character in ISO 10646 whose UCS-4 bit string, when interpreted as an unsigned binary number, has the value indicated
[a-zA-Z], [#xNN-#xNN]
matches any character with a value in the range(s) indicated (inclusive)
[^a-z], [^#xNN-#xNN]
matches any character (i.e., #x0009, #x000A, #x000D, or [#x0020-#xFFFD]) with a value outside the range indicated
[^abc], [^#xNN#xNN#xNN]
matches any character with a value not among the characters given
"string"
matches the literal string given inside the double quotes
'string'
matches the literal string given inside the single quotes
a b
a followed by b
a | b
a or b but not both
a?
a or nothing; optional a
a+
one or more occurrences of a
a*
zero or more occurrences of a
(expression)
expression is treated as a unit; allows subgroups to carry the operator ?, *, or +
/* ... */
comment
[ WFC: ... ]
Well-formedness check; this identifies by name a check for well-formedness associated with a production
[ VC: ... ]
Validity check; this identifies by name a check for validity associated with a production

1.4 Terminology

Some terms used with special meaning in this specification are:

may
Conforming data and software is permitted to but need not behave as described.
must
Conforming data and software is required to behave as described; otherwise they are in error.
error
A violation of the rules of this specification; results are undefined. Conforming software may detect and report an error and may recover from it.
reportable error
An error which conforming software must, at user option, report to the user.
validity constraint
A rule which applies to all valid XML documents. Violations of validity constraints are errors; they must, at user option, be reported by validating XML processors.
well-formedness constraint
A rule which applies to all well-formed XML documents. Violations of well-formedness constraints are reportable errors.
at user option
Conforming software may or must (depending on the verb in the sentence) provide users a means to select, or to decline, the behavior described.
match
Case-insensitive match: two strings or names being compared must be identical except for differences between upper- and lower-case letters in scripts which have such a distinction. Characters with multiple possible representations in ISO 10646 (e.g. both precomposed and base+diacritic forms) match only if they have the same representation in both strings, after case folding. Case folding must be performed as specified in The Unicode Standard, Version 2.0, section 4.1, except that for compatibility reasons XML processors must perform case-insensitive matching by folding lowercase letters to uppercase, not vice versa.
exact(ly) match
Case-sensitive match: two strings or names being compared must be identical. Characters with multiple possible representations in ISO 10646 (e.g. both precomposed and base+diacritic forms) match only if they have the same representation in both strings.
for compatibility
A feature of XML included solely to ensure that XML remains compatible with SGML.

1.5 Common Syntactic Constructs

This section defines some symbols used widely in the grammar.

S (white space) consists of one or more blank characters, carriage returns, line feeds, tabs, or ideographic space characters.

White space
[1] S ::= (#x0020 | #x000a | #x000d | #x0009 | #x3000)+

Characters are classified for convenience as letters, digits, or other characters. Legal characters are tab, carriage return, line feed, and the legal characters of Unicode and ISO 10646. Letters consist of an alphabetic base character possibly followed by one or more combining characters, or of an ideographic character.

Characters
[2] Character ::= #x09 | #x0A | #x0D | [#x20-#xFFFD] | [#x00010000-#x7FFFFFFF] /* any ISO 10646 31-bit code, FFFE and FFFF excluded */
[3] BaseChar ::= [#x41-#x5A] | [#x61-#x7A] /* Latin 1 upper and lowercase */
| #xAA | #xB5 | #xBA | [#xC0-#xD6] | [#xD8-#xF6] /* Latin 1 supplementary */
| [#xF8-#xFF] /* Latin 1 supplementary */
| [#x0100-#x017F] /* Extended Latin-A */
| [#x0180-#x01F5] | [#x01FA-#x0217] /* Extended Latin-B */
| [#x0250-#x02A8] /* IPA Extensions */
| [#x02B0-#x02B8] | [#x02BB-#x02C1] | [#x02E0-#x02E4] /* Spacing Modifiers */
| #x037A | #x0386 | [#x0388-#x038A] | #x038C | [#x038E-#x03A1] | [#x03A3-#x03CE] | [#x03D0-#x03D6] | #x03DA | #x03DC | #x03DE | #x03E0 | [#x03E2-#x03F3] /* Greek and Coptic */
| [#x0401-#x040C] | [#x040E-#x044F] | [#x0451-#x045C] | [#x045E-#x0481] | [#x0490-#x04C4] | [#x04C7-#x04C8] | [#x04CB-#x04CC] | [#x04D0-#x04EB] | [#x04EE-#x04F5] | [#x04F8-#x04F9] /* Cyrillic */
| [#x0531-#x0556] | [#x0559-#x055A] | [#x0561-#x0587] /* Armenian */
| [#x05D0-#x05EA] | [#x05F0-#x05F2] /* Hebrew */
| [#x0621-#x063A] | [#x0641-#x064A] | [#x0671-#x06B7] | [#x06BA-#x06BE] | [#x06C0-#x06CE] | [#x06D0-#x06D3] | [#x06D5-#x06D6] | [#x06E5-#x06E6] /* Arabic */
| [#x0905-#x0939] | #x093D | [#x0958-#x0961] /* Devanagari */
| #x0981 | [#x0985-#x098C] | [#x098F-#x0990] | [#x0993-#x09A8] | [#x09AA-#x09B0] | #x09B2 | [#x09B6-#x09B9] | [#x09DC-#x09DD] | [#x09DF-#x09E1] | [#x09F0-#x09F1] /* Bengali */
| [#x0A05-#x0A0A] | [#x0A0F-#x0A10] | [#x0A13-#x0A28] | [#x0A2A-#x0A30] | [#x0A32-#x0A33] | [#x0A35-#x0A36] | [#x0A38-#x0A39] /* Gurmukhi */
| [#x0A8F-#x0A91] | [#x0A93-#x0AA8] | [#x0AAA-#x0AB0] | [#x0AB2-#x0AB3] | [#x0AB5-#x0AB9] | #x0AE0 /* Gujarati */
| [#x0B05-#x0B0C] | [#x0B0F-#x0B10] | [#x0B13-#x0B28] | [#x0B2A-#x0B30] | [#x0B32-#x0B33] | [#x0B36-#x0B39] | #x0B3D | [#x0B5C-#x0B5D] | [#x0B5F-#x0B61] /* Oriya */
| [#x0B85-#x0B8A] | [#x0B8E-#x0B90] | [#x0B92-#x0B95] | [#x0B99-#x0B9A] | #x0B9C | [#x0B9E-#x0B9F] | [#x0BA3-#x0BA4] | [#x0BA8-#x0BAA] | [#x0BAE-#x0BB5] | [#x0BB7-#x0BB9] /* Tamil */
| [#x0C05-#x0C0C] | [#x0C0E-#x0C10] | [#x0C12-#x0C28] | [#x0C2A-#x0C33] | [#x0C35-#x0C39] | [#x0C60-#x0C61] /* Telugu */
| [#x0C85-#x0C8C] | [#x0C8E-#x0C90] | [#x0C92-#x0CA8] | [#x0CAA-#x0CB3] | [#x0CB5-#x0CB9] | #x0CDE | [#x0CE0-#x0CE1] /* Kannada */
| [#x0D05-#x0D0C] | [#x0D0E-#x0D10] | [#x0D12-#x0D28] | [#x0D2A-#x0D39] | [#x0D60-#x0D61] /* Malayalam */
| [#x0E01-#x0E2E] | #x0E30 | [#x0E32-#x0E33] | [#x0E40-#x0E45] /* Thai */
| [#x0E81-#x0E82] | #x0E84 | [#x0E87-#x0E88] | #x0E8A | #x0E8D | [#x0E94-#x0E97] | [#x0E99-#x0E9F] | [#x0EA1-#x0EA3] | #x0EA5 | #x0EA7 | [#x0EAA-#x0EAB] | [#x0EAD-#x0EAE] | #x0EB0 | [#x0EB2-#x0EB3] | #x0EBD | [#x0EC0-#x0EC4] | [#x0EDC-#x0EDD] /* Lao */
| [#x0F40-#x0F47] | [#x0F49-#x0F69] /* Tibetan */
| [#x10A0-#x10C5] | [#x10D0-#x10F6] /* Georgian */
| [#x1100-#x1159] | [#x115F-#x11A2] | [#x11A8-#x11F9] /* Hangul Jamo */
| [#x1E00-#x1E9B] | [#x1EA0-#x1EF9] /* Add'l Extended Latin */
| [#x1F00-#x1F15] | [#x1F18-#x1F1D] | [#x1F20-#x1F45] | [#x1F48-#x1F4D] | [#x1F50-#x1F57] | #x1F59 | #x1F5B | #x1F5D | [#x1F5F-#x1F7D] | [#x1F80-#x1FB4] | [#x1FB6-#x1FBC] | #x1FBE | [#x1FC2-#x1FC4] | [#x1FC6-#x1FCC] | [#x1FD0-#x1FD3] | [#x1FD6-#x1FDB] | [#x1FE0-#x1FEC] | [#x1FF2-#x1FF4] | [#x1FF6-#x1FFC] /* Greek Extensions */
| #x207F /* Super-, subscripts */
| #x2102 | #x2107 | [#x210A-#x2113] | #x2115 | [#x2118-#x211D] | #x2124 | #x2126 | #x2128 | [#x212A-#x212D] | [#x212F-#x2131] | [#x2133-#x2138] /* Letterlike Symbols */
| [#x2160-#x2182] /* Number forms */
| [#x3041-#x3094] /* Hiragana */
| [#x30A1-#x30FA] /* Katakana */
| [#x3105-#x312C] /* Bopomofo */
| [#x3131-#x318E] /* Hangul Jamo */
| [#xAC00-#xD7A3] /* */
| [#xFB00-#xFB06] | [#xFB13-#xFB17] | [#xFB1F-#xFB28] | [#xFB2A-#xFB36] | [#xFB38-#xFB3C] | #xFB3E | [#xFB40-#xFB41] | [#xFB43-#xFB44] | [#xFB46-#xFB4F] /* Alphabetic presentation forms */
| [#xFB50-#xFBB1] | [#xFBD3-#xFD3D] | [#xFD50-#xFD8F] | [#xFD92-#xFDC7] | [#xFDF0-#xFDF8] | [#xFE70-#xFE72] | #xFE74 | [#xFE76-#xFEFC] /* Arabic presentation forms */
| [#xFF21-#xFF3A] | [#xFF41-#xFF5A] | [#xFF66-#xFF6F] | [#xFE71-#xFF9D] | [#xFFA0-#xFFBE] | [#xFFC2-#xFFC7] | [#xFFCA-#xFFCF] | [#xFFD2-#xFFD7] | [#xFFDA-#xFFDC] /* Half- and fullwidth forms */
[4] Ideographic ::= [#x4E00-#x9FA5] | [#xF900-#xFA2D] | #x3007 | [#x3021-#x3029]
[5] CombiningChar ::= [#x0300-#x0361] | [#x0483-#x0486] | [#x0591-#x05C4] | [#x064B-#x0652] | #x0670 | [#x06D7-#x06DC] | [#x06DD-#x06DF] | [#x06E0-#x06E4] | [#x06E7-#x06E8] | [#x06EA-#x06ED] | [#x0901-#x0903] | [#x093E-#x094C] | #x094D | [#x0951-#x0954] | [#x0962-#x0963] | [#x0981-#x0983] | #x09BC | #x09BE | #x09BF | [#x09C0-#x09C4] | [#x09C7-#x09C8] | [#x09CB-#x09CD] | #x09D7 | [#x09E2-#x09E3] | #x0A02 | #x0A3C | #x0A3E | #x0A3F | [#x0A40-#x0A42] | [#x0A47-#x0A48] | [#x0A4B-#x0A4D] | [#x0A70-#x0A71] | [#x0A81-#x0A83] | #x0ABC | [#x0ABE-#x0AC5] | [#x0AC7-#x0AC9] | #x0ACB | #x0ACC | [#x0B01-#x0B03] | #x0B3C | [#x0B3E-#x0B43] | [#x0B47-#x0B48] | [#x0B4B-#x0B4C] | [#x0B56-#x0B57] | [#x0B82-#x0B83] | [#x0BBE-#x0BC2] | [#x0BC6-#x0BC8] | [#x0BCA-#x0BCC] | #x0BD7 | [#x0C01-#x0C03] | [#x0C3E-#x0C44] | [#x0C46-#x0C48] | [#x0C4A-#x0C4D] | [#x0C55-#x0C56] | [#x0C82-#x0C83] | [#x0CBE-#x0CC4] | [#x0CC6-#x0CC8] | [#x0CCA-#x0CCC] | [#x0CD5-#x0CD6] | [#x0D02-#x0D03] | [#x0D3E-#x0D43] | [#x0D46-#x0D48] | [#x0D! ! 4A-#x0D4C] | #x0D57 | #x0E31 | [#x0E34-#x0E3A] | [#x0E47-#x0E4E] | #x0EB1 | [#x0EB4-#x0EB9] | [#x0EBB-#x0EBC] | [#x0EC8-#x0ECD] | [#x0F18-#x0F19] | #x0F35 | #x0F37 | #x0F39 | #x0F3E | #x0F3F | [#x0F71-#x0F84] | [#x0F86-#x0F8B] | [#x0F90-#x0F95] | #x0F97 | [#x0F99-#x0FAD] | [#x0FB1-#x0FB7] | #x0FB9 | [#x20D0-#x20DC] | #x20E1 | [#x302A-#x302F] | #x3099 | #x309A | #xFB1E | [#xFE20-#xFE23]
[6] Letter ::= (BaseChar CombiningChar*) | Ideographic
[7] Digit ::= [#x0030-#x0039] /* ISO 646 digits */
| [#x0660-#x0669] /* Arabic-Indic digits */
| [#x06F0-#x06F9] /* Eastern Arabic-Indic digits */
| [#x0966-#x096F] /* Devanagari digits */
| [#x09E6-#x09EF] /* Bengali digits */
| [#x0A66-#x0A6F] /* Gurmukhi digits */
| [#x0AE6-#x0AEF] /* Gujarati digits */
| [#x0B66-#x0B6F] /* Oriya digits */
| [#x0BE7-#x0BEF] /* Tamil digits (no zero) */
| [#x0C66-#x0C6F] /* Telugu digits */
| [#x0CE6-#x0CEF] /* Kannada digits */
| [#x0D66-#x0D6F] /* Malayalam digits */
| [#x0E50-#x0E59] /* Thai digits */
| [#x0ED0-#x0ED9] /* Lao digits */
| [#x0F20-#x0F29] /* Tibetan digits */
| [#xFF10-#xFF19] /* Fullwidth digits */
[8] Ignorable ::= [#x200C-#x200F] /* zw layout */
| [#x202A-#x202E] /* bidi formatting */
| [#x206A-#x206F] /* alt formatting */
| #xFEFF /* zw nonbreak space */
[9] Extender ::= #x00B7 | #x02D0 | #x02D1 | #x0387 | #x0640 | #x0E46 | #x0EC6 | #x3005 | [#x3031-#x3035] | [#x309B-#x309E] | [#x30FC-#x30FE] | #xFF70 | #xFF9E | #xFF9F

A Name is a token beginning with a letter or hyphen and continuing with letters, digits, hyphens, or full stops (together known as name characters). The use of any name beginning with a string which matches "-XML-" in a fashion other than those described in this specification is a reportable error.

A Number is a sequence of digits. An Nmtoken (name token) is any mixture of name characters.

Names, Numbers, and Tokens
[10] MiscName ::= '.' | IgnorableExtender
[11] NameChar ::= LetterDigitMiscName
[12] Name ::= (Letter | '-') (NameChar)*
[13] Nmtoken ::= (NameChar)+
[14] Nmtokens ::= Nmtoken (S Nmtoken)*

Literal data is any quoted string containing neither a left angle bracket nor the quotation mark used as a delimiter. It may contain entity and character references.

Literals
[15] Literal ::= '"' ([^"] | PEReferenceCharRef)* '"' | "'" ([^'] | PEReferenceCharRef)* "'"
[16] QuotedCData ::= '"' ([^"<] | Reference)* '"' | "'" ([^'<] | Reference)* "'"

2. Documents

A textual object is an XML document if it is either valid, or failing that, well-formed, as defined in this specification.

2.1 Logical and Physical Structure

Each XML document has both a logical and a physical structure.

Physically, the document is composed of units called entities; it begins in a "root" or document entity, which may refer to other entities, and so on ad infinitum. Entities referred to are embedded in the document at the point of reference.

The logical structure contains declarations, elements, tags, comments, character references, and processing instructions, all of which are indicated in the document by explicit markup.

The two structures must be synchronous: tags and elements must each begin and end in the same entity, but may refer to other entities internally; comments, processing instructions, character references, and entity references must each be contained entirely within a single entity. Entities must each contain an integral number of elements, comments, processing instructions, and references, possibly together with character data not contained within any element in the entity, or else they must contain non-textual data, which by definition contains no elements.

2.2 Well-Formed XML Documents

A textual object is said to be a well-formed XML document if, first, it matches the production labeled XML Document, and if for each entity reference which appears in the document, the entity name has been declared in the document type declaration.

Matching the "XML Document" production implies that:

  1. It contains one or more elements.
  2. There is exactly one element, called the root, or document element, for which neither the start-tag nor the end-tag is in the content of any other element. For all other elements, if the start-tag is in the content of another element, the end-tag is in the content of the same element. More simply stated, the elements, delineated by start- and end-tags, nest within each other.

As a consequence of this, for each non-root element C, there is one other element P such that C is in the content of P, but is not in the content of any other element that is in the content of P. Then P is referred to as the parent of C, and C as a child of P.

2.3 Characters

The data stored in an XML entity is either text or binary. Binary data has an associated notation, identified by name; beyond a requirement to make available the notation name and the system identifier of the binary data in a storage object, XML provides no information about and places no constraints on binary data. So-called binary data may in fact be textual, perhaps even well-formed XML text; its identification as binary means that an XML processor need not parse it in the fashion described by the specification. XML text data is a sequence of characters. A character is an atomic unit of text represented by a bit string; valid bit strings and their meanings are specified by ISO 10646. Users may extend the ISO 10646 character repertoire, in the rare cases where this is necessary, by exploiting the private use areas.

The mechanism for encoding character values into bit patterns may vary from entity to entity. All XML processors must accept the UTF-8 and UCS-2 encodings of 10646; the mechanisms for signaling which of the two are in use, and for bringing other encodings into play, are discussed later, in the discussion of character encodings.

Regardless of the specific encoding used, any character in the ISO 10646 character set may be referred to by the decimal or hexadecimal equivalent of its bit string.

2.4 Character Data and Markup

XML text consists of intermingled character data and markup. Markup takes the form of start-tags, end-tags, empty elements, entity references, character references, comments, CDATA sections, document type declarations, and processing instructions. The simplest form of XML processor thus could parse a well-formed XML document using the following grammar:

Trivial text grammar
[17] Trivial ::= (PCDataMarkup)*
[18] Eq ::= S? '=' S?
[19] Markup ::= '<' Name (S Name Eq QuotedCData)* S? '>' /* start-tags */
| '</' Name S? '>' /* end-tags */
| '<' Name (S Name Eq QuotedCData)* S? '/>' /* empty elements */
| '&' Name ';' /* entity references */
| '&#' [0-9]+ ';' /* character references */
| '&u-' Hex4 ';' /* character references */
| '<!--' [^-]* ('-' [^-]+)* '-->' /* comments */
| '<![CDATA[' CData ']]>' /* CDATA sections */
| '<!DOCTYPE' [^]]+ ('[' (('<--' [^-]* ('-' [^-]+)* '-->') | ('"' [^"]* '"') | ("'" [^']* "'") | conditionalSect | [^]]* ) ']')? '>' /* doc type declaration */
| '<?' [^?]* ('?' [^>]+)* '?>' /* processing instructions */

Most processors will require the more complex grammar given in the rest of this specification.

All text that is not markup constitutes the character data of the document.

The ampersand character (&) and the left angle bracket (<) may appear in their literal form only when used as markup delimiters, or within comments, processing instructions, or CDATA sections. If they are needed in the text, they must be represented using the strings "&amp;" and "&lt;" The right angle bracket (>) may be represented using the string "&gt;", and must be so represented when it appears in the string "]]>", when that string is not marking the end of a CDATA section.

Parsed character data is thus any string of characters which does not contain the start-delimiter of any markup. Character data is any string of characters not including the CDATA-section-close delimiter, "]]>". To allow attribute values to contain both single and double quotes, the apostrophe or single-quote character (') may be represented as "&apos;", and the double-quote character (") as "&quot;".

Character data
[20] PCData ::= [^<&]*

2.5 Comments

Comments may appear anywhere except in a CDATA section, i.e. within element content, in mixed content, or in a DTD subset. They may not occur within declarations or tags. They are not part of the document's character data; an XML processor may, but need not, make it possible for an application to retrieve the text of comments. For compatibility, the string -- (double-hyphen) may not occur within comments.

Comments
[21] Comment ::= '<!--' [^-]* ('-' [^-]+)* '-->'

An example of a comment:

<!-- declarations for <head> & <body> -->

2.6 Processing Instructions

Processing instructions (PIs) allow the XML processor to pass instructions directly to selected applications.

Processing Instructions
[22] PI ::= '<?' Name S [^?]* ('?' [^>]+)* '?>'

PIs are not part of the document's character data, but must be passed through to the application. The Name is called the PI target. It is normally the name of a declared notation, identifying the application to which it belongs. The use of the PI target "XML" in any way other than those described in this specification is a reportable error.

2.7 CDATA Sections

CDATA sections can occur anywhere character data may occur; they are used to escape blocks of text which may contain characters which would otherwise be recognized as markup. CDATA sections begin with the string <![CDATA[ and end with the string ]]>:

CDATA sections
[23] CDSect ::= CDStart CData CDEnd
[24] CDStart ::= '<![CDATA['
[25] CData ::= [^]]* (((']' ([^]])) | (']]' [^>])) [^]]*)*
[26] CDEnd ::= ']]>'

Within a CDATA section, only the CDEnd string is recognized, so that left angle brackets and ampersands may occur in their literal form and need not be escaped using &lt; and &amp;. CDATA sections cannot nest.

An example of a marked section:

<![CDATA[<greeting>Hello, world!</greeting>]]>

2.8 White Space Handling

In editing XML documents, it is often convenient to use "white space" (spaces, tabs, and blank lines, denoted by the nonterminal S in this specification) to set apart the markup for greater readability. Such white space is typically not intended for inclusion in the delivered version of the document. On the other hand, "significant" white space that must be retained in the delivered version is common; for example in poetry or source code.

In element content, all white space (S) is ignored; validating XML processors must not pass it to the application. Non-validating processors which do not read the DTD must treat all elements as if they were declared with mixed content; this will in some cases result in a different parse tree from that produced by processors which do read the DTD.

In mixed content, an XML processor must provide two distinct white space handling modes, COLLAPSE and PRESERVE, and have the ability to apply these modes on a per-element basis. They operate as follows:

COLLAPSE
The XML processor must suppress (i.e. not pass to the application) all white space in an element which immediately follows the start-tag and all that which immediately precedes the end-tag. In the element's character data, it must convert all sequences of white space characters to a single space (#x0020) character, before passing the data to the application.
PRESERVE
The XML processor must suppress an initial line break character which immediately follows the start-tag of the element, or which which immediately precedes its end-tag. All other characters in the character data of the element must be passed to the application without change.

The white space handling mode is signaled through the use of a reserved attribute; XML processors must behave as though every element encountered in the document had an attribute declared thus:

    -XML-space (preserve|collapse) #IMPLIED

The value of the attribute sets the white space handling mode for the element and for any contained elements, unless they override the inherited value. Unless otherwise specified, an XML processor must set the white space handling mode for the root element of a document to COLLAPSE.

2.9 Prolog and Document Type Declaration

XML documents must begin with an XML declaration which specifies the version of XML being used and optionally also specifies some other information.

The function of the markup in an XML document is to describe its storage and logical structures, and associate attribute-value pairs with the logical structure. XML provides a mechanism, the document type declaration, to define constraints on that logical structure, and to support the use of predefined storage units. An XML document is said to be valid if there is an associated document type declaration and if the document complies with the constraints expressed in it.

The document type declaration must appear before the first element in the document.

XML document
[27] document ::= Prolog element Misc*
[28] Prolog ::= XMLDecl Misc* doctypedecl? Misc*
[29] XMLDecl ::= '<?XML' VersionInfo EncodingDecl? RMDecl? S? '?>'
[30] VersionInfo ::= S 'version' Eq ('"1.0"' | "'1.0'")
[31] Misc ::= CommentPIS

For example, the following is a complete XML document, well-formed but not valid:

<?XML version="1.0"?>
<greeting>Hello, world!</greeting>

The XML document type declaration may include a pointer to an external entity containing a subset of the necessary markup declarations, and may also directly include another, internal, subset.

These two subsets, taken together, are properly referred to as the document type definition, abbreviated DTD. However, it is a common practice for the bulk of the markup declarations to appear in the external subset, and for this subset, usually contained in a file, to be referred to as "the DTD" for a class of documents. The external subset must obey the same grammatical constraints as the internal subset; i.e. it must match the production for internalsubset.

Document type definition
[32] doctypedecl ::= '<!DOCTYPE' S Name (S ExternalID)? S? ('[' internalsubset* ']' S?)? '>'
[33] internalsubset ::= elementdeclAttlistDeclEntityDeclNotationDeclPEReferenceconditionalSectPISComment

For example:

<?XML version="1.0"?>
<!DOCTYPE greeting SYSTEM "hello.dtd">
<greeting>Hello, world!</greeting>

The system identifier hello.dtd indicates the location of a DTD for the document.

The declarations can also be given locally, as in this example:

<?XML version="1.0" encoding="UTF-8" ?>
<!DOCTYPE greeting [
  <!ELEMENT greeting (#PCDATA)>
]>
<greeting>Hello, world!</greeting>

The version label version="1.0" indicates that the document conforms to version 1.0 of the XML specification. The character-set label encoding="UTF-8" indicates that the document entity is encoded using the UTF-8 transformation of ISO 10646.

If both the external and internal subsets are used, the local declarations in the internal subset are read and processed first, followed by those in the external subset. This has the effect that entity declarations in the internal subset take precedence over those in the external subset.

2.10 Required Markup Declaration

In many cases, an XML processor can read an XML document and accomplish useful tasks without having first processed the entire DTD. However, certain declarations can substantially affect the actions of an XML processor. A document author can communicate whether or not DTD processing is necessary using a required markup declaration (abbreviated RMD) processing instruction, which appears as a pseudo-attribute on the XML declaration:

Required markup declaration
[34] RMDecl ::= 'RMD' Eq ('NONE' | 'INTERNAL' | 'ALL')

In an RMD, the value NONE indicates that an XML processor can parse the containing document correctly without first reading any part of the DTD. The value INTERNAL indicates that the XML processor must read and process the internal subset of the DTD to parse the containing document correctly. The value ALL indicates that the XML processor must read and process the declarations in both the subsets of the DTD to parse the containing document directly.

The RMD must indicate that the entire DTD is required if the external subset contains any declarations of

If such declarations occur in the internal but not the external subset, the RMD must take the value INTERNAL. It is an error to specify INTERNAL if the external subset is required, or to specify NONE if the internal or external subset is required.

If no RMD is provided, the effect is identical to an RMD with the value ALL; if neither an internal nor an external subset is provided, however, the value ALL has no visible effect.

An example XML declaration with an RMD:

<?XML version="1.0" RMD='INTERNAL'?>

3. Logical Structures

Each XML document contains one or more elements, the boundaries of which are either delineated by start-tags and end-tags, or, for empty elements, are limited to the start-tag. Each element has a type, identified by name (sometimes called its generic identifier or GI), and may have a set of attributes. Each attribute has a name and a value.

This specification does not constrain the semantics, use, or (beyond syntax) names of the elements and attributes.

3.1 Start- and End-Tags

The beginning of every XML element is marked by a start-tag.

Start-tag
[35] STag ::= '<' Name (S Attribute)* S? '>'
[36] Attribute ::= Name Eq QuotedCData [ VC: Attribute Value Type ]

The Name in the start- and end-tags gives the element's type. The Name-QuotedCData pairs are referred to as the attribute specifications of the element, with the Name referred to as the attribute name and the content of the QuotedCData (the characters between the "'" or '"' delimiters) as the attribute value.

Validity Constraint - Attribute Value Type:
Attribute values must be of the type declared for the attribute. (For attribute types, see the discussion of
attribute declarations.)

An example of a start tag:

<termdef id="dt-stag" term="Start-Tag">

The end of every element which is not empty is marked by an end-tag containing a name that echoes the element's type as given in the start-tag:

End-tag
[37] ETag ::= '</' Name S? '>'

An example of an end-tag:

</termdef>

If an element is empty, the start-tag constitutes the whole element. An empty element takes a special form:

Tags for empty elements
[38] EmptyElement ::= '<' Name (S Attribute)* S? '/>';

An example of an empty element:

<IMG align="left"
 src="http://www.w3.org/pub/WWW/Icons/WWW/w3c_48x48.gif" />

For interoperation with existing Web software, users of XML may desire to create documents which are simultaneously valid XML and processable by existing HTML browsers. The difference in the form of empty elements may be accommodated by using an XML-compatible version of the HTML DTD which allows HTML's empty elements (AREA, BASE, BASEFONT, BR, HR, IMG, INPUT, ISINDEX, LINK, META, and PARAM) to have explicit end-tags.

This might be accomplished by declaring the HTML empty elements using declarations of the following form: <!ELEMENT br - O (br?) -(br) > In documents, such elements would be represented not as <br> but as <br></br>.

The text between the start-tag and end-tag is called the element's content:

Content of elements
[39] content ::= (elementPCDataReferenceCDSectPIComment)* [ VC: Element Content ]
[40] element ::= EmptyElement /* empty elements */
STag content ETag [ WFC: GI Match ]

Validity Constraint - Element Content:
The content of an element instance must match the content model declared for that element type.

Well-Formedness Constraint - GI Match:
The Name in an element's end-tag must match that in the start-tag.

3.2 Element Declarations

The element structure of an XML document may, for the purpose of establishing validity, be constrained using element and attribute declarations, effectively a grammar for a class of documents.

An element declaration constrains the element's type and its content. The content constraints will be described first; four forms are available: empty, any, mixed content, and element content.

Declarations often contain references to element types, for example when constraining which element types can appear as children of others, and which attributes may be attached to which element types. At user option, an XML processor may issue a warning when no element is declared whose type matches that given, but this is not an error.

An element declaration takes the form:

Element declaration
[41] elementdecl ::= '<!ELEMENT' S Name S ('EMPTY' | 'ANY' | Mixedelements) S? '>' [ VC: Unique Element Declaration ]

where Name identifies the type of the element.

Validity Constraint - Unique Element Declaration:
No element type may be declared more than once.

An element declared using the keyword EMPTY must be empty when it appears in the document.

If an element type is declared using the keyword ANY, then there are no constraints on its content aside from its being well-formed: it may contain child elements of any type and number, interspersed with character data.

Some examples of element declarations:

<!ELEMENT br EMPTY>
<!ELEMENT container ANY>

3.2.1 Mixed Content

An element type may be declared to contain mixed content, that is, text comprising character data optionally interspersed with child elements. In this case, the types of the child elements are constrained, but not their order nor their number of occurrences:

Mixed-content declaration
[42] Mixed ::= '(' S? '#PCDATA' ( S? '|' S? Name )* S? ')*'
| '(' S? '#PCDATA' S? ')'

where the Names give the types of elements that may appear as children. The same name may not appear more than once in a single mixed-content declaration.

Some examples of mixed content declarations:

<!ELEMENT p (#PCDATA|a|ul|b|i|em)*>
<!ELEMENT b (#PCDATA)>

3.2.2 Element Content

An element type may be declared to have element content, consisting only of other elements. In this case, the constraint includes a content model, a context-free grammar governing the allowed types of the child elements and the order in which they appear. The grammar is built on content particles (CPs), which consist of names, choice lists of content particles, or sequence lists of content particles:

Element-content models
[43] elements ::= (choiceseq) ('?' | '*' | '+')?
[44] cp ::= (Namechoiceseq) ('?' | '*' | '+')?
[45] cps ::= S? cp S?
[46] choice ::= '(' cps ('|' cps)+ ')'
[47] seq ::= '(' cps (',' cps)* ')'

where each Name gives the type of an element which may appear as a child. Any content particle in a choice list may appear in the element content at the appropriate location; content particles occurring in a sequence list must each appear in the element content in the order given. The optional character following a name or list governs whether the element or the content particles in the list may occur one or more, zero or more, or zero or one times respectively. The syntax and meaning are identical to those used in the productions in this specification.

The content of an element matches a content model if and only if it is possible to trace out a path through the content model, obeying the sequence, choice, and repetition operators and matching each element in the content against an element name in the content model. For compatibility reasons, it is an error if an element in the document can match more than one occurrence of an element name in the content model. More formally: a finite state automaton may be constructed from the content model using the standard algorithms, e.g. algorithm 3.5 in section 3.9 of Aho, Sethi, and Ullman. In many such algorithms, a follow set is constructed for each position in the regular expression (i.e., each leaf node in the syntax tree for the regular expression); if any position has a follow set in which more than one following position is labeled with the same element type name, then the content model is in error and may be reported as an error.

If white space occurs between the children of an element declared with element content, it must be suppressed by any validating XML processor. Non-validating processors may choose not to distinguish element content from mixed content in this way, but risk passing their applications a tree which varies slightly from the correct one, if any white space in the document should be ignored by virtue of being in element content.

Some examples of element content models:

<!ELEMENT spec (front, body, back)>
<!ELEMENT div1 (head, (p | list | note)*, div2*)>

3.3 Attribute-List Declarations

Attributes are used to associate name-value pairs with elements. Attributes may appear only within start-tags; thus, the productions used to recognize them appear in that discussion. Attribute-list declarations may be used:

Attribute-list declarations specify the name, data type, and default value (if any) of each attribute associated with a given element type:

Attribute list declaration
[48] AttlistDecl ::= '<!ATTLIST' S Name AttDef+ S? '>' [ VC: Unique Attribute-List Declaration ]
[49] AttDef ::= S Name S AttType S Default [ VC: Unique Attribute Name ]

The Name in the AttlistDecl rule is the type of an element; it is a reportable error to declare attributes for an element type not itself declared. The Name in the AttDef rule is the name of the attribute.

Validity Constraint - Unique Attribute-List Declaration:
At most one attribute-list declaration may be provided for a given element type.

Validity Constraint - Unique Attribute Name:
An attribute name may appear at most once in an attribute-list declaration.

3.3.1 Attribute Types

XML attribute types are of three kinds: a string type, a set of tokenized types, and enumerated types. The string type may take any literal string as a value; the tokenized types have varying lexical and semantic constraints, as noted:

Attribute types
[50] AttType ::= StringTypeTokenizedTypeEnumeratedType
[51] StringType ::= 'CDATA'
[52] TokenizedType ::= 'ID' [ VC: ID ]
| 'IDREF' [ VC: Idref ]
| 'IDREFS' [ VC: Idref ]
| 'ENTITY' [ VC: Entity Name ]
| 'ENTITIES' [ VC: Entity Name ]
| 'NMTOKEN' [ VC: Name Token ]
| 'NMTOKENS' [ VC: Name Tokens ]

Validity Constraint - ID:
Values of this type must be valid Name symbols. A name must not appear more than once in an XML document as a value of this type: i.e. ID values must uniquely identify the elements which bear them. The XML processor must normalize the case of the attribute value before passing it to the application.

Validity Constraint - Idref:
Values of this type must be one (for IDREFS one or more) Name symbols, which must each match the value of an ID attribute on some element in the XML document; i.e. IDREF values must match some ID. The XML processor must reduce white space to single blanks and normalize the case of the attribute value before passing it to the application.

Validity Constraint - Entity Name:
Values of this type must be one (for ENTITIES one or more) Name symbols, which must each
exactly match the name of an external binary entity declared in the XML DTD. The XML processor must reduce white space to single blanks before passing the attribute value to the application.

Validity Constraint - Name token:
Values of this type must consist of a string matching the Nmtoken nonterminal of the grammar defined in this specification. The XML processor must normalize the case of the attribute value before passing it to the application.

Validity Constraint - Name tokens:
Values of this type must consist of a string matching the Nmtokens nonterminal of the grammar defined in this specification. The XML processor must reduce white space to single blanks, and normalize the case of the attribute value, before passing it to the application.

Enumerated attributes can take one of a list of values provided in the declaration; there are two types:

Enumerated attribute types
[53] EnumeratedType ::= NotationTypeEnumeration
[54] NotationType ::= 'NOTATION' S '(' S? Name (S? '|' S? Name)* S? ')' [ VC: Notation Attributes ]
[55] Enumeration ::= '(' S? Nmtoken (S? '|' S? Nmtoken)* S? ')' [ VC: Enumeration ]

Validity Constraint - Notation Attributes:
The names in the declaration of NOTATION attributes must be names of declared notations (see the discussion of
notations). Values of this type must match one of the notation names included in the declaration.

Validity Constraint - Enumeration:
Values of this type must match one of the Nmtoken tokens in the declaration.
For compatibility reasons, the same Nmtoken may not occur more than once in the enumerated attribute types of a single attribute-list declaration.

3.3.2 Attribute Defaults

An attribute declaration may provide information on whether the attribute's presence is required, and if not, how an XML processor should react if a declared attribute is absent in a document:

Attribute defaults
[56] Default ::= '#REQUIRED' | '#IMPLIED' | ('#FIXED'? QuotedCData)

#REQUIRED means that it is a reportable error should the processor encounter a start-tag where this attribute is omitted, i.e. could occur but does not. #IMPLIED means that if an attribute is omitted, the XML processor must inform the application that no value was specified; no constraint is placed on the behavior of the application.

If the attribute is neither #REQUIRED nor #IMPLIED, then the QuotedCData value contains the declared default value. If the #FIXED is present, it is a reportable error if the attribute is present with a different value from the default. If a default value is declared, when an XML processor encounters an omitted attribute, it is to assume that the attribute is present and has the declared default value.

Examples of attribute-list declarations:

<!ATTLIST termdef
          id      ID      #REQUIRED
          name    CDATA   #IMPLIED>
<!ATTLIST list
          type    (bullets|ordered|glossary)  "ordered">
<!ATTLIST form
          method  CDATA   #FIXED "POST">

3.3.3 Attribute-Value Normalization

Before the value of an attribute is passed to the application, the XML processor must normalize it as follows:

  1. Record-ends must be replaced by single blanks.
  2. Character references and references to internal text entities must be expanded. References to external entities are a reportable error.
  3. If the attribute is not of type CDATA, all strings of white space must be normalized to single space characters.
  4. Values of type ID, IDREF, IDREFS, NMTOKEN, NMTOKENS, or of enumerated or notation types, must be folded to uppercase.

3.4 Conditional Sections

Conditional sections are portions of the document type declaration internal or external subset, which are included in, or excluded from, the logical structure of the DTD based on the keyword which governs them.

Conditional section
[57] conditionalSect ::= '<![' CSKey '[' csdata ']]>'
[58] CSKey ::= PEReference | 'INCLUDE' | 'IGNORE'
[59] csdata ::= internalsubset

Like the internal and external DTD subsets, a conditional section may contain one or more complete declarations, comments, or nested conditional sections, intermingled with white space. Conditional sections may not occur within declarations, except the document-type declaration.

If the CSKey of the conditional section is INCLUDE, then the conditional section is read and processed in the normal way. If the CSKey is IGNORE, then the declarations within the conditional section are ignored; the processor must read the conditional section to detect nested conditional sections and ensure that the end of the outermost (ignored) conditional section is properly detected. If a conditional section with a keyword of INCLUDE occurs within a larger conditional section with a keyword of IGNORE, both the outer and the inner conditional sections are ignored.

If the CSKey of the conditional section is a parameter entity reference, the parameter entity is replaced by its value (recursively if necessary) before the processor decides whether to include or ignore the conditional section.

An example:

<!ENTITY % Unix 'INCLUDE' >
<!ENTITY % DOS  'IGNORE' >

<![%DOS;[
<!ENTITY dir-command '<command>dir</command>' >
]]>
<![%Unix;[
<!ENTITY dir-command '<command>ls -l</command>' >
]]>

4. Physical Structures

An XML document may consist of one or many storage units. The unit of storage is the entity; entities are identified by name and have content. Each XML document has one entity called the document entity, which serves as the starting point for the XML processor (and may contain the whole document).

Entitities may be either binary or text. A text entity contains text data which is to be considered as an integral part of the document. A binary entity contains binary data identified by notation. Text and binary entities cannot be distinguished by syntax; their types are established in their declarations.

4.1 Character and Entity References

A character reference refers to a specific character in the ISO 10646 character set, often one not directly accessible from available input devices:

Character reference
[60] Hex ::= [0-9a-fA-F]
[61] Hex4 ::= Hex Hex Hex Hex
[62] CharRef ::= '&#' [0-9]+ ';' | '&u-' Hex4 ';'

Names of the form u- followed by four hexadecimal digits) must be used only for character references; any other use is a reportable error.

An entity reference refers to the content of a named entity. General entities are text entities for use within the document itself; references to them use ampersand and semicolon as delimiters. Parameter entities are text entities for use within the DTD, or within conditional sections; references to them use percent-sign and semicolon as delimiters.

Entity Reference
[63] Reference ::= EntityRefCharRef
[64] EntityRef ::= '&' Name ';' [ WFC: Entity Declared ]
[ WFC: Text Entity ]
[ WFC: No Recursion ]
[65] PEReference ::= '%' Name ';' [ WFC: Entity Declared ]
[ WFC: No Recursion ]
[ WFC: In DTD ]

Well-Formedness Constraint - Entity Declared:
The Name given in the entity reference must
match exactly the name given in the declaration of the entity. In the case of parameter entities, the declaration must precede the reference.

Well-Formedness Constraint - Text Entity:
An entity reference may not contain the name of a
binary entity. Binary entities may be referred to only in attribute values declared to be of type ENTITY or ENTITIES.

Well-Formedness Constraint - No Recursion:
A text or parameter entity may not contain a reference to itself or to any entity open where it is referred to.

Well-Formedness Constraint - In DTD:
A parameter entity reference is recognized only within the internal and external DTD subsets and as the keyword to a
conditional section.

Examples of character and entity references:

"&u-0020;" and "&u-0009;" are space characters
"&Pub-Status;" is an entity reference

Example of a parameter-entity reference:

<!ENTITY % ISOLat2
         SYSTEM "http://www.xml.com/iso/isolat2-xml.entities" >
%ISOLat1;

4.2 Entity Declarations

Entities are declared thus:

Entity declaration
[66] EntityDecl ::= '<!ENTITY' S Name S EntityDef S? '>' /* General entities */
| '<!ENTITY' S '%' S Name S EntityDef S? '>' /* Parameter entities */
[67] EntityDef ::= LiteralExternalDef;

The Name is that by which the entity is invoked by exact match in an entity reference. If the same entity is declared more than once, the first declaration encountered is binding; at user option, an XML processor may issue a warning if entities are declared multiple times.

4.2.1 Internal Entities

If the entity definition is just a Literal, this is called an internal entity. There is no separate storage unit, and the content of the entity is given in the declaration. An internal entity is a text entity.

Example of an internal entity declaration:

<!ENTITY Pub-Status "This is a pre-release of the
 specification.">

4.2.2 External Entities

If the entity is not internal, it is an external entity, declared as follows:

External entity declaration
[68] ExternalDef ::= ExternalID NDataDecl?
[69] ExternalID ::= 'SYSTEM' S SystemLiteral
[70] SystemLiteral ::= '"' [^"]* '"' | "'" [^']* "'"
[71] NDataDecl ::= S 'NDATA' S Name [ VC: Notation Declared ]

If the NDataDecl is present, this is a binary data entity, otherwise a text entity.

Validity Constraint - Notation Declared:
The Name must match the declared name of a
notation.

The Literal that follows the keyword SYSTEM is called the entity's system identifier. It is a URL, which may be used to retrieve the content of the entity. Relative URLs are relative to the location of the entity or file within which the entity declaration occurs. Relative URLs in entity declarations within the internal DTD subset are thus relative to the location of the document; those in entity declarations in the external subset are relative to the location of the files containing the external subset.

Examples of external entity definitions:

<!ENTITY open-hatch
         SYSTEM "http://www.textuality.com/boilerplate/OpenHatch.xml">
<!ENTITY hatch-pic
         SYSTEM "../grafix/OpenHatch.gif"
         NDATA gif >

4.2.3 Character Encoding in Entities

Each text entity in an XML document may use a different encoding for its characters. All XML processors must be able to read entities in either the UTF-8 or the UCS-2 encoding. It is recognized that for some purposes, particularly work with Asian languages, the use of the UTF-16 encoding is required, and correct handling of this encoding is a desirable characteristic in XML processor implementations.

Entities encoded in UCS-2 must begin with the Byte Order Mark described by ISO 10646 Annex E and Unicode Appendix B (the ZERO WIDTH NO-BREAK SPACE character, U+FEFF). This is an encoding signature, not part of either the markup or character data of the XML document. XML processors must be able to use this character to differentiate between UTF-8 and UCS-2 encoded documents.

Although an XML processor is only required to read entities in the UTF-8 and UCS-2, it is recognized that many other encodings are in daily use around the world, and it may be advantageous for XML processors to read entities that use these non-standard encodings. For this purpose, XML provides an encoding declaration processing instruction, which must appear at the beginning of a system entity, before any other character data or markup. In the document entity, the encoding declaration is part of the XML declaration; in other entities, it is a free-standing processing instruction:

Encoding declaration
[72] EncodingDecl ::= S 'encoding' Eq QEncoding
[73] EncodingPI ::= '<?XML' S 'encoding' Eq QEncoding S? '?>'
[74] QEncoding ::= '"' Encoding '"' | "'" Encoding "'"
[75] Encoding ::= LatinName
[76] LatinName ::= [A-Za-z] ([A-Za-z0-9] | '-' | '.')* /* Name comprising only Latin characters */

The values UTF-8, UTF-16, UCS-2, and UCS-4 should be used for the various encodings of Unicode / ISO 10646, the values ISO8859-1, ISO8859-2, ... ISO8859-9 should be used for the parts of ISO 8859, and the values ISO-2022-JP, Shift-JIS, and EUC-JIS. should be used for the various encoded forms of JIS X-0208. XML processors may recognize other encodings; it is recommended that character encodings registered with the Internet Assigned Numbers Authority (IANA), other than those just listed, should be referred to using their registered names.

It is an error for an entity including an encoding declaration to be stored in an encoding other than that named in the declaration.

An entity which begins with neither a Byte Order Mark nor an encoding declaration must be in the UTF-8 encoding.

While XML provides mechanisms for distinguishing encodings, it is recognized that in a heterogeneous networked environment, there is often difficulty in reliably signaling the encoding of an entity. Errors in this area fall into two categories:

  1. failing to read an entity because of inability to recognize its actual encoding, and
  2. reading an entity incorrectly because of an incorrect guess of its proper encoding.
The first class of error is extremely damaging, and the second class is extremely unlikely. For these reasons, XML processors should make an effort to use all available information, internal and external, to aid in detecting an entity's correct encoding. Such information may include, but is not limited to: If an XML processor encounters an entity with an encoding that it is unable to process, it may inform the application of this fact and allow the application to request either that the entity should be treated as an binary entity, or that processing should cease.

Examples of encoding declarations:

<?XML ENCODING='UTF-8'?>
<?XML ENCODING='EUC-JIS'?>

4.2.4 Document Entity

The document entity serves as the root of the entity tree and a starting-point for an XML processor. This specification does not specify how the document entity is to be located by an XML processor; unlike other entities, the document entity might well appear on an input stream of the processor without any identification at all.

4.3 XML Processor Treatment of Entities

When an XML processor encounters a character reference or an entity reference in parsed character data, or the name of an external binary entity as the value of an ENTITY or ENTITIES attribute:

  1. In all cases, the XML processor may inform the application of the reference's occurrence and its identifier (for an entity reference, the name; for a character reference, the "&...;" string.)
  2. For both character and entity references, the processor must remove the reference itself from the text data before passing the data to the application.
  3. For character references, the processor must insert the indicated ISO 10646 bit pattern into the text data at the location of the reference before passing it to the application.
  4. For an external entity, the processor must inform the application of the entity's system identifier.
  5. If the external entity is binary, the processor must inform the application of the associated notation name, and the notation's associated system identifier.
  6. For an internal (text) entity, the processor must include the entity; that is, retrieve its content, and treat the content as a part of the text data of the XML document, processing this replacement text data (which may contain both text and markup) to determine what data to pass to the application. Since the entity's content text may contain other entity references, an XML processor may have to repeat the inclusion process recursively.
  7. If the entity is an external text entity, then in order to validate the XML document, the processor must include the content of the entity.
  8. If the entity is an external text entity, and the processor is not attempting to validate the XML document, the processor may, but need not, include the entity's content. This rule is based on the recognition that the inclusion semantic provided by the SGML and XML text entity mechanism, primarily designed to support modularity in authoring, may not be appropriate for other applications, in particular document browsing. Browsers, for example, when encountering an external text entity reference, might choose to provide a visual indication of the entity's presence and retrieve it for display only on demand. While this behavior would not allow the application to validate the document, it is compliant with this specification.

4.4 Notation Declarations

Notations identify by name the format of external binary entities.

Notation declarations provide a name for the notation, for use in entity and attribute-list declarations and in attribute-value specifications, and an external identifier for the notation which may allow an XML processor or its client application to locate a helper application capable of processing data in the given notation.

Notation declarations
[77] NotationDecl ::= '<!NOTATION' S Name S ExternalID S? '>'

XML processors must provide applications with the name and external identifier of any notation declared and referred to in an attribute value, attribute definition, or entity declaration. They may additionally resolve the external identifier into the system identifier, file name, or other information needed to allow the application to call a processor for data in the notation described. (It is not an error, however, for XML documents to declare and refer to notations for which notation-specific applications are not available on the system where the XML processor or application is running.)

5. Conformance

Conforming XML processors fall into two classes: validating and non-validating.

Validating and non-validating systems alike must report violations of the well-formedness constraints given in this specification.

Validating systems must report locations in which the document does not comply with the constraints expressed by the declarations in the DTD. They must also report all failures to fulfill the validity constraints given in this specification.


Appendices

A. XML and SGML

XML is designed to be a subset of SGML, in that every valid XML document should also be a valid SGML document, using the same DTD, and that the parse trees produced by an SGML parser and an XML processor should be the same. To achieve this, XML was defined by removing features and options from the specification of SGML.

Despite this, there are a small number of cases where XML fails to be a pure subset of SGML, including:

The following list describes features which are available in SGML but not in XML. It may not be complete.

The specific SGML declaration needed to enable SGML systems to process XML documents will vary from document to document, depending on the character set and the capacities and quantities required. Documents in Unicode UCS-2 form should be able to use the following SGML declaration:

<!SGML "ISO 8879:1986"
    CHARSET
        -- The CHARSET section is unchanged from the typical SGML
           declaration for basic SGML document, Figure 8, pg 479 in
           the Handbook. --
        BASESET "ISO 646-1983//CHARSET 
                         International Reference Version (IRV)
                         //ESC 2/5 4/0"
        DESCSET
              0    9    UNUSED
              9    2    9
             11    2    UNUSED
             13    1    13
             14   18    UNUSED
             32   95    32
            127    1    UNUSED
        BASESET "ISO Registration Number 109//CHARSET
                 ECMA-94 Right Part of Latin Alphbet 
                 Nr. 3//ESC 2/13 4/3"
        DESCSET
            128   32    UNUSED
            160    5    32
            165   89    32
            254    1    127
            255    1    UNUSED

    CAPACITY SGMLREF
        -- Capacities are not restricted in XML --
        TOTALCAP    99999999
        ENTCAP      99999999
        ENTCHCAP    99999999
        ELEMCAP     99999999
        GRPCAP      99999999
        EXGRPCAP    99999999
        EXNMCAP     99999999
        ATTCAP      99999999
        ATTCHCAP    99999999
        AVGRPCAP    99999999
        NOTCAP      99999999
        NOTCHCAP    99999999
        IDCAP       99999999
        IDREFCAP    99999999
        MAPCAP      99999999
        LKSETCAP    99999999
        LKNMCAP     99999999

    SCOPE DOCUMENT

    SYNTAX
        SHUNCHAR NONE
        BASESET "ISO 646-1983//CHARSET 
                 International Reference Version (IRV)
                 //ESC 2/5 4/0"
        DESCSET 
            0 128 0
        FUNCTION
            RE      13
            RS      10
            SPACE   32
            TAB     SEPCHAR    9
        NAMING
            -- '-' is an allowed name start character in XML --
            LCNMSTRT    "-"
            UCNMSTRT    "-"
            LCNMCHAR    "."    -- Moved '-' to LCNMSTRT --
            UCNMCHAR    "."    -- Moved '-' to UCNMSTRT --
            NAMECASE
                GENERAL     YES
                ENTITY      NO
        DELIM
            GENERAL    SGMLREF
                NET    "/>"
                PIC    "?>"
            SHORTREF   SGMLREF
        NAMES SGMLREF
        QUANTITY SGMLREF
            -- Quantities are not restricted in XML --
            ATTCNT      99999999
            ATTSPLEN    99999999
            -- BSEQLEN          NOT USED --
            -- DTAGLEN          NOT USED --
            -- DTEMPLEN         NOT USED --
            ENTLVL      99999999
            GRPCNT      99999999
            GRPGTCNT    99999999
            GRPLVL      99999999
            LITLEN      99999999
            NAMELEN     99999999
            -- NORMSEP          NO NEED TO CHANGE IT --
            PILEN       99999999
            TAGLEN      99999999
            TAGLVL      99999999

    FEATURES
        MINIMIZE
            DATATAG     NO
            OMITTAG     NO
            RANK        NO
            -- SHORTTAG is the only allowed feature. It is required. --
            SHORTTAG    YES    -- SHORTTAG is needed for NET --

        LINK
            SIMPLE      NO
            IMPLICIT    NO
            EXPLICIT    NO
        
        OTHER
            CONCUR      NO
            SUBDOC      NO
            FORMAL      NO
    
    APPINFO    NONE
>

B. References

Aho/Ullman
Aho, Alfred V., Ravi Sethi, and Jeffrey D. Ullman. Compilers: Principles, Techniques, and Tools. Reading: Addison-Wesley, 1986, rpt. corr. 1988.
Brüggemann-Klein
Brüggemann-Klein, Anne. Regular Expressions into Finite Automata. Universität Freiburg, Institut für Informatik, Bericht 33, Juli 1991.
Brüggemann-Klein
Brüggemann-Klein, Anne, and Derick Wood. Deterministic Regular Languages. Universität Freiburg, Institut für Informatik, Bericht 38, Oktober 1991.
ISO/IEC 8879
ISO (International Organization for Standardization). ISO/IEC 8879-1986 (E). Information processing -- Text and Office Systems -- Standard Generalized Markup Language (SGML). First edition -- 1986-10-15. [Geneva]: International Organization for Standardization, 1986.
ISO/IEC 10646
ISO (International Organization for Standardization). ISO/IEC 10646-1993 (E). Information technology -- Universal Multiple-Octet Coded Character Set (UCS) -- Part 1: Architecture and Basic Multilingual Plane. [Geneva]: International Organization for Standardization, 1993.
ISO/IEC 10744
ISO (International Organization for Standardization). ISO/IEC 10744-1992 (E). Information technology -- Hypermedia/Time-based Structuring Language (HyTime). [Geneva]: International Organization for Standardization, 1992. Extended Facilities Annexe. [Geneva]: International Organization for Standardization, 1996.
IETF RFC 1738
IETF (Internet Engineering Task Force). RFC 1738: Uniform Resource Locators. 1991.
Unicode
The Unicode Consortium. The Unicode Standard: Version 2.0. Reading, Mass.: Addison-Wesley Developers Press, 1996.

C. Deterministic Content Models

For compatibility, it is required that content models in element declarations be deterministic. SGML requires deterministic content models (it calls them `unambiguous'); XML processors built using SGML systems may flag non-deterministic content models as errors.

For example, the content model ((b, c) | (b, d)) is non-deterministic, because given an initial b the parser cannot know which b in the model is being matched without looking ahead to see which element follows the b. In this case, the two references to b can be collapsed into a single reference, making the model read (b, (c | d)). An initial b now clearly matches only a single name in the content model. The parser doesn't need to look ahead to see what follows; either c or d would be accepted.

Algorithms exist which allow many but not all non-deterministic content models to be reduced automatically to equivalent deterministic models; see Brüggemann-Klein 1991.

D. Production note

The printed copy of this draft specification was generated automatically from an XML source file by the Jade DSSSL engine under control of a DSSSL stylesheet. Table of Contents generation, headers, footers, page numbering, section numbering, and table layout were all performed by the DSSSL application. RTF output from Jade was then brought into Microsoft Word for final page-break adjustments and conversion to PostScript for the generation of camera-ready copy.

The HTML copy of this draft specification was generated automatically from an XML source file using a custom formatter written in perl.

E. W3C SGML Working Group and Editorial Review Board

E.1 W3C SGML Working Group

This specification was prepared with the assistance and participation of the W3C SGML Working Group. Publication of this specification does not necessarily imply that all members of the working group agree with its content. At the time this specification was prepared, the W3C SGML Working Group comprised the following members:

Sharon Adler, EBT; Paula Angerstein, Texcel; Murray Altheim, Spyglass; Todd Bauman, U. of Maryland; Anders Berglund, EBT; Karl Best, Novell; Michel Biezunski, High Text; Harvey Bingham, SGML consultant; Jon Bosak, Sun; Tim Bray, Textuality; Steve Brown, InfoObjects; Martin Bryan, SGML Centre; Mark Buckley, Microsoft; Len Bullard, Lockheed-Martin; Lou Burnard, Oxford University; Steve Byrne, JavaSoft; James Clark; Dan Connolly, W3C; Kurt Conrad, Sagebrush Group; Paul Cope, auto-graphics; Keith Corbett, Harlequin; Robin Cover, SIL; Derek Denny-Brown, TechnoTeacher; Steve DeRose, EBT; Dave Durand, Boston University; Carol Ellerbeck, INSO; Joe English, CR Laboratories; Ralph Ferris, Fujitsu OSSI; Lee Fogal, Digital Equipment; Todd Freter, Novell; Matthew Fuchs, Disney Imagineering; Charles Goldfarb, Information Management Consulting; Paul Grosso, ArborText; Eduardo Gutentag, Sun; Hasse Haitto, Synex; Catherine Hamon, Hightext; Dave Hollander, HP; Ken Holman, Microstar; John Iobst, Newspaper Assoc. of America; Rick Jelliffe, Allette Systems; Alan Karben, Wall Street Journal; Pär Karlsson, Ericsson; Eliot Kimber, Passage Systems; Debbie Lapeyre, Mulberry Technologies; John Lavagnino, Martin Hensel/Brown U.; Bill Lindsey, BDM Technologies; Per Åke Ling, Ericsson; Megan MacMillan, BDM Technologies; Christopher Maden, EBT; Tom Magliery, NCSA; Eve Maler, ArborText; Murray Maloney, SoftQuad; James Mason, ORNL; Alex Milowski, Copernican Solutions; Ed Mooney, Sun Microsystems; Steve Newcomb, TechnoTeacher; Gavin Nicol, EBT; Nancy Paisner, Hitachi; Gary Palmer, ActiveSystems; Jean Paoli, Microsoft; Dave Peterson, SGMLWorks!; Martin Pike, Stilo; Paul Prescod, U. of Waterloo; Lynne Price, SGML consultant; Liam Quin, SoftQuad; Arjun Ray, Q2-II; Peter Sharpe, SoftQuad; Bill Smith, Sun; C. M. Sperberg-McQueen, U. of Ill.; Bob Stayton, SCO; Robert Streich, Schlumberger; Jeff Suttor, Sun; James Tauber, U. of Western Australia; Wayne Taylor, Novell; Henry Thompson, U. of Edinburgh; Sarah G.E. Tourville, SAGRELTO; Sam Wilmott, OmniMark; Chris Wilson, Microsoft; Wayne Wohler, IBM; Lauren Wood, SoftQuad;

E.2 W3C SGML Editorial Review Board

This specification was prepared and approved for publication by the W3C SGML Editorial Review Board (ERB). ERB approval of this specification does not necessarily imply that all ERB members voted for its approval. At the time it approved this specification, the SGML ERB comprised the following members:

Jon Bosak, Sun (Chair); James Clark (Technical Lead); Tim Bray, Textuality (Co-editor); C. M. Sperberg-McQueen, U. of Ill. (Co-editor); Steve DeRose, EBT; Dave Hollander, HP; Eliot Kimber, Highland; Tom Magliery, NCSA; Eve Maler, ArborText; Jean Paoli, Microsoft; Peter Sharpe, SoftQuad;