[Mirrored (November 04, 1996) from: http://www.textuality.com/sgml-erb/WD-xml.html]
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.
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.
Note on status of this document: This is even more of a moving target than the typical W3C working draft. Several important decisions on the details of XML are still outstanding - members of the W3C SGML Working Group will recognize these areas of particular volatility in the spec, but those who are not intimately familiar with the deliberative process should be careful to avoid actions based on the content of this document, until the notice you are now reading has been removed.
Extensible Markup Language, abbreviated XML, describes a class of data objects stored on computers and partially describes the behavior of programs which process these objects. Such objects are called XML documents. 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, structure, and arbitrary attribute-value pairs associated with that 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 some of the required behavior of an XML processor in terms of the manner it must read XML data, and the information it must provide to the application.
XML was developed by a Generic SGML Editorial Review Board formed under the auspices of the W3 Consortium in 1996 and chaired by Jon Bosak of Sun Microsystems, with the very active participation of a Generic SGML Working Group also organized by the W3C. The membership of these groups is given in an appendix.
The design goals for XML are:
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 (0.01) is for internal discussion within the SGML ERB only. It should not be distributed outside the ERB.
Known problems in version 0.01:
Other standards relevant to users and implementors of XML include:
The formal grammar of XML is given using a simple Extended Backus-Naur Form (EBNF) notation. Each rule in the grammar defines one non-terminal or terminal symbol of the grammar, in the form
symbol ::= expression |
Symbols are written with an initial capital letter if they are defined by a regular expression, with an initial lowercase letter if they have a more complex definition (i.e. if they require a stack for proper recognition). Literal strings are quoted; unless otherwise noted they are not case-sensitive. The distinction between symbols which can and cannot be recognized using simple regular-expressions is made for clarity only. It may be reflected in the boundary between an implementation's lexical scanner and its parser, but there is are no assumptions about the placement of such a boundary, nor even that the implementation has separate modules for parser and lexical scanner.
Within the expression on the right-hand side of a rule, the meaning of symbols is as shown below:
#NN
#xNN
[#xNN-#xNN]
, [a-zA-Z]
[^#xNN-#xNN]
, [^a-z]
[^abc]
"string"
'string'
a b
a | b
a?
a+
a*
(expression)
?
, *
, or +
/* ... */
[ WFC: ... ]
[ VC: ... ]
Some terms used with special meaning in this specification are:
may
must
error
reportable error
validity constraint
well-formedness constraint
at user option
match
exact(ly) match
for compatibility
This section defines some symbols used widely in the grammar.
S (white space) consists of one or more blank characters, carriage returns, line feeds, or tabs.
< 1 White space > | |||
|
For some purposes, characters are classified as letters, digits, or other characters:
< 2 Name > | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
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.
< 3 Names, Numbers, and Tokens > | ||||||||||||
|
Literal data is any quoted string containing neither the quotation mark used as a delimiter nor angle brackets. It may contain entity and character references.
< 4 Literals > | |||||||||||||||
|
A textual object is an XML Document if it is either valid, or failing that, well-formed, as defined in this specification.
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 document contains declarations, elements, comments, entity references, character references, and processing instructions, all of which are indicated in the document by explicit markup. These concepts and their markup are all explained elsewhere in this specification.
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.
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 size in bytes of the binary data in a storage object, XML provides no information about and places no constraints on binary data. In fact, so-called binary data may in fact be textual, perhaps even well-formed XML text; but 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 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 making use of 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 signalling 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:
< 5 Character references > | ||||||||||||
|
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, marked sections, document type declarations, and processing instructions. The simplest form of XML processor thus could parse a well-formed XML document using the following rules:
< 6 Trivial text grammar > | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
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 and right angle bracket (< and >) may appear in their literal form only when used as markup delimiters, or within comments, processing instructions, or marked sections. If they are needed in the text, they must be represented using the strings "&
", "<
", and ">
". 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 marked-section-close delimiter, "]]>
". For convenience, the single-quote character (') may be represented as "&sq;
", and the double-quote character (") as "&dq;
".
< 7 Character Data > | ||||||
|
Comments may appear anywhere that character data may, except in a marked section (more properly, comments appearing in a marked section will not be recognized as such). 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. An XML processor must inform the application of the length of comments if they are not passed through, to enable the application to keep track of the correct location of objects in the XML document. For compatibility, the string -- (double-hyphen) may not occur within comments.
< 8 Comments > | |||
|
< 9 Processing Instructions > | |||
|
PIs are not part of the document's character data, but must be passed through to the application. The Name which follows the '?' at the beginning of the PI 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 other way other than those described in this specification is a reportable error.
< 10 Marked Sections > | |||||||||
|
Within a marked section, only the MsEnd string is recognized, so that angle brackets and ampersands may occur in their literal form and need not be escaped using <
, etc. Marked sections cannot nest.
While authoring XML documents, it is often convenient to use "white space" (spaces, tabs, 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, to be retained in the delivered version, is common; for example in poetry or source code.
An XML processor must provide two distinct white space handling modes, COLLAPSE and KEEP, and have the ability to apply these modes on a per-element basis. They operate as follows:
COLLAPSE
KEEP
The white space handling mode is signaled through the use of a reserved attribute, whose declaration is as follows:
<!ATTLIST * -XML-SPACE (KEEP|COLLAPSE) #IMPLIED> |
where the "*" signifies that this attribute may apply to any element.
The value of the attribute sets the white space handling mode for the element and for any contained elements. Unless otherwise specified, an XML processor is to set the white space handling mode for the root element of a document to COLLAPSE.
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.
< 11 XML document > | |||||||||
|
For example, the following is a complete XML document, well-formed but not valid:
<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 of the necessary markup declarations.
< 12 Document type declaration > | |||||||||
|
<!DOCTYPE greeting SYSTEM "hello.dtd"> |
The system identifier hello.dtd
indicates the location of a full DTD for the document.
The declarations can also be given locally, as in this slightly larger example:
<?XML encoding="UTF-8"> |
The character-set label <?XML encoding="UTF-8">
indicates that the document entity is encoded using the UTF-8 transformation of ISO 10646. The legal values of the character set code are given in the discussion of character encodings.
Individual markup declaration types are described elsewhere in this specification.
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:
< 13 Required markup declaration > | |||
|
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 no RMD is provided, the effect is identical to an RMD with the value ALL.
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.
The beginning of every XML element is marked by a start-tag.
< 14 Start-tag Recognition > | ||||||||
|
The Name in the start- and end-tag rules gives the element's type. The Name-QuotedCData pairs are referred to as the attributes 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.)
The end of every element which is not empty is marked by an end-tag:
< 15 End-tag Recognition > | |||
|
The Name, once again, gives the element's type.
< 16 Tags for empty elements > | |||
|
For compatibility, an empty element may have the same syntax as a start-tag; in this case, it cannot be recognized based on syntax, but must be declared as being empty. Such elements are called undistinguished empty elements.
The text between the start-tag and end-tag is called the element's content:
< 17 Content of elements > | |||||||||||||
|
A textual object is said to be a well-formed XML document if, first, it matches the production above labeled XML Document, and if:
Matching the "XML Document" production implies that:
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 the child of P.
The element structure of an XML document may be declared fully or partially. Such declarations serve two purposes:
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:
< 18 Element declarations > | |||||
|
where Name identifies the type of the element.
Validity Constraint - Unique Element Declaration:
No element type may be declared more than once.
For compatibility, an element type may be declared using the keyword EMPTY; this is an undistinguished empty element.
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 subelements of any type and number, interspersed with character data.
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:
< 19 Mixed-content declaration > | ||||||
|
where the Names give the types of elements that may appear as children.
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:
< 20 Element-content models > | |||||||||||||||
|
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 is identical to that used in the productions in this specification.
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 declarations may be used:
< 21 Attribute list declaration > | ||||||||||
|
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.
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:
< 22 Attribute types > | |||||||||||||||||||||||||||||||||||||||||
|
Validity Constraint - ID:
Values of this type must be valid Names. 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.
Validity Constraint - Idref:
Values of this type must be one (for IDREFS one or more) Names, 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.
Validity Constraint - Entity Name:
Values of this type must be one (for ENTITIES one or more) Names, which must each exactly match the name of an external binary entity declared in the XML DTD.
Enumerated attributes can take one of a list of values provided in the declaration; there are two types:
< 23 Enumerated attribute declarations > | |||||||||||||
|
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.
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:
< 24 Attribute defaults > | |||||||||
|
#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 Literal 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.
The prolog of an XML document may contain an abbreviated summary of the DTD for the convenience of non-validating processors.
< 25 DTD summary > | ||||||||||||||||||||||||||||||
|
The empty, text, and notext declarations give, respectively, lists of element types declared as empty, mixed-content, or element-content elements. The idinfo declaration lists attributes declared as id or idref(s) (in the ids and refs values, respectively). Each attribute name is given as an element-attribute pair; an asterisk matches all element types which have attributes of the given name. The default declaration specifies default values for the attributes of a given element type.
For example:
<?XML empty names="ptr xptr pb" ?> |
Elements not listed as notext
are implicitly declared as text
elements; the text declaration is thus not strictly necessary.
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, described below.
< 26 Character Reference > | ||||||
|
An entity reference refers to the content of a named entity.
< 27 Entity Reference > | ||||||||||||||||||
|
Well-Formedness Constraint - Entity Declared:
The Name given in the entity reference must match exactly the name given in the declaration of the entity.
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 entity may not contain a reference to itself.
Entities are declared thus:
< 28 Entity declaration > | ||||||
|
The Name is that by which the entity is invoked by exact match in an entity reference.
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.
If the entity is not internal, it is an external entity, declared as follows:
< 29 External entity declaration > | ||||||||
|
If the NDataDecl is present, this is a binary data entity, otherwise a text entity.
Validity Constraint - Notation Declared:
The Name must match one of those in a notation declaration.
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 UCS-2 encodings. It is recognized that for for some advanced work, particularly 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 an entity, before any other character data or markup:
< 30 Encoding declaration > | |||||||||||||||||||||
|
It is a reportable 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:
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.
When an XML processor encounters a character reference or an entity name (in a reference or attribute value):
&...
" string.)Notations identify by name the format of external binary entities.
< 31 Notation declarations > | |||
|
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, API address, 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.)
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.
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.
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.
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 had the following members: