<!DOCTYPE spec system "spec.dtd" [

<!-- new unnumbered version by bosak 1997.08.07:
	date changed to Aug. 7
	trailing .html removed from visible URLs
	SGML ERB changed to XML WG throughout
	Maloney added to WG list, Paoli moved up
	trailing space removed from </prod> tags
	numeric char refs #252 and #228 replaced by latin-8 codes
        "Part 1. Syntax" removed
        "XML vs. SGML" list spacing changed to "compact"
-->

<!--* $Id: xml.sgm,v 1.47 1997/07/16 23:41:46 cmsmcq Exp cmsmcq $ *-->

<!--* The words 'FINAL EDIT' in comments mark places where changes
need to be made after approval of the document by the ERB, before
publication.  *-->

<!--*** comments with three stars and a number mark line numbers (in
the previous version of this document) to which changes need to be made
if the modified % operator is to be used.  If not, these comments
can be deleted. *-->

<!ENTITY XML.version "1.0">
<!ENTITY doc.date "07 August 1997">
<!ENTITY iso6.doc.date "970807">
<!ENTITY w3c.doc.date "07-Aug-97">

<!ENTITY lt     "<"> 
<!ENTITY gt     ">"> 
<!ENTITY amp    "&"> 
<!ENTITY xmlpio "'&lt;?XML'">
<!ENTITY pic    "'?>'">
<!ENTITY br     "<BR>">
<!ENTITY mdash  "--"> <!--* was: <!ENTITY mdash  "&#38;#151;"> *-->
<!ENTITY com    "--">
<!ENTITY como   "--">
<!ENTITY comc   "--">
<!ENTITY hcro   "&amp;#x">
<!--* <!ENTITY nbsp " "> *-->
<!ENTITY nbsp   "&#160;">
<!ENTITY IDEOSPACE "3000" >
<!ENTITY magicents "<ident>amp</ident>,
<ident>lt</ident>,
<ident>gt</ident>,
<ident>apos</ident>,
<ident>quot</ident>">

<!--* audience and distribution status:
<!ENTITY doc.audience "internal discussion within the SGML ERB only">
<!ENTITY doc.distribution "should not be distributed
outside the ERB">
*-->
 
<!--* audience and distribution status:  for later use in WG *-->
<!--*
<!ENTITY doc.audience "internal discussion within the SGML WG
and W3 Consortium only">
<!ENTITY doc.distribution "should not be distributed
outside the WG or Consortium">
*-->
 
<!--* audience and distribution status:  for use at publication time *-->
<!--*  *-->
<!ENTITY doc.audience "public review and discussion">
<!ENTITY doc.distribution "may be distributed freely, as long as
all text and legal notices remain intact">
 
]>
<!--* for Panorama **-->
<!--* ?VERBATIM "scrap"> *-->
<?VERBATIM "eg" ?>
<!--* N.B. NOTE TYPE='V-CHECK' and NOTE TYPE='WF-CHECK' should be
displayed in bold with leading text of 'Validity Constraint'
and 'Well-Formedness Constraint', respectively, followed by the
value of the N attribute, followed by a colon and two blanks.
This information belongs in a RENDITION element but I can't remember
where that goes without an SGML editor to guide me. -msm
*-->
<spec>
<w3cheader>
<wd-title>Extensible Markup Language (XML)</wd-title>
<wd-num>WD-xml-&iso6.doc.date;</wd-num>
<wd-date>W3C Working Draft &w3c.doc.date;</wd-date>
<versions><thisver><ver><a
href="http://www.w3.org/TR/WD-xml-&iso6.doc.date;.html"
>http://www.w3.org/TR/WD-xml-&iso6.doc.date;</a></ver>
</thisver>
<previousver><ver><a 
href='http://www.w3.org/TR/WD-xml-961114.html'>
http://www.w3.org/TR/WD-xml-961114</a></ver>
<ver><a 
href='http://www.w3.org/TR/WD-xml-lang-970331.html'>
http://www.w3.org/TR/WD-xml-lang-970331</a></ver>
<ver><a 
href='http://www.w3.org/TR/WD-xml-lang-970630.html'>
http://www.w3.org/TR/WD-xml-lang-970630</a></ver>
</previousver>
<latestver>
<ver><a 
href='http://www.w3.org/TR/WD-xml'>
http://www.w3.org/TR/WD-xml</a></ver>
</latestver>
<!-- don't use this any more!
<latestver><ver><a href="http://www.textuality.com/sgml-erb/WD-xml.html"
>http://www.textuality.com/sgml-erb/WD-xml-lang.html</a></ver
></latestver>
-->
</versions>
<authors><author><name>Tim Bray</name>
<affiliation>Textuality and Netscape</affiliation>
<email>tbray@textuality.com</email></author>
<author><name>Jean Paoli</name>
<affiliation>Microsoft</affiliation>
<email>jeanpa@microsoft.com</email></author>
<author><name>C. M. Sperberg-McQueen</name>
<affiliation>University of Illinois at Chicago</affiliation>
<email>cmsmcq@uic.edu</email></author></authors>
<status>
<p>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 <A
href="http://www.w3.org/TR">http://www.w3.org/TR</A>.</P>
<P><EMPH>Note:</EMPH> Since working drafts are subject to frequent
change, you are advised to reference the above URL, rather than the
URLs for working drafts themselves.</P>
 
<P>This work is part of the <a
href="http://www.w3.org/MarkUp/SGML/Activity">W3C SGML
Activity</a> (for current status, see
http://www.w3.org/MarkUp/SGML/Activity).</P>
 
</status>
<abstract>
<p>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. XML has been designed for
ease of implementation and for interoperability with both SGML and
HTML.</p>
</abstract>
</w3cheader>
<SPECHEADER>
<FILEDESC>
<TITLESTMT><TITLE>Extensible Markup Language</TITLE></TITLESTMT>
<PUBLICATIONSTMT>
<p>Chicago, Vancouver, Mountain View, et al.:
World-Wide Web Consortium, XML Working Group, 1996, 1997.</p>
</PUBLICATIONSTMT>
<SOURCEDESC>
<P>Created in electronic form.</P>
</SOURCEDESC>
</FILEDESC>
<profiledesc>
<langusage>
<language id='EN'>English</language>
<language id='EBNF'>Extended Backus-Naur Form (formal grammar)</language>
</langusage>
</profiledesc>
<REVISIONDESC>
<LIST type="simple">
<item>
<p>1997-07-24 : CMSMcQ : correct error (lost *) in definition 
of ignoreSectContents (thanks to Makoto Murata)</p>
<p>Allow all empty elements to have end-tags, consistent with
SGML TC (as per JJC).</p>
</item>
<item>
<p>1997-07-23 : CMSMcQ : pre-emptive strike on pending corrections:
introduce the term 'empty-element tag', note that all empty elements
may use it, and elements declared EMPTY must use it.
Add WFC requiring encoding decl to come first in an entity.
Redefine notations to point to PIs as well as binary entities.
Change autodetection table by removing bytes 3 and 4 from 
examples with Byte Order Mark.
Add content model as a term and clarify that it applies to both
mixed and element content.
</p>
</item>
<item>
<p>1997-06-30 : CMSMcQ : change date, some cosmetic changes,
changes to productions for choice, seq, Mixed, NotationType,
Enumeration.  Follow James Clark's suggestion and prohibit 
conditional sections in internal subset.  TO DO:  simplify
production for ignored sections as a result, since we don't 
need to worry about parsers which don't expand PErefs finding
a conditional section.</p>
</item>
<item>
<p>1997-06-29 : TB : various edits</p>
</item>
<item>
<p>1997-06-29 : CMSMcQ : further changes:<list>
<item>
<p>suppress old FINAL EDIT comments and some dead material.</p>
</item>
<item>
<p>revise occurrences of % in grammar to exploit Henry Thompson's pun,
especially markupdecl and attdef</p>
</item>
<item>
<p>remove RMD requirement relating to element content (?)</p>
</item>
</list>
</p>
</item>
<item>
<p>1997-06-28 : CMSMcQ : Various changes for 1 July draft:
<list><item><p>add text for draconian error handling (introduce
the term Fatal Error)</p>
</item>
<item>
<p>RE deleta est (changing wording from 
original announcement to restrict the requirement to validating
parsers)</p>
</item>
<item>
<p>tag definition of validating processor and link to it</p>
</item>
<item>
<p>add colon as name character</p>
</item>
<item>
<p>change def of %operator</p>
</item>
<item>
<p>change standard definitions of lt, gt, amp</p>
</item>
<item>
<p>strip leading zeros from #x00nn forms.</p></item></list>
</p>
</item>
<item>
<p>1997-04-02 : CMSMcQ : final corrections of editorial errors
found in last night's proofreading.  Reverse course once more on
well-formed:   Webster's Second hyphenates it, and that's enough
for me. </p>
</item>
<item>
<p>1997-04-01 : CMSMcQ : corrections from JJC, EM, HT, and self</p>
</item>
<item>
<p>1997-03-31 : Tim Bray : many changes</p>
</item>
<item>
<p>1997-03-29 : CMSMcQ : some Henry Thompson (on entity handling),
some Charles Goldfarb, some ERB decisions (PE handling in miscellaneous
declarations.  Changed Ident element to accept def attribute.
Allow normalization of Unicode characters.  move def of systemliteral
into section on literals.</p>
</item>
<item>
<p>1997-03-28 : CMSMcQ : make as many corrections as possible, from
Terry Allen, Norbert Mikula, James Clark, Jon Bosak, Henry Thompson,
Paul Grosso, and self.  Among other things:  give in on "well formed"
(Terry is right), tentatively rename QuotedCData as AttValue
and Literal as EntityValue to be more informative, since attribute
values are the <emph>only</emph> place QuotedCData was used, and
vice versa for entity text and Literal. (I'd call it Entity Text, 
but 8879 uses that name for both internal and external entities.)</p>
</item>
<item>
<p>1997-03-26 : CMSMcQ : resynch the two forks of this draft, reapply
my changes dated 03-20 and 03-21.  Normalize old 'may not' to 'must not'
except in the one case where it meant 'may or may not'.</p>
</item>
<item>
<p>1997-03-21 : TB : massive changes on plane flight from Chicago
to Vancouver</p>
</item>
<item>
<p>1997-03-21 : CMSMcQ : correct as many reported errors as possible.</p>
</item>
<item>
<p>1997-03-20 : CMSMcQ : correct typos listed in CMSMcQ hand copy of spec.</p>
</item>
<item>
<p>1997-03-20 : CMSMcQ : cosmetic changes preparatory to revision for
WWW conference April 1997:  restore some of the internal entity 
references (e.g. to docdate, etc.), change character xA0 to &amp;nbsp;
and define nbsp as &amp;#160;, and refill a lot of paragraphs for
legibility.
</p>
</item>

<item><p>1996-11-12 : CMSMcQ : revise using Tim's edits.<list
type='bullets'>
<item><p>Add list type of NUMBERED and change most lists either to
BULLETS or to NUMBERED.</p></item>
<item><p>suppress QuotedNames, Names (not used)</p></item>
<item><p>correct trivial-grammar doc type decl</p></item>
<item><p>rename 'marked section' as 'CDATA section' passim</p></item>
</list>
Also edits from James Clark:
<list type="bullets">
<item><p>define the set of characters from which [^abc] subtracts</p></item>
<item><p>charref should use just [0-9] not Digit</p></item>
<item><p>location info needs cleaner treatment:  remove?  (ERB
question)</p></item>
<item><p>one example of a PI has wrong pic.</p></item>
<item><p>clarify discussion of encoding names</p></item>
<item><p>encoding failure should lead to unspecified results; don't
prescribe error recovery</p></item>
<item><p>don't require exposure of entity boundaries</p></item>
<item><p>ignore white space in element content</p></item>
<item><p>reserve entity names of the form u-NNNN</p></item>
<item><p>clarify relative URLs</p></item>
</list>
And some of my own:
<list type="bullets">
<item><p>correct productions for content model:  model cannot
consist of a name, so "elements ::= cp" is no good.</p></item>
</list>
</p></item>
<item><p>1996-11-11 : CMSMcQ : revise for style.
Add new rhs to entity declaration, for parameter entities.</p>
</item>
<item><p>1996-11-10 : CMSMcQ : revise for style.
Fix / complete section on names, characters.
Add sections on parameter entities, conditional sections.
Still to do:  Add compatibility note on deterministic content models.
Finish stylistic revision.
</p></item>
<item><p>1996-10-31 : TB : Add Entity Handling section</p></item>
<item><p>1996-10-30 : TB : Clean up term &amp; termdef.  Slip in
ERB decision re EMPTY.</p></item>
<item><p>1996-10-28 : TB : Change DTD.  Implement some of Michael's
suggestions.  Change comments back to //.  Introduce language for
XML namespace reservation.  Add section on white-space handling.
Lots more cleanup.
</p></item>
<item><p>1996-10-24 : CMSMcQ : quick tweaks, implement some ERB
decisions.  Characters are not integers.  Comments are /* */ not //.
Add bibliographic refs to 10646, HyTime, Unicode.
Rename old Cdata as MsData since it's <emph>only</emph> seen
in marked sections.  Call them attribute-value pairs not
name-value pairs, except once.  Internal subset is optional, needs
'?'.  Implied attributes should be signaled to the app, not
have values supplied by processor.</p></item>
<item><p>1996-10-16 : TB : track down &amp; excise all DSD references;
introduce some EBNF for entity declarations.</p></item>
<item><p>1996-10-?? : TB : consistency check, fix up scraps so
they all parse, get formatter working, correct a few productions.</p></item>
<item><p>1996-10-10/11 : CMSMcQ : various maintenance, stylistic, and
organizational changes:
<list type="bullets">
<item><p>replace a few literals with xmlpio and
pic entities, to make them consistent and ensure we can change pic
reliably when the ERB votes</p></item>
<item><p>drop paragraph on recognizers from notation section</p></item>
<item><p>add match, exact match to terminology</p></item>
<item><p>move old 2.2 XML Processors and Apps into intro</p></item>
<item><p>mention comments, PIs, and marked sections in discussion of
delimiter escaping</p></item>
<item><p>streamline discussion of doctype decl syntax</p></item>
<item><p>drop old section of 'PI syntax' for doctype decl, and add
section on partial-DTD summary PIs to end of Logical Structures
section</p></item>
<item><p>revise DSD syntax section to use Tim's subset-in-a-PI
mechanism</p></item></list></p></item>
<item><p>1996-10-10 : TB : eliminate name recognizers (and more?)</p></item>
<ITEM><p>1996-10-09 : CMSMcQ : revise for style, consistency through 2.3
(Characters)</p></item>
<ITEM><p>1996-10-09 : CMSMcQ : re-unite everything for convenience,
at least temporarily, and revise quickly</p></item>
<item><p>1996-10-08 : TB : first major homogenization pass</p></ITEM>
<ITEM><p>1996-10-08 : TB : turn "current" attribute on div type into 
CDATA</p></ITEM>
<ITEM><p>1996-10-02 : TB : remould into skeleton + entities</p></ITEM>
<ITEM><p>1996-09-30 : CMSMcQ : add a few more sections prior to exchange
                            with Tim.</p></ITEM>
<ITEM><p>1996-09-20 : CMSMcQ : finish transcribing notes.</p></ITEM>
<ITEM><p>1996-09-19 : CMSMcQ : begin transcribing notes for draft.</p></ITEM>
<ITEM><p>1996-09-13 : CMSMcQ : made outline from notes of 09-06,
do some housekeeping</p></ITEM>
</LIST>
</REVISIONDESC>
</SPECHEADER>
<TEXT>
<FRONT>
<TITLEPAGE>
<DOCTITLE>
<titlepart>Extensible Markup Language </titlepart>
<titlepart>Version &XML.version; </titlepart>
</DOCTITLE>
<TITLEPART>Document W3C-SGML-ERB DD-1996-0004</TITLEPART>
<!--* <TITLEPART>Version &doc.version;</TITLEPART> *-->
<DOCDATE>&doc.date;</DOCDATE>
<TITLEPART>This draft is intended for public
discussion.</TITLEPART>
<TITLEPART>It is subject to approval by the
XML Working Group.</TITLEPART>
</TITLEPAGE>
 
</FRONT>
<BODY>
 
<div1 type="section">
<head>Introduction</head>
 
<p>The Extensible Markup Language, abbreviated XML, describes a class of
data objects called <term def="dt-xml-doc">XML documents</term> and partially
describes the behavior of 
computer programs which process them. XML is an application profile or
restricted form of SGML, the Standard Generalized Markup Language <ref
type='bib' target='ISO8879'>[ISO 8879]</ref>.</p>
<p>XML documents are made up of storage units called <TERM
def="dt-entity">entities</TERM>, which contain either <TERM
def="dt-text">text</TERM> or <TERM def="dt-binary">binary</TERM> data.
Text is made up of <TERM def="dt-character">characters</TERM>, some
of which form the <TERM def="dt-chardata">character data</TERM> in the
document, and some of which form <TERM def="dt-markup">markup</TERM>.
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.</p>
<p><termdef id="dt-xml-proc" term="XML Processor">A software module
called an <ident>XML processor</ident> is used to read XML documents
and provide access to their content and structure.</termdef> <termdef
id="dt-app" term="Application">It is assumed that an XML processor is
doing its work on behalf of another module, referred to as the
<ident>application</ident>.</termdef> 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.</p>
 
<div2 type="section">
<head>Origin and Goals</head>
<p>XML was developed by an XML Working Group (originally known as the
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 XML Special
Interest Group (previously known as the SGML Working Group) also
organized by the W3C. The membership of the XML Working Group is given
in an appendix. Dan Connolly served as the WG's contact with the W3C.
</p>
<P>The design goals for XML are:<LIST type="numbered">
<ITEM><P>XML shall be straightforwardly usable over the
Internet.</P></ITEM>
<ITEM><P>XML shall support a wide variety of applications.</P></ITEM>
<ITEM><P>XML shall be compatible with SGML.</P></ITEM>
<ITEM><P>It shall be easy to write programs which process XML
documents.</P></ITEM>
<ITEM><P>The number of optional features in XML is to be kept to the
absolute minimum, ideally zero.</P></ITEM>
<ITEM><P>XML documents should be human-legible and reasonably
clear.</P></ITEM>
<ITEM><P>The XML design should be prepared quickly.</P></ITEM>
<ITEM><P>The design of XML shall be formal and concise.</P></ITEM>
<ITEM><P>XML documents shall be easy to create.</P></ITEM>
<ITEM><P>Terseness in XML markup is of minimal importance.</P></ITEM></LIST>
</p>
<p>This specification, together with the associated standards, provides
all the information necessary to understand XML version &XML.version;
and construct computer programs to process it.</P>
<p>This version of the XML specification (&doc.date;)
is for &doc.audience;.
It &doc.distribution;.</p>

</div2>
 
<div2 type="section">
<head>Relationship to Existing Standards</head>
 
<p>Standards relevant to users and implementors of XML include:
<list type="bullets">
<item><P>SGML (ISO 8879:1986).  By definition, <TERM
def="dt-valid">valid</TERM> XML documents are conformant SGML
documents in the sense described in ISO standard 8879. The current
draft of this specification 
presupposes the successful completion of the current
work on a technical corrigendum to ISO 8879 now being prepared
by ISO/IEC JTC1/SC18/WG8.  If the corrigendum is not
adopted in the expected form, some clauses of this specification 
may change,  and some
recommendations now labeled <mentioned>for
interoperability</mentioned> will become requirements labeled
<mentioned>for compatibility</mentioned>.</P></item>
<item><P>Unicode and ISO/IEC 10646.  This specification depends on the
international
standard ISO/IEC
10646 (with amendments AM 1 through AM 5)
and the <title>Unicode Standard, Version
2.0</title>, which define the encodings and meanings of the
<TERM def="dt-character">characters</TERM> which make up XML <TERM
def="dt-text">text</TERM>
data.  All the characters in ISO/IEC 10646
are present, at the same code points, in Unicode.</P></item>
<item><p>IETF RFC 1738 and RFC 1808.
RFC 1738 and RFC 1808 define the syntax and semantics of Uniform Resource
Locators, or URLs.</p></item>
<!--* Terry Allen wants us to list 1808 (and 1874?), too *-->
</list>
</p>
</div2>

 
<div2 type="section">
<head>Terminology</head>
 
<p>Some terms used with special meaning in this specification are:
<list type='gloss'>
<label>may</label>
<item><p><termdef id="dt-may" term="May">Conforming data and XML
processors are permitted to but need not behave as
described.</termdef></p></item>
<label>must</label>
<item><p>Conforming data and XML processors are required to 
behave as described; otherwise
they are in error.</p></item>
<label>error</label>
<item><p><termdef id='dt-error' term='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.</termdef></p></item>
<!-- no longer, I think -TWB
<label>reportable error</label>
<item><p><termdef id="dt-reportable" term="Reportable Error">An error
which conforming software must, at user option, report to the
user.</termdef></p></item> -->
<label>fatal error</label>
<item><p><termdef id="dt-fatal" term="Fatal Error">An error
which conforming software must detect and report to the application.
After encountering a fatal error, an XML processor may continue
processing the data to search for further errors and may report such
errors to the application.  In order to support correction of errors,
the processor may make unprocessed text from the document (with
intermingled character data and markup) available to the application.
Once a fatal error is detected, however, the processor must not
continue normal processing (i.e. it must not
continue to pass character data and information about the document's
logical structure to the application in the normal way).
</termdef></p></item>
<label>validity constraint</label>
<item><p>A rule which applies to all <term def="dt-valid">valid</term> XML
documents.
Violations of
validity constraints are errors; they must, at user option, be reported
by <term def="dt-validating">validating XML processors</term>.</p></item>
<label>well-formedness constraint</label>
<item><p>A rule which applies to all <term
def="dt-wellformed">well-formed</term> XML documents.
Violations of well-formedness constraints are 
<term def="dt-fatal">fatal errors</term>.</p></item>
<label>at user option</label>
<item><p>Conforming software may or must (depending on the modal verb in the
sentence) behave as described; if it does, it must
provide users a means to enable or disable the behavior
described.</p></item>
<label>match</label>
<item><p><termdef id="dt-match" term="match">(Of strings or names:) 
Case-insensitive match:  two strings or names being
compared match if they are identical after case-folding.
(Of strings and rules in the grammar:)  
A string matches a grammatical production if it belongs to the
language generated by that production.
(Of content and content models:)
The content of a <term def="dt-parentchild">parent element</term> 
in a document matches the content model
for that element if (a) the content model matches the rule for
<code><ident def="NT-Mixed">Mixed</ident></code> and the content consists of 
character data and elements whose names match names in the
content model, or if (b) the content model matches the rule for
<code><ident def="NT-elements">elements</ident></code>, and the sequence of 
<term def="dt-parentchild">child elements</term>
belongs to the language generated by the regular expression in
the content model.
</termdef>
</p></item>
<label>case-folding</label>
<item><p><termdef id="dt-casefold" term="case-fold"> a process applied
to a sequence of characters, in which those identified as
non-uppercase (in scripts which have case distinctions) are replaced
by their uppercase equivalents, as specified in <ref type='bib'
target='Unicode'>The Unicode Standard, Version 2.0</ref>, 
section 4.1.
Note that Unicode recommends folding to lowercase; <term
def='dt-compat'>for compatibility reasons</term>, XML processors must
fold to uppercase. Case-folding, as described here, neither requires
nor forbids the normalization of Unicode character sequences into
canonical form (e.g. as described in <ref type='bib'
target='Unicode'>The Unicode Standard</ref>, section 5.9). 
</termdef></p></item>
<label>exact(ly) match</label>
<item><p><termdef id="dt-exact" term="Exact Match">Case-sensitive
string match:  two strings or names being compared must be identical.
Characters with multiple possible representations in ISO/IEC 10646 (e.g.
characters with 
both precomposed and base+diacritic forms) match only if they have the
same representation in both strings.
At user option, processors may normalize such characters to their
canonical form.</termdef>
</p></item>
<label>for compatibility</label>
<item><p><termdef id="dt-compat" term="For Compatibility">A feature of
XML included solely to ensure that XML remains compatible with SGML.
</termdef></p></item>
<label>for interoperability</label>
<item><p><termdef id="dt-interop" term="For interoperability">A
non-binding recommendation included to increase the chances that XML
documents can be processed by the existing installed base of SGML
processors which predate the
technical corrigendum to ISO 8879 now in the process of preparation
by ISO/IEC JTC1/SC18/WG8. </termdef></p></item>
</list>
</p>
</div2>

 
<div2 type="section">
<head>Notation</head>
 
<p>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
<eg>symbol ::= expression</eg></p>
<p>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.</p>
<!--*<p>In order to simplify the description of the behavior of an 
<term def="dt-xml-proc">XML processor</term>, in particular as regards 
<term def="dt-entity">entity</term> processing, this specification describes
some of that behavior in terms of a two-phase process.
The first phase may be considered a preprocessor; it recognizes 
<term def="dt-entref">entity references</term> at points marked in the grammar
using the "<code>%</code>" operator and replaces them as described in 
this specification.
The grammar describes the syntax of XML documents after this "preprocessing"
activity has taken place.
However, the "preprocessor" is not entirely free in its actions; entity
references may only recognized and replaced at a relatively small number of
locations in documents; these spots are marked with a special operator in the
grammar.</p>
<p>The description in terms of processing phases is adopted strictly for
reasons of clarity and brevity; this
specification neither constrains the phase architecture of an XML processor
nor presupposes that all implementations parse in multiple phases.
</p>*-->
<p>Within the expression on the right-hand side of a rule, the
meaning of symbols is as shown below.
<list type="gloss">
<label><code>#xN</code></label>
<item><p>where <ident>N</ident> is a hexadecimal integer, the
expression represents the character in ISO/IEC 10646 whose canonical
(UCS-4) bit string, when interpreted as an unsigned binary number, has
the value indicated.  The number of leading zeroes in the
<code>#xN</code> form is insignificant; the number of leading
zeroes in the corresponding bit string is governed by the character
encoding in use and is not significant for XML.</p></item>
<label><code>[a-zA-Z]</code>, <code>[#xN-#xN]</code></label>
<item><p>represents any <term def='dt-character'>character</term> 
with a value in the range(s) indicated (inclusive).</p></item>
<label><code>[^a-z]</code>, <code>[^#xN-#xN]</code></label>
<item><p>represents any <term def='dt-character'>character</term> 
with a value <emph>outside</emph> the
range indicated.</p></item>
<label><code>[^abc]</code>, <code>[^#xN#xN#xN]</code></label>
<item><p>represents any <term def='dt-character'>character</term>
with a value not among the characters given.</p></item>
<label><code>"<ident>string</ident>"</code></label>
<item><p>represents a literal string <term def="dt-match">matching</term> that 
given inside the double quotes.</p></item>
<label><code>'<ident>string</ident>'</code></label>
<item><p>represents a literal string <term def="dt-match">matching</term> that
given inside the single quotes.</p></item>
<label><code>a b</code></label>
<item><p><ident>a</ident> followed by <ident>b</ident>.</p></item>
<label><code>a | b</code></label>
<item><p><ident>a</ident> or <ident>b</ident> but not both.</p></item>
<label><code>a - b</code></label>
<item><p>the set of strings represented by 
<ident>a</ident> but not represented by 
<ident>b</ident></p></item>
<label><code>a?</code></label>
<item><p><ident>a</ident> or nothing; optional <ident>a</ident>.</p></item>
<label><code>a+</code></label>
<item><p>one or more occurrences of <ident>a</ident>.</p></item>
<label><code>a*</code></label>
<item><p>zero or more occurrences of <ident>a</ident>.</p></item>
<label><code>%a</code></label>
<item><p>specifies that <emph>in the external DTD subset</emph> a
<term def='dt-param-entity'>parameter entity</term> may occur in the
text at the position where <ident>a</ident> may occur; if so, its
replacement text must match <code>S? <ident>a</ident> S?</code>.  If
the expression <ident>a</ident> is governed by a suffix operator, then
the suffix operator determines both the maximum number of parameter-entity 
references allowed and the number of occurrences of <ident>a</ident>
in the replacement text of the parameter entities:  <code>%a*</code>
means that <ident>a</ident> must occur zero or more times, and
that some of its occurrences may be replaced by references to
parameter entities whose replacement text must contain zero or 
more occurrences of <ident>a</ident>; it is thus a more compact way
of writing <code>%(a*)*</code>.
Similarly, <code>%a+</code> means that <ident>a</ident>
must occur one or more times, and may be replaced by 
parameter entities with replacement text matching 
<code>S? (a S?)+</code>.  
<!--* as suggested by Henry Thompson *-->
<!--* Note that <code>%</code> has lower precedence than any of the
suffix operators <code>?</code>, <code>*</code>, or <code>+</code>;
that is to say, <code>%a*</code> and <code>%(a*)</code> each mean that
the result of <term def='dt-include'>including</term> a parameter
entity reference at the indicated location must match <code>a*</code>.
*-->
The recognition of parameter entities in the internal subset is much more
highly constrained.
</p></item>
<label>(<ident>expression</ident>)</label>
<item><p><ident>expression</ident> is treated as a unit, and
may carry the <code>%</code> prefix operator, or a suffix operator:
<code>?</code>, <code>*</code>, or <code>+</code>.</p></item>
<label><code>/* ... */</code></label>
<item><p>comment.</p></item>
<label><code>[ WFC: ... ]</code></label>
<item><p>Well-formedness check; this identifies by name a check for
<term def="dt-wellformed">well-formedness</term> associated with
a production.</p></item>
<label><code>[ VC: ... ]</code></label>
<item><p>Validity check; this identifies by name a check for
<term def="dt-valid">validity</term> associated with
a production.</p></item>
</list>
</p></div2>
 
<div2 type="section">
<head>Common Syntactic Constructs</head>
 
<p>This section defines some symbols used widely in the grammar.</p>
<p><ident>S</ident> (white space) consists of one or more space (#x20)
characters, carriage returns, line feeds, or tabs.
<!--* tabs, or ideographic space characters. *-->
<scrap lang="ebnf" id='white' name="White space">
<prod><lhs id='NT-S'>S</lhs>
<rhs>(#x20 | #x9 | #xd | #xa)+</rhs>
</prod>
</scrap></p>
<p><termdef id="dt-character" term="Character">Legal
characters are tab, carriage return, line feed, and the legal graphic
characters of Unicode and ISO/IEC 10646.</TERMDEF> 
<scrap lang="ebnf" id="char32" name="Character range">
<prod><lhs id="NT-Char">Char</LHS> 
<RHS>#x9 | #xA | #xD | [#x20-#xFFFD]
| [#x00010000-#x7FFFFFFF]</RHS> 
<COM>any ISO/IEC 10646 UCS-4 code, FFFE and FFFF excluded</COM> </PROD>
</scrap>
Characters are classified for convenience as letters, digits, or other
characters.  Letters consist of an alphabetic or syllabic 
base character possibly
followed by one or more combining characters, or of an ideographic
character.  Certain layout and format-control characters defined by 
ISO/IEC 10646 should be ignored
when recognizing identifiers; these are defined by the
classes <ident>Ignorable</ident> and <ident>Extender</ident>.
Full definitions of the specific characters in each class
are given in the appendix on <ref target='CharClasses'>character 
classes</ref>.</p>
<p><termdef id="dt-name" term="Name">A <ident>Name</ident> is a token
beginning with a letter or underscore character and continuing with
letters, digits, hyphens, underscores,  or full stops (together known
as name characters)</termdef>. 
Names beginning with the string <mentioned>XML</mentioned> are
reserved for standardization in this or future versions of this
specification.
<!--* 
The use of any name beginning with a
string which matches "<code>XML</code>" in a fashion other than those
described in this and related specifications is an <term
def="dt-error">error</term>. 
*-->
</p>
<p>Note:  the colon character is also
allowed within XML names; it is reserved for experimentation with
name spaces and schema scoping.  Its meaning is expected to be
standardized at some future point, at which point those documents 
using colon for experimental purposes will need to be updated.
(Note:  there is no guarantee that any name-space mechanism
adopted for XML will in fact use colon as a name-space delimiter.)
In practice, this means that authors should not use colon in XML
names except as part of name-space experiments, but that implementors
should accept colon as a name character.
</p>
<p>An
<ident>Nmtoken</ident> (<gloss>name token</gloss>) is any mixture of
name characters.
<scrap lang='ebnf' name='Names and tokens'>
<prod><lhs id='NT-MiscName'>MiscName</lhs>
<rhs>'.' | '-' | '_' | ':'
| <nt def='NT-CombiningChar'>CombiningChar</nt> 
| <nt def='NT-Ignorable'>Ignorable</nt> 
| <nt def='NT-Extender'>Extender</nt></rhs>
</prod>
<prod><lhs id='NT-NameChar'>NameChar</lhs>
<rhs><nt def="NT-Letter">Letter</nt> 
| <nt def='NT-Digit'>Digit</nt> 
| <nt def='NT-MiscName'>MiscName</nt></rhs>
</prod>
<prod><lhs id='NT-Name'>Name</lhs>
<rhs>(<nt def='NT-Letter'>Letter</nt> | '_' | ':')
(<nt def='NT-NameChar'>NameChar</nt>)*</rhs></prod>
<prod><lhs id='NT-Names'>Names</lhs>
<rhs><nt def='NT-Name'>Name</nt> 
(<nt def='NT-S'>S</nt> <nt def='NT-Name'>Name</nt>)*</rhs></prod>
<prod><lhs id='NT-Nmtoken'>Nmtoken</lhs>
<rhs>(<nt def='NT-NameChar'>NameChar</nt>)+</rhs></prod>
<prod><lhs id='NT-Nmtokens'>Nmtokens</lhs>
<rhs><nt def='NT-Nmtoken'>Nmtoken</nt> (<nt def='NT-S'>S</nt> <nt def='NT-Nmtoken'>Nmtoken</nt>)*</rhs></prod>
</scrap>
</p>
<p>Literal data is any quoted string not containing
the quotation mark used as a delimiter for that string; different
forms of literal data may or may not contain
angle brackets, <term def="dt-entref">entity references</term>, and <term
def="dt-charref">character references</term>.  Literals are used
for specifying the replacement text of internal entities
(<ident>EntityValue</ident>),
the values of attributes (<ident>AttValue</ident>), 
and external identifiers 
(<ident def="NT-SystemLiteral">SystemLiteral</ident>); for some
purposes, the entire literal can be skipped without scanning for
markup within it (<ident>SkipLit</ident>):
<scrap lang='ebnf' name='Literals'>
<prod><lhs id='NT-EntityValue'>EntityValue</lhs>
<rhs>'"' 
([^%&amp;"] 
| <nt def='NT-PEReference'>PEReference</nt> 
| <nt def='NT-Reference'>Reference</nt>)* 
'"' 
</rhs>
<rhs>|&nbsp; 
"'" 
([^%&amp;'] 
| <nt def='NT-PEReference'>PEReference</nt> 
| <nt def='NT-Reference'>Reference</nt>)* 
"'"</rhs>
</prod>
<prod><lhs id='NT-AttValue'>AttValue</lhs>
<rhs>'"' 
([^&lt;&amp;"] 
| <nt def='NT-Reference'>Reference</nt>)* 
'"' 
</rhs>
<rhs>|&nbsp; 
"'" 
([^&lt;&amp;'] 
| <nt def='NT-Reference'>Reference</nt>)* 
"'"</rhs>
</prod>
<prod>
<lhs id="NT-SystemLiteral">SystemLiteral</lhs>
<rhs>'"' <nt def='NT-URLchar'>URLchar</nt>* '"' 
| "'" (<nt def='NT-URLchar'>URLchar</nt> - "'")* "'"</rhs>
</prod>
<prod>
<lhs id="NT-URLchar">URLchar</lhs>
<rhs><com>See
<a href="http://www.w3.org/Addressing/rfc1738.txt">RFC 1738</a>
and
<a href="http://www.w3.org/Addressing/rfc1808.txt">1808</a>
</com></rhs>
</prod>
<prod>
<lhs id="NT-PubidLiteral">PubidLiteral</lhs>
<rhs>'"' <nt def='NT-PubidChar'>PubidChar</nt>* '"' 
| "'" (<nt def='NT-PubidChar'>PubidChar</nt> - "'")* "'"</rhs>
</prod>
<prod>
<lhs id="NT-PubidChar">PubidChar</lhs>
<rhs>#x20 | #x9 | #xd | #xa | #x&IDEOSPACE;
|&nbsp;[a-zA-Z0-9]
|&nbsp;[-'()+,./:=?]</rhs>
</prod>
<prod>
<lhs id="NT-SkipLit">SkipLit</lhs>
<rhs>('"' [^"]* '"') 
|&nbsp;("'" [^']* "'")</rhs>
</prod>
</scrap>
<!-- Repeated elsewhere
Within <ident def="NT-EntityValue">EntityValue</ident>, parameter-entity
and character references are recognized and expanded immediately;
general-entity references may occur, but they are not expanded until
the entity containing them is referenced and expanded in the document
itself.  Within <ident def="NT-AttValue">AttValue</ident>, general and
character references are recognized and expanded; parameter-entity
references are not recognized.  Within <ident def="NT-SystemLiteral">
SystemLiteral</ident>, no references of any kind are recognized.-->
Note that <term def="dt-entref">entity references</term> and 
<term def="dt-charref">character references</term> are recognized and
processed within <ident def="NT-EntityValue">EntityValue</ident> and <ident
def="NT-AttValue">AttValue</ident>, but not within 
<ident def="NT-SystemLiteral">SystemLiteral</ident>.
</p>
</div2>
</div1>
<!--* &Docs; *-->
 
<div1 type="section">
<head>Documents</head>
 
<p><termdef id="dt-xml-doc" term="XML Document">A textual object is an
<ident>XML document</ident> if it is
either <term def="dt-valid">valid</term> or 
<term def="dt-wellformed">well-formed</term>, as
defined in this specification.</termdef></p>
 
<div2 type="section">
<head>Logical and Physical Structure</head>
 
<p>Each XML document has both a logical and a physical structure.</p>
<p>Physically, the document is composed of units called <term
def="dt-entity">entities</term>.  An entity may <term
def="dt-entref">refer</term> to other entities to cause their
inclusion in the document. A document begins in a "root"  or <term
def="dt-docent">document entity</term>.
</p>
<p>The logical structure contains declarations, elements, 
<!--* tags, *-->
comments,
character references, and
processing
instructions, all of which are indicated in the document by explicit
markup.</p>
<p>The two structures must be synchronous: 
see <ref target="sec-logphys">section 4.1</ref>.
</p>
 
</div2>
 
<DIV2 type="section">
<HEAD>Well-Formed XML Documents</HEAD>
 
<P><termdef id="dt-wellformed" term="Well-Formed">A textual object is
said to be a <ident>well-formed</ident> XML document if, first, it
matches the production labeled <ident>document</ident>, and if for
each <term def="dt-entref">entity reference</term> which appears in
the document, either the entity has been declared in the <term
def="dt-doctype">document type declaration</term> or the entity name is
one of: &magicents;.
</termdef></P>
<p>Matching the <ident def="NT-document">document</ident> production 
implies that:
<list type="numbered">
<ITEM><P>It contains one or more
<TERM def="dt-element">elements</TERM>.</p>
</item>
<item>
<p>It meets all the well-formedness constraints (WFCs) given
in the grammar.</P></ITEM>
<!--* you win - there's no benefit in doing this twice
<item><p>The document matches:
<scrap lang='ebnf' name='well-formed document structure'>
<prod><lhs id='NT-wellformeddoc'>wellformeddoc</lhs>
<rhs><nt def='NT-prolog'>prolog</nt> 
<nt def='NT-root'>root</nt> <nt def='NT-Misc'>Misc</nt></rhs></prod>
<prod><lhs id='NT-root'>root</lhs>
<rhs><nt def='NT-element'>element</nt></rhs></prod>
<prod><lhs id='NT-Misc'>Misc</lhs>
<rhs>(<nt def='NT-Comment'>Comment</nt> 
| <nt def='NT-PI'>PI</nt> 
| <nt def='NT-S'>S</nt>)*</rhs></prod>
<prod><lhs id='NT-prolog'>prolog</lhs>
<rhs><nt def='NT-Misc'>Misc</nt> (<nt def='NT-doctypedecl'>doctypedecl</nt> 
<nt def='NT-Misc'>Misc</nt>)?</rhs></prod>
</scrap>
</p><p>[Q E.1 Or:  the document matches the grammar given in this
specification.]</p></item> *-->
<ITEM><P><termdef id="dt-root" term="Root Element">There is exactly
one element,
called the <ident>root</ident>, or document element, for
which neither the <TERM def="dt-stag">start-tag</TERM> nor the
<TERM def="dt-etag">end-tag</TERM> is in
the <TERM def="dt-content">content</TERM> of any other element.</termdef>  
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,
delimited by start- and end-tags, nest within each other.
</P></ITEM>
</LIST></p>
<P><termdef id="dt-parentchild" term="Parent/Child">As a consequence 
of this,
for each non-<TERM def="dt-root">root</TERM>
element
<ident>C</ident> in the document, there is one other element <ident>P</ident>
in the document such that 
<ident>C</ident> is in the content of <ident>P</ident>, but is not in
the content of any other element that is in the content of
<ident>P</ident>.  Then <ident>P</ident> is referred to as the
<ident>parent</ident> of <ident>C</ident>, and <ident>C</ident> as a
<ident>child</ident> of <ident>P</ident>.</termdef></P></DIV2>
 
<DIV2 type="section" id="charsets">
<HEAD>Characters</HEAD>
 
<P>The data stored in an XML <term def="dt-entity">entity</term> is
either <TERM def="dt-text">text</TERM> or <TERM
def="dt-binary">binary</TERM>. <termdef id="dt-binary"
term="Binary">Binary data has an associated <TERM
def="dt-notation">notation</TERM>, identified by name; beyond a
requirement to make available the notation's name and the 
associated system
identifier, XML places no constraints on the contents or use of binary
entities. So-called binary data might in fact be textual; its
identification as binary means that an XML processor need not parse
it in the fashion described by this specification.</termdef> <termdef
id="dt-text" term="Text">XML text data is a sequence of <TERM
def="dt-character">characters</TERM>.</termdef> 
<!--* This sentence was tagged as a duplicate termdef for character.
Lose it. *-->
A character is an atomic unit of
text;
<!--* represented by a bit string;*--> 
valid 
<!--* bit strings and their meanings *-->
characters
are specified by <ref target="ISO10646">ISO/IEC 10646</ref>.
<!--* end of old termdef *-->
Users may extend the ISO/IEC 10646 character repertoire by exploiting the
private use areas.</p>
<p>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
<!--* FINAL EDIT:  UCS-2 or UTF-16? *-->
the two are in use, or for bringing other encodings into play, are
discussed later, in the discussion of <ref
target='charencoding'>character encodings</ref>.
</P>
<p>Regardless of the specific encoding used, any character in the ISO/IEC
10646 character set may be referred to by the decimal or hexadecimal
equivalent of its bit string.
</p>
</DIV2>
 
<DIV2 type="section" id='syntax'>
<HEAD>Character Data and Markup</HEAD>
 
<P>XML text consists of intermingled <TERM def="dt-chardata">character
data</TERM> and markup.
<termdef id="dt-markup" term="Markup">Markup takes the form of
<term def="dt-stag">start-tags</term>,
<term def="dt-etag">end-tags</term>,
<term def="dt-empty">empty elements</term>,
<term def="dt-entref">entity references</term>,
<term def="dt-charref">character references</term>,
<term def="dt-comment">comments</term>,
<term def="dt-cdsection">CDATA sections</term>,
<term def="dt-doctype">document type declarations</term>, and
<term def="dt-pi">processing instructions</term>.
</termdef>
</p>
<P><termdef id="dt-chardata" term="Character Data">All text that is not markup
constitutes the character data of
the document.</termdef></P>
<p>The ampersand character (&amp;) and the left angle bracket (&lt;)
may appear in their literal form <emph>only</emph> when used as markup
delimiters, or within <term def="dt-comment">comments</term>, <term
def="dt-pi">processing instructions</term>, or <term
def="dt-cdsection">CDATA sections</term>.  If they are needed elsewhere,
<!--* in the
character data, *-->
they must be <term def="dt-escape">escaped</term>
using either numeric character references or the strings
"<code>&amp;amp;</code>" and "<code>&amp;lt;</code>". The right angle
bracket (>) may be represented using the string
"<code>&amp;gt;</code>", and must, <term def='dt-compat'>for
compatibility</term>, be so represented when it appears in the string
"<code>]]&gt;</code>", when that string is not marking the end of 
a <term def="dt-cdsection">CDATA section</term>. 
</p>
<p>
<!--* 
Parsed character data is thus any string of characters which does
not contain the start-delimiter of any markup.  
*-->
In the content of elements, character data 
is any string of characters which does
not contain the start-delimiter of any markup.  
In a CDATA section, character data
is any string of characters not including the CDATA-section-close
delimiter, "<code>]]&gt;</code>".</p>
<p>
To allow attribute values to contain both single and double quotes, the
apostrophe or single-quote character (') may be represented as
"<code>&amp;apos;</code>", and the double-quote character (") as
"<code>&amp;quot;</code>".
<scrap lang="ebnf" name='Character data'>
<prod><lhs id='NT-PCData'>PCData</lhs>
<rhs>[^&lt;&amp;]*</rhs>
</prod>
</scrap>
</p>
</DIV2>
 
<DIV2 type="section">
<HEAD>Comments</HEAD>
 
<p><termdef id="dt-comment" term="Comment">Comments may appear anywhere 
except in a <term def="dt-cdsection">CDATA section</term>, i.e. within
<term def="dt-elemcontent">element content</term>, in 
<term def="dt-mixed">mixed content</term>, or in a DTD.  They must
not occur within declarations or tags.
They are not part of the document's <TERM def="dt-chardata">character
data</TERM>; an XML
processor may, but need not, make it possible for an application to
retrieve the text of comments.
<!--* FINAL EDIT:  should this stay? *-->
<!--*
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.  *-->
<!--* The string <code>&comc;&gt;</code> must not occur within
a comment. *-->
<term def="dt-compat">For compatibility</term>, the string
<mentioned>--</mentioned> (double-hyphen) must not occur within
comments.
<scrap lang="ebnf" name='Comments'>
<prod><lhs id='NT-Comment'>Comment</lhs>
<rhs>'&lt;!&como;' 
(<nt def='NT-Char'>Char</nt>* - 
(<nt def='NT-Char'>Char</nt>* '&comc;' <nt def='NT-Char'>Char</nt>*)) 
'&comc;&gt;'</rhs>
</prod>
</scrap>
<!--*** 1068 *--></termdef></P>
<p>An example of a comment:
<eg>&lt;!&como; declarations for &lt;head> &amp; &lt;body> &comc;&gt;</eg>
</P>
</DIV2>
 
<DIV2 type="section">
<HEAD>Processing Instructions</HEAD>
 
<P><termdef id="dt-pi" term="Processing instruction"><ident>Processing
instructions</ident> (PIs) allow documents to contain instructions
for applications.
 
<scrap lang="ebnf" name='Processing instructions'>
<prod><lhs id='NT-PI'>PI</lhs>
<rhs>'&lt;?' <nt def='NT-Name'>Name</nt> 
<nt def='NT-S'>S</nt> 
(<nt def='NT-Char'>Char</nt>* - 
(<nt def='NT-Char'>Char</nt>* &pic; <nt def='NT-Char'>Char</nt>*)) 
<!--*** 1087 *-->&pic;</rhs></prod>
</scrap></termdef>
PIs are not part of the document's <TERM def="dt-chardata">character
data</TERM>, but must be passed through to the application. The
<ident>Name</ident> is called the <ident>PI target</ident>; it is used
to identify the application to which the instruction is directed.  XML
provides an optional mechanism, <term def='dt-notation'>NOTATION</term>, for
formal declaration of such names.
PI targets with names beginning with the string "XML"
are reserved for standardization in this or future versions of
this specification.
<!--* The use of PI targets with names beginning "XML" in
any way other than those described in this specification is an <term
def="dt-error">error</term>.*-->
</P>
</DIV2>
 
<DIV2 type="section">
<HEAD>CDATA Sections</HEAD>
 
<P><termdef id="dt-cdsection" term="CDATA Section">CDATA sections can occur
anywhere character data may occur; they are
used to escape blocks of text containing characters which would
otherwise be recognized as markup.  CDATA sections begin with the
string <code>&lt;![CDATA[</code> and end with the string
<code>]]&gt;</code>:
<scrap lang="ebnf" name='CDATA sections'>
<prod>
<lhs id='NT-CDSect'>CDSect</lhs>
<rhs><nt def='NT-CDStart'>CDStart</nt> 
<nt def='NT-CData'>CData</nt> 
<nt def='NT-CDEnd'>CDEnd</nt></rhs></prod>
<prod>
<lhs id='NT-CDStart'>CDStart</lhs>
<rhs>'&lt;![CDATA['</rhs>
</prod>
<prod><lhs id='NT-CData'>CData</lhs>
<rhs>(<nt def='NT-Char'>Char</nt>* - 
(<nt def='NT-Char'>Char</nt>* ']]&gt;' <nt def='NT-Char'>Char</nt>*))
</rhs>
</prod>
<prod><lhs id='NT-CDEnd'>CDEnd</lhs>
<rhs>']]&gt;'</rhs>
</prod>
</scrap>

Within a CDATA section, only the <ident>CDEnd</ident> string is
recognized, so that left angle brackets and ampersands may occur in
their literal form; they need not (and cannot) be escaped using
<code>&amp;lt;</code> and <code>&amp;amp;</code>.  CDATA sections
cannot nest.</termdef>
</p>

<p>An example of a CDATA section: 
<eg>&lt;![CDATA[&lt;greeting>Hello, world!&lt;/greeting>]]&gt;</eg>
</p>
</DIV2>
 
<div2 type="section">
<head>White Space Handling</head>

<p>In editing XML documents, it is often convenient to use "white space"
(spaces, tabs, and blank lines, denoted by the nonterminal <code>S</code> 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 and
source code.</p>
<p>An <term def='dt-xml-proc'>XML processor</term> 
<!--* which does not read the DTD *-->
must always pass all characters in a document that are not
markup through to the application.   A <term def='dt-validating'>
validating XML processor</term> must distinguish white space
in <term def="dt-elemcontent">element content</term> from other non-markup
characters and signal
to the application that white space in element content is not
significant.
<!--* An XML processor which does read the DTD 
must always pass all
characters in <term def="dt-mixed">mixed content</term>  that are not
markup through to the application.  It may also choose to pass white
space ocurring in <term def='dt-elemcontent'>element content</term> to
the application; if it does so, it must signal to the application that
the white space in question is not significant.  *-->
<!--* Should the
processor be <term def='dt-valid'>validating</term>, it may recognize
cases where white space, appearing in <term
def='dt-elemcontent'>element content</term>, cannot be significant; it
must inform the application of this fact. *-->
</p>
<p>A special <term def='dt-attr'>attribute</term> may be inserted in
documents to signal an intention that the element to which this attribute
applies requires all white space to be treated as
significant by applications.</p>
<p>In valid documents, this attribute must be 
<term def="dt-attdecl">declared</term> as follows, if used:
<eg><![CDATA[    XML-SPACE (DEFAULT|PRESERVE) #IMPLIED]]></eg>
</p>
<p>The value <code>DEFAULT</code> signals that applications'
default white-space processing modes are acceptable for this element; the
value <code>PRESERVE</code> indicates the intent that applications preserve
all the white space.
This declared intent is considered to apply to all elements within the content
of this element, unless overriden with another instance of the
<ident>XML-SPACE</ident> attribute.
</p>
<p>The <term def='dt-root'>root element</term> of any document
is considered to have signaled no intentions as regards application space
handling, unless it provides a value for 
this attribute or the attribute is declared with a default value.
</p>
</div2>
 
<DIV2 type="section">
<HEAD>Prolog and Document Type Declaration</HEAD>
 
<P><termdef id='dt-xmldecl' term='XML Declaration'>XML documents 
may, and should, 
begin with an XML declaration which specifies, among other
things, the version of
XML being used.</termdef>
</p>
<p>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 <term def="dt-doctype">document type declaration</term>, to
define constraints on that logical structure and to support the use of
predefined storage units.
<termdef id="dt-valid" term="Validity">An XML document is said to be
<ident>valid</ident> if there is an associated document type
declaration and if the document
complies with the constraints expressed in it.</termdef></P>
<p>The document type declaration must appear before
the first <term def="dt-stag">start-tag</term> in the document.
<scrap lang="ebnf" id='xmldoc' name="XML document">
<prod>
<lhs id='NT-document'>document</lhs>
<rhs><nt def='NT-prolog'>prolog</nt> 
<nt def='NT-element'>element</nt> 
<nt def='NT-Misc'>Misc</nt>*</rhs></prod>
<prod>
<lhs id='NT-prolog'>prolog</lhs>
<rhs><nt def='NT-XMLDecl'>XMLDecl</nt>? 
<nt def='NT-Misc'>Misc</nt>* 
(<nt def='NT-doctypedecl'>doctypedecl</nt> 
<nt def='NT-Misc'>Misc</nt>*)?</rhs></prod>
<prod>
<lhs id='NT-XMLDecl'>XMLDecl</lhs>
<rhs>&xmlpio; 
<nt def='NT-VersionInfo'>VersionInfo</nt> 
<nt def='NT-EncodingDecl'>EncodingDecl</nt>? 
<nt def='NT-RMDecl'>RMDecl</nt>? 
<nt def="NT-S">S</nt>? 
&pic;</rhs>
</prod>
<prod>
<lhs id='NT-VersionInfo'>VersionInfo</lhs>
<rhs><nt def="NT-S">S</nt> 'version' <nt def='NT-Eq'>Eq</nt> 
('"&XML.version;"' | "'&XML.version;'")</rhs>
</prod>
<prod>
<lhs id='NT-Misc'>Misc</lhs>
<rhs><nt def='NT-Comment'>Comment</nt> | <nt def='NT-PI'>PI</nt> | 
<nt def='NT-S'>S</nt></rhs></prod>
</scrap></p>
<p>The identification of the XML version as "1.0" does not indicate a
commitment to produce any future versions of XML, nor if any are produced, to
use any particular numbering scheme.
Since future versions are not ruled out, this construct is provided 
as a means to allow the possibility of automatic version recognition, should
it become necessary.</p>
<p>For example, the following is a complete XML document, <term
def="dt-wellformed">well-formed</term> but not
<term def="dt-valid">valid</term>:
<eg><![CDATA[<?XML version="1.0"?>
<greeting>Hello, world!</greeting>
]]></eg>
and so is this:
<eg><![CDATA[<greeting>Hello, world!</greeting>
]]></eg>
</p>
<p><termdef id="dt-doctype" term="Document Type Declaration">The XML
<ident>document type declaration</ident> may include a pointer to an
<term def="dt-extent">external entity</term> containing a subset of
the necessary markup declarations, and may also directly include
another, internal, subset. </termdef></p>
<p><termdef id="dt-dtd" term="DTD">
These two subsets make up the
<ident>document type definition</ident>, abbreviated <ident>DTD</ident>.
The DTD, in effect, provides a grammar which defines a class of documents.
Properly speaking, the DTD consists of both subsets taken together,
but 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.</termdef>
<scrap lang="ebnf" id='dtd' name="Document type definition">
<prod><lhs id='NT-doctypedecl'>doctypedecl</lhs>
<rhs>'&lt;!DOCTYPE' <nt def='NT-S'>S</nt> 
<nt def='NT-Name'>Name</nt> (<nt def='NT-S'>S</nt> 
<nt def='NT-ExternalID'>ExternalID</nt>)? 
<!--*** 1273 *--><nt def='NT-S'>S</nt>? ('[' 
%<nt def='NT-markupdecl'>markupdecl</nt>* 
']' 
<nt def='NT-S'>S</nt>?)? '>'</rhs>
<vc name="Root Element Type">Root Element Type</vc>
<vc name="Non-null DTD">Non-null DTD</vc>
<!--*** 1277 *--></prod>
<prod><lhs id='NT-markupdecl'>markupdecl</lhs>
<!--*** 1279 *--><rhs>(
%<nt def='NT-elementdecl'>elementdecl</nt> 
| %<nt def='NT-AttlistDecl'>AttlistDecl</nt> 
| %<nt def='NT-EntityDecl'>EntityDecl</nt> 
| %<nt def='NT-NotationDecl'>NotationDecl</nt> 
<!--* | %<nt def='NT-conditionalSect'>conditionalSect</nt>  *-->
| %<nt def='NT-PI'>PI</nt> 
| %<nt def='NT-S'>S</nt> 
| %<nt def='NT-Comment'>Comment</nt>
| <nt def='NT-InternalPERef'>InternalPERef</nt> 
)*</rhs>
</prod>
<prod>
<lhs id="NT-InternalPERef">InternalPERef</lhs>
<rhs><nt def="NT-PEReference">PEReference</nt></rhs>
<wfc name="Integral Declarations">Integral Declarations</wfc>
</prod>
</scrap>
<note id="vc-roottype" n="Root Element Type" type="v-check">
The <ident>Name</ident> in the document-type declaration must
match the element type of the root element.
</note>
<note id="vc-nonnullDTD" n="Non-null DTD" type="v-check">
The internal and external subsets of the DTD must not both
be empty.
</note>
<note id="wfc-integraldec" n="Integral Declarations" type="wf-check">
A parameter-entity 
reference recognized in this context must have replacement
text consisting of zero or more complete declarations,
i.e. matching the production for the non-terminal
<ident def="nt-markupdecl">markupdecl</ident>.</note>
</p>
<p>
The external subset must obey substantially 
the same grammatical constraints
as the internal subset; i.e. it must match the production for the
non-terminal symbol
<!--*** 1267 *--><ident def="NT-markupdecl">markupdecl</ident>.
In the external subset, however, parameter-entity references can
<!-- be used where the operator % appears in a production of the grammar; -->
be used to replace constructs prefixed by <code>%</code> in a production of
the grammar, and <term def="dt-cond-section">conditional sections</term>
may occur.
In the internal subset, by contrast, conditional sections may not
occur and the only parameter-entity references 
allowed are those which match the non-terminal 
<ident def="NT-InternalPERef">InternalPERef</ident>
within the rule for <ident def="NT-doctypedecl">markupdecl</ident>.
<!-- in the internal subset, parameter entities may be used only to replace
constructs prefixed by <code>%</code> in production number 29. -->
<scrap id="ext-Subset" name="External subset">
<prod><lhs id='NT-extSubset'>extSubset</lhs>
<!--*** 1279 *--><rhs>(
%<nt def='NT-markupdecl'>markupdecl</nt> 
| %<nt def='NT-conditionalSect'>conditionalSect</nt> 
)*</rhs>
</prod>
</scrap></p>
<p>For example:
<eg><![CDATA[<?XML version="1.0"?>
<!DOCTYPE greeting SYSTEM "hello.dtd">
<greeting>Hello, world!</greeting>
]]></eg>
The <term def="dt-sysid">system identifier</term> <code>hello.dtd</code>
indicates
the location of a DTD for the document.</p>
<p>The declarations can also be given locally, as in this 
example:
<eg><![CDATA[<?XML version="1.0" encoding="UTF-8" ?>
<!DOCTYPE greeting [
  <!ELEMENT greeting (#PCDATA)>
]>
<greeting>Hello, world!</greeting>
]]></eg>
<!--
The version label <code>version="&XML.version;"</code> indicates that the
document conforms to version &XML.version; of the XML specification.
The character-set label <code><![CDATA[encoding="UTF-8"]]></code>
indicates that the document entity is encoded using the UTF-8
transformation of ISO/IEC 10646.--></p>
<p>If both the external and internal subsets are used,
an XML processor must read the internal subset first,
then the external subset.
This has the effect that entity and attribute declarations in the
internal subset take precedence over those in the external subset.
</p>
</div2>
 
<div2 type="section">
<head>Required Markup Declaration</head>
 
<p>In some cases, an <term def="dt-xml-proc">XML processor</term> can
read an XML document and accomplish useful tasks without having first
processed the entire <term def="dt-dtd">DTD</term>.  However, certain
declarations can substantially affect the actions of an XML processor.
It is desirable, therefore, to be able to specify whether a 
document contains any such declarations.
A document author can communicate whether or not DTD processing is
necessary using a <ident>required markup declaration</ident>
(abbreviated RMD), which appears as a component of the XML
declaration:
<scrap lang="ebnf" id='fulldtd' name='Required markup declaration'>
<prod><lhs id='NT-RMDecl'>RMDecl</lhs>
<rhs>
<nt def="NT-S">S</nt> 
'RMD' <nt def='NT-Eq'>Eq</nt> "'" ('NONE' | 'INTERNAL' | 'ALL') "'" 
</rhs>
<rhs>
| <nt def="NT-S">S</nt> 
'RMD' <nt def='NT-Eq'>Eq</nt> '"' ('NONE' | 'INTERNAL' | 'ALL') '"'
</rhs></prod>
</scrap></p>
<p>
In an RMD, the value <ident>NONE</ident> indicates that an XML
processor can parse the containing document correctly without first
reading any part of the DTD.  The value <ident>INTERNAL</ident>
indicates that the XML processor must read and process the <term
def="dt-doctype">internal subset</term> of the DTD, if provided, to
parse the containing document correctly.  The value <ident>ALL</ident>
indicates that the XML processor must read and process the
declarations in both the subsets of the DTD, if provided, to parse the
containing document correctly.
</p>
<p>The RMD must indicate that the entire DTD is required if the
external subset contains any declarations of<list type="bullets">
<item><p>attributes with <term def="dt-default">default</term> values, if
elements to which
these attributes apply appear in the document without
specifying values for these attributes, or</p></item>
<item><p>entities (other than &magicents;), 
if <term def="dt-entref">references</term> to those
entities appear in the document, or</p>
</item>
<!--* FINAL EDIT:  does this restriction now go away? *-->
<!--* *-->
<item>
<p>element types with <term def="dt-elemcontent">element content</term>, 
if white space occurs
directly within any instance of those types.
</p></item>
<!--* *-->
<!--* between two children.
and if that white space would not be eliminated under the
rules for white space handling in mixed content
must be suppressed
by a validating XML processor by virtue of being in
element content.*-->
</list>
If such declarations occur in the internal but not the external
subset, the RMD must take the value <ident>INTERNAL</ident>.  It is an
error to specify <ident>INTERNAL</ident> if the external subset is
required, or to specify <ident>NONE</ident> if the internal or
external subset is required.
</p>
<p>If no RMD is provided, an XML processor must behave as though 
an RMD had been provided with the value <ident>ALL</ident>.</p>
<p>An example XML declaration with an RMD:<eg
>&lt;?XML version="&XML.version;" RMD='INTERNAL'?></eg></p>
</div2>
</div1>
<!--* &Elements; *-->
 
<DIV1 type="section">
<HEAD>Logical Structures</HEAD>
 
<P><termdef id="dt-element" term="Element">Each <TERM
def="dt-xml-doc">XML document</TERM> contains one or more
<ident>elements</ident>, the boundaries of which are 
either delimited by <term def="dt-stag">start-tags</term> 
and <term def="dt-etag">end-tags</term>, or, for <term
def="dt-empty">empty</term> elements by an <term
def="dt-eetag">empty-element tag</term>. Each element has a type,
identified by name (sometimes called its <ident>generic
identifier</ident> or <ident>GI</ident>), and may  have a set of
attributes.</termdef>  Each attribute has a <TERM
def="dt-attrname">name</TERM> and a <TERM
def="dt-attrval">value</TERM>.
</p>
<P>This specification does not constrain the semantics, use, or (beyond
syntax) names of the elements and attributes, except that names
beginning with the string <mentioned>XML</mentioned> 
are reserved for standardization in this or future versions of this
specification.
<!--* must not be
used except as provided for in this specification. *-->
</P>
 
<DIV2 id='sec-starttags' type="section">
<HEAD>Start-Tags, End-Tags, and Empty-Element Tags</HEAD>
 
<P><termdef id="dt-stag" term="Start-Tag">The beginning of every
non-empty XML element is marked by a <ident>start-tag</ident>.
<scrap lang='ebnf' name='Start-tag'>
<prod><lhs id='NT-STag'>STag</lhs>
<rhs>'&lt;' <nt def='NT-Name'>Name</nt> 
(<nt def='NT-S'>S</nt> <nt def='NT-Attribute'>Attribute</nt>)* 
<nt def='NT-S'>S</nt>? '>'</rhs>
<wfc name="Unique Att Spec">Unique Att Spec</wfc>
</prod>
<prod><lhs id='NT-Attribute'>Attribute</lhs>
<rhs><nt def='NT-Name'>Name</nt> <nt def='NT-Eq'>Eq</nt> 
<nt def='NT-AttValue'>AttValue</nt></rhs>
<vc name='Attribute Value Type'>Attribute Value Type</vc>
<wfc name='No External Entity References'>No External Entity 
References</wfc></prod>
<prod><lhs id='NT-Eq'>Eq</lhs>
<rhs><nt def='NT-S'>S</nt>? '=' <nt def='NT-S'>S</nt>?</rhs></prod>
</scrap>
The <ident>Name</ident> in the start- and end-tags gives the
element's <ident>type</ident>.</termdef>
<termdef id="dt-attr" term="Attribute">
The <ident>Name</ident>-<ident>AttValue</ident> pairs are referred to as
the <ident>attribute specifications</ident> of the element</termdef>,
<termdef id="dt-attrname" term="Attribute Name">with the <ident>Name</ident>
referred to as the <ident>attribute name</ident></termdef> and
<termdef id="dt-attrval" term="Attribute Value">the content of the
<ident>AttValue</ident> (the characters between the <code>'</code> or 
<code>"</code> delimiters)
as the <ident>attribute value</ident>.</termdef>
</p>
<note id='uniqattspec' n='Unique Att Spec' type='v-check'
place='inline'>
No attribute may appear more than once in the same start-tag
or empty-element tag.
</note>
<note id='ValueType' n='Attribute Value Type' type='v-check'
place='inline'>
The attribute must have been declared; the value must be of the type 
declared for it.
(For attribute types, see the discussion of <ref target='AttDecls'>attribute
declarations</ref>.)
</note>
<note id='NoExternalRefs' n='No External Entity References' type='wf-check'
place='inline'>Attribute values cannot contain entity references to
external entities.</note>
<p>An example of a start-tag:
<eg>&lt;termdef id="dt-dog" term="dog"></eg></p>
<p><termdef id="dt-etag" term="End Tag">The end of every element 
may (for elements which are not
<term def="dt-empty">empty</term>, must) be marked by an <ident>end-tag</ident>
containing a name that echoes the element's type as given in the
start-tag:
<scrap lang='ebnf' name='End-tag'>
<prod><lhs id='NT-ETag'>ETag</lhs>
<rhs>'&lt;/' <nt def='NT-Name'>Name</nt> 
<nt def='NT-S'>S</nt>? '>'</rhs></prod>
</scrap>
</termdef></p>
<p>An example of an end-tag:<eg>&lt;/termdef></eg></p>
<P><termdef id="dt-content" term="Content">The text between the start-tag and
end-tag is called the element's
<ident>content</ident>:
<scrap lang='ebnf' name='Content of elements'>
<prod><lhs id='NT-content'>content</lhs>
<rhs>(<nt def='NT-element'>element</nt> | <nt def='NT-PCData'>PCData</nt> 
| <nt def='NT-Reference'>Reference</nt> | <nt def='NT-CDSect'>CDSect</nt> 
| <nt def='NT-PI'>PI</nt> | <nt def='NT-Comment'>Comment</nt>)*</rhs>
<vc name="Content">Content</vc>
</prod>
<prod><lhs id='NT-element'>element</lhs>
<rhs><nt def='NT-EmptyElement'>EmptyElement</nt></rhs>
<rhs>| <nt def='NT-STag'>STag</nt> <nt def='NT-content'>content</nt> 
<nt def='NT-ETag'>ETag</nt></rhs><wfc name='GI Match '>GI Match</wfc></prod>
</scrap>
</termdef></P>
<note type="v-check" id='vc-elemcont' place='inline' n='Content'>
Each element type used must be declared.
The content of an element instance must match the content model declared
for that element type.</note>
<note id='GIMatch' n='GI Match' type='wf-check' place='inline'>
The <ident>Name</ident> in an element's end-tag must match that in
the start-tag.</note>
<P><termdef id="dt-empty" term="Empty">If an element is <ident>empty</ident>,
it may be represented either by a start-tag immediately followed
by an end-tag, or by an empty-element tag.</termdef>
<termdef id="dt-eetag" term="empty-element tag">An 
Empty-element tag takes a special form:
<scrap lang='ebnf' name='Tags for empty elements'>
<prod><lhs id='NT-EmptyElement'>EmptyElement</lhs>
<rhs>'&lt;' <nt def='NT-Name'>Name</nt> (<nt def='NT-S'>S</nt> 
<nt def='NT-Attribute'>Attribute</nt>)* <nt def='NT-S'>S</nt>? 
'/&gt;'</rhs>
<wfc name="Unique Att Spec">Unique Att Spec</wfc>
</prod>
</scrap>
</termdef></p>
<p>Empty-element tags may be used for any element which has no
content, whether or not they are declared using the keyword
<kw>EMPTY</kw>.</P>
<p>Examples of empty elements:
<eg>&lt;IMG align="left"
 src="http://www.w3.org/Icons/WWW/w3c_home" />
&lt;br>&lt;/br>
&lt;br/></eg></p>
</DIV2>
 
<!--* Well-Formed XML Documents was here *-->
<DIV2 type="section" id='elemdecls'>
<HEAD>Element Declarations</HEAD>
 
<P>The <TERM def="dt-element">element</TERM> structure of an
<TERM def="dt-xml-doc">XML document</TERM> may, for 
<term def="dt-valid">validation</term> purposes, 
be constrained
using element and attribute declarations.</P>
<P>An element declaration constrains the element's
<TERM def="dt-stag">type</TERM> and its 
<TERM def="dt-content">content</TERM>.
</p>


<p>Element declarations often constrain which element types can
appear as <term def="dt-parentchild">children</term> of the element.
At user option, an XML processor may issue a warning
when a reference is made to an element type for which no declaration
is provided, but this is not an error.</p>
<P><termdef id="dt-eldecl" term="Element Declaration">An <ident>element
declaration</ident> takes the form:
<scrap lang='ebnf' name='Element declaration' rend='light'>
<prod>
<lhs id='NT-elementdecl'>elementdecl</lhs>
<!--*** 1538 *--><rhs>'&lt;!ELEMENT' <nt def='NT-S'>S</nt> 
%<nt def='NT-Name'>Name</nt> 
<nt def='NT-S'>S</nt> 
(%<nt def='NT-S'>S</nt> <nt def='NT-S'>S</nt>)?
%<nt def='NT-contentspec'>contentspec</nt>
<nt def='NT-S'>S</nt>? '>'</rhs>
<vc name='Unique Element Declaration '>
Unique Element Declaration </vc></prod>
<!--*** 1545 *--><prod>
<lhs id='NT-contentspec'>contentspec</lhs>
<rhs>'EMPTY' 
| 'ANY' 
| <nt def='NT-Mixed'>Mixed</nt> 
| <nt def='NT-elements'>elements</nt>
</rhs>
</prod>
</scrap>
where the <ident>Name</ident> gives the type of the
element.</termdef></p>

<note id='EDUnique' n='Unique Element Declaration' place='inline'
type='V-check'>
No element type may be declared more than once.</note>

<p><termdef id="dt-model" term="content model">An element can declared 
using a <ident>content model</ident>, in which case
its content can be categorized as <term 
def="dt-elemcontent">element content</term> or <term 
def='dt-mixed'>mixed content</term>,
as explained below.</termdef></p>
<p>An element declared using the keyword <kw>EMPTY</kw> must be <term
def="dt-empty">empty</term> and may be tagged using an
<term def="dt-eetag">empty-element tag</term>
when it appears in the document.</P>
<P>If an element type is declared using the keyword <kw>ANY</kw>, then
there are no validity constraints on its content:  it may
contain <term def='dt-parentchild'>child elements</term> of
any type and
number, interspersed with character data.</p>
<p>Examples of element declarations:
<eg>&lt;!ELEMENT br EMPTY>
&lt;!ELEMENT %name.para; %content.para; >
&lt;!ELEMENT container ANY></eg></p>
 
<DIV3 type="section">
<HEAD>Element Content</HEAD>
 
<P><termdef id='dt-elemcontent' term='Element content'>An element <term
def="dt-stag">type</term> may be declared to have
element content, which means that elements of that
type may only contain other elements (no character data).
</termdef>
In this case, the
constraint includes a content model, a simple grammar governing
the allowed types of the <TERM def="dt-parentchild">child</TERM>
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:
<scrap lang='ebnf' name='Element-content models'>
<prod><lhs id='NT-elements'>elements</lhs>
<rhs>(<nt def='NT-choice'>choice</nt> 
| <nt def='NT-seq'>seq</nt>) 
('?' | '*' | '+')?</rhs></prod>
<prod><lhs id='NT-cp'>cp</lhs>
<!--*** 1598 *--><rhs>(<nt def='NT-Name'>Name</nt> 
| <nt def='NT-choice'>choice</nt> 
<!--*** 1600 *-->| <nt def='NT-seq'>seq</nt>) 
('?' | '*' | '+')?</rhs></prod>
<prod><lhs id='NT-cps'>cps</lhs>
<rhs><nt def='NT-S'>S</nt>? 
<!--*** 1603 *-->%<nt def='NT-cp'>cp</nt> 
<nt def='NT-S'>S</nt>?</rhs>
</prod>
<prod><lhs id='NT-choice'>choice</lhs>
<rhs>'(' 
<nt def='NT-S'>S</nt>? 
<!--*** 1609 *-->%<nt def='NT-ctokplus'>ctokplus</nt> 
(<nt def='NT-S'>S</nt>? 
'|' 
<nt def='NT-S'>S</nt>? 
%<nt def='NT-ctoks'>ctoks</nt>)* 
<!--*** 1610 *--><nt def='NT-S'>S</nt>? 
')'</rhs></prod>
<prod>
<lhs id="NT-ctokplus">ctokplus</lhs>
<rhs><nt def="NT-cps">cps</nt>
('|' <nt def="NT-cps">cps</nt>)+
</rhs>
</prod>
<prod>
<lhs id="NT-ctoks">ctoks</lhs>
<rhs><nt def="NT-cps">cps</nt>
('|' <nt def="NT-cps">cps</nt>)*
</rhs>
</prod>
<prod><lhs id='NT-seq'>seq</lhs>
<rhs>'(' 
<nt def='NT-S'>S</nt>?
<!--*** 1614 *-->%<nt def='NT-stoks'>stoks</nt> 
(<nt def='NT-S'>S</nt>?
',' 
<nt def='NT-S'>S</nt>? 
%<nt def='NT-stoks'>stoks</nt>)*
<!--*** 1616 *--><nt def='NT-S'>S</nt>? ')'</rhs></prod>
<prod>
<lhs id="NT-stoks">stoks</lhs>
<rhs><nt def="NT-cps">cps</nt>
(',' <nt def="NT-cps">cps</nt>)*
</rhs>
</prod>
</scrap>
where each <ident>Name</ident> gives the type of an element which may
appear as a <term def="dt-parentchild">child</term>.  Any content
particle in a choice list may appear in the <term
def="dt-elemcontent">element content</term> at the appropriate
location; content particles occurring in a sequence list must each
appear in the <term def="dt-elemcontent">element content</term> 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 (<code>+</code>), zero or more (<code>*</code>), or zero or 
one times (<code>?</code>).  The syntax
and meaning are identical to those used in the productions in this
specification.  </P>
<p>
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.  <term
def='dt-compat'>For compatibility reasons</term>, 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 <ref target='Dragon'>Aho, Sethi, and Ullman</ref>.
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.
For more information, see the appendix on <ref target="determinism">
deterministic content models</ref>.
</p>
<p>Examples of element-content models:
<eg>&lt;!ELEMENT spec (front, body, back?)>
&lt;!ELEMENT div1 (head, (p | list | note)*, div2*)>
&lt;!ELEMENT head (%head.content; | %head.misc;)*></eg></p>
</DIV3>

<DIV3 type="section">
<HEAD>Mixed Content</HEAD>
 
<P><termdef id='dt-mixed' term='Mixed Content'>An element type may be
declared to contain
mixed content, that is, <term def="dt-text">text</term> comprising <TERM
def="dt-chardata">character
data </TERM> optionally interspersed with
<TERM def="dt-parentchild">child</TERM> elements.</termdef>
In this case, the <TERM def="dt-stag">types</TERM> of the child elements are
constrained, but not their order nor their number of occurrences:
<scrap lang='ebnf' name='Mixed-content declaration'>
<prod>
<lhs id='NT-Mixed'>Mixed</lhs>
<!--*** 1671 *--><rhs>'(' <nt def='NT-S'>S</nt>? 
%( %'#PCDATA'
(<nt def='NT-S'>S</nt>? 
<!--*** 1676 *-->'|' 
<nt def='NT-S'>S</nt>? 
<!--*** 1678 *-->%<nt def='NT-Mtoks'>Mtoks</nt>)* 
) 
<nt def='NT-S'>S</nt>? 
')*' </rhs>
<!--*** 1697 *--><rhs>| '(' <nt def='NT-S'>S</nt>? %('#PCDATA') <nt def='NT-S'>S</nt>? ')'
</rhs></prod>
<prod>
<lhs id="NT-Mtoks">Mtoks</lhs>
<rhs>%<nt def="NT-Name">Name</nt>
(<nt def='NT-S'>S</nt>? 
'|' 
<nt def='NT-S'>S</nt>? 
 %<nt def="NT-Name">Name</nt>)*
</rhs>
</prod>
</scrap>
where the <ident>Name</ident>s give the types of elements
that may appear as children.
The same name must not appear more than once in a single mixed-content
declaration.
</P>
<p>Examples of mixed content declarations:
<eg>&lt;!ELEMENT p (#PCDATA|a|ul|b|i|em)*>
&lt;!ELEMENT p (#PCDATA | %font; | %phrase; | %special; | %form;)* >
&lt;!ELEMENT b (#PCDATA)></eg></p>
</DIV3>
</DIV2>
 
<DIV2 type="section" id='attdecls'>
<HEAD>Attribute-List Declarations</HEAD>
 
<P><TERM def="dt-attr">Attributes</TERM> are used to associate
name-value pairs with <TERM def="dt-element">elements</TERM>.
Attributes may appear only within <term
def="dt-stag">start-tags</term>; thus, the productions used to
recognize them appear in the discussion of 
<ref target='sec-starttags'>start-tags</ref>.  Attribute-list
declarations may be used:<LIST TYPE="bullets">
<item><p>To define the set of attributes pertaining to a given
element type.</p></item>
<ITEM><P>To establish a set of type constraints on these
attributes.</P></ITEM>
<ITEM><P>To provide <TERM def="dt-default">default values</TERM>
for attributes.</P></ITEM>
</LIST></P>
<P><termdef id="dt-attdecl" term="Attribute-List Declaration">
Attribute-list declarations specify the name, data type, and default
value (if any) of each attribute associated with a given element type:
<scrap lang='ebnf' name='Attribute list declaration'>
<prod><lhs id='NT-AttlistDecl'>AttlistDecl</lhs>
<!--*** 1734 *--><rhs>'&lt;!ATTLIST' <nt def='NT-S'>S</nt> 
%<nt def='NT-Name'>Name</nt> 
<nt def='NT-S'>S</nt>? 
<!--*** 1737 *-->%<nt def='NT-AttDef'>AttDef</nt>+
<nt def='NT-S'>S</nt>? '&gt;'</rhs>
<!--* 
<vc name='Unique Attribute-List Declaration '>Unique Attribute-List 
Declaration</vc>
*-->
</prod>
<prod><lhs id='NT-AttDef'>AttDef</lhs>
<!--*** 1745 *--><rhs><nt def='NT-S'>S</nt> %<nt def='NT-Name'>Name</nt> 
<nt def='NT-S'>S</nt> %<nt def='NT-AttType'>AttType</nt> 
<nt def='NT-S'>S</nt> %<nt def='NT-Default'>Default</nt></rhs>
<!--* 
<vc name='Unique Attribute Name '>Unique Attribute Name </vc> 
*-->
</prod>
</scrap>
The <ident def="NT-Name">Name</ident> in the
<ident>AttlistDecl</ident> rule is the type of an element.  At user
option, an XML processor may issue a warning if attributes are
declared for an element type not itself declared, but this is not an
error.  The <ident>Name</ident> in the <ident>AttDef</ident> rule is
the name of the attribute.</termdef></p>
<!--* 
<note type='V-Check' id='ALUnique' n='Unique Attribute-List Declaration'
place='inline'>At most one attribute-list declaration may be provided
for a given element type.</note>
<note type='V-Check' id='ANUnique' n='Unique Attribute Name'
place='inline'>An attribute name may appear at most once in an
attribute-list declaration.</note>
*-->
<p>
When more than one <ident>AttlistDecl</ident> is provided for a given
element type, the contents of all those provided are merged.  When
more than one definition is provided for the same attribute of a
given element type, the first declaration is binding and later
declarations are ignored.  
<term def='dt-interop'>For interoperability,</term> writers of DTDs
may choose to provide at most one attribute-list declaration
for a given element type, and at most one attribute definition
for a given attribute name.
For interoperability, an XML processor may at user option
issue a warning when more than one attribute-list declaration is
provided for a given element type, or more than one attribute definition
for a given attribute, but this is not an error.
</p>

<DIV3 type="section">
<HEAD>Attribute Types</HEAD>
 
<P>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:
<scrap lang='ebnf' name='Attribute types'>
<prod><lhs id='NT-AttType'>AttType</lhs>
<!--*** 1794 *--><rhs><nt def='NT-StringType'>StringType</nt> 
| <nt def='NT-TokenizedType'>TokenizedType</nt> 
<!--*** 1796 *-->| <nt def='NT-EnumeratedType'>EnumeratedType</nt>
</rhs>
</prod>
<prod><lhs id='NT-StringType'>StringType</lhs>
<rhs>'CDATA'</rhs>
</prod>
<prod><lhs id='NT-TokenizedType'>TokenizedType</lhs>
<rhs>'ID'</rhs>
<vc name='ID '>ID </vc>
<rhs>| 'IDREF'</rhs>
<vc name='Idref '>Idref </vc>
<rhs>| 'IDREFS'</rhs>
<vc name='Idref '>Idref </vc>
<rhs>| 'ENTITY'</rhs>
<vc name='Entity Name '>Entity Name </vc>
<rhs>| 'ENTITIES'</rhs>
<vc name='Entity Name '>Entity Name </vc>
<rhs>| 'NMTOKEN'</rhs>
<vc name='Name Token '>Name Token </vc>
<rhs>| 'NMTOKENS'</rhs>
<vc name='Name Tokens '>Name Token </vc></prod>
</scrap>
</P>
<note type='V-Check' id='id'  n='ID'>Values of this type must be valid
<code>Name</code> 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.   
</note>
<note type='V-Check' id='idref' n='Idref'>Values of this type must match
the <ident def="NT-Name">Name</ident> 
(for <kw>IDREFS</kw>, the <ident def="NT-Names">Names</ident>) production; 
each <ident>Name</ident> must match the value of an ID attribute on 
some element in the XML document; i.e. <kw>IDREF</kw> values must 
match some ID. 
</note>
<note type='V-Check' id='entname' n='Entity Name'>Values of this type
must match the production for <ident def="NT-Name">Name</ident> 
(for <kw>ENTITIES</kw>, <ident def="NT-Names">Names</ident>);
each <ident def="NT-Name">Name</ident> must 
<term def="dt-exact">exactly match</term> the
name of an <term def="dt-extent">external</term> <term
def="dt-binent">binary general entity</term> declared in the <term
def="dt-dtd">DTD</term>.</note>
<note type='V-Check' id='nmtok' n='Name token'>Values of this type
must consist of a string matching the <term
def="NT-Nmtoken">Nmtoken</term> nonterminal 
(for <kw>NMTOKENS</kw>, the <term
def="NT-Nmtokens">Nmtokens</term> nonterminal) of the grammar defined
in this specification.</note>
<p>The XML processor must normalize attribute values before
passing them to the application, as described in the section
on <ref target="AVNormalize">attribute-value normalization</ref>.</p>
<P>Enumerated attributes can take one of a list of values provided in
the declaration; there are two types: 
<scrap lang='ebnf' name='Enumerated attribute types'> 
<prod>
<lhs id='NT-EnumeratedType'>EnumeratedType</lhs> 
<rhs><nt def='NT-NotationType'>NotationType</nt> 
| <nt def='NT-Enumeration'>Enumeration</nt>
</rhs></prod>
<prod>
<lhs id='NT-NotationType'>NotationType</lhs> 
<!--*** 1857 *--><rhs>%'NOTATION' 
<nt def='NT-S'>S</nt> 
'(' 
<nt def='NT-S'>S</nt>?  
%<nt def='NT-Ntoks'>Ntoks</nt> 
(<nt def='NT-S'>S</nt>? '|' <nt def='NT-S'>S</nt>? 
%<nt def='NT-Ntoks'>Ntoks</nt>)* 
<!--*** 1864 *--><nt def='NT-S'>S</nt>? 
')' </rhs>
<vc name='Notation Attributes ' >Notation Attributes </vc></prod>
<prod>
<lhs id="NT-Ntoks">Ntoks</lhs>
<rhs>%<nt def="NT-Name">Name</nt>
(<nt def='NT-S'>S</nt>? 
'|' 
<nt def='NT-S'>S</nt>? 
 %<nt def="NT-Name">Name</nt>)*
</rhs>
</prod>
<!--*** 1866 *--><prod>
<lhs id='NT-Enumeration'>Enumeration</lhs> 
<rhs>'(' <nt def='NT-S'>S</nt>?
<!--*** 1871 *-->%<nt def='NT-Etoks'>Etoks</nt> 
(<nt def='NT-S'>S</nt>? '|' 
<nt def='NT-S'>S</nt>?  
<!--*** 1874 *-->%<nt def='NT-Etoks'>Etoks</nt>)* 
<nt def='NT-S'>S</nt>? 
')'</rhs> 
<vc name='Enumeration '>Enumeration</vc></prod>
<prod>
<lhs id="NT-Etoks">Etoks</lhs>
<rhs>%<nt def="NT-Nmtoken">Nmtoken</nt>
(<nt def='NT-S'>S</nt>? 
'|' 
<nt def='NT-S'>S</nt>? 
 %<nt def="NT-Nmtoken">Nmtoken</nt>)*
</rhs>
</prod>
</scrap>
</p>

<note type='V-Check' id='notatn' n='Notation Attributes'>The names in
the declaration of <kw>NOTATION</kw> attributes must be names of
declared notations (see the discussion of <ref
target='Notations'>notations</ref>).  Values of this type must match
one of the notation names included in the declaration.</note>
<note type='V-Check' id='enum' n='Enumeration'>Values of this type
must match one of the <code>Nmtoken</code> tokens in the declaration.
<term def='dt-interop'>For interoperability,</term> the same
<code>Nmtoken</code> should not occur more than once in the enumerated
attribute types of a single element type.</note>
</DIV3>
 
<DIV3 type="section">
<HEAD>Attribute Defaults</HEAD>
 
<P>An <term def="dt-attdecl">attribute declaration</term> provides
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:
<scrap lang='ebnf' name='Attribute defaults'>
<prod><lhs id='NT-Default'>Default</lhs>
<!--*** 1914 *--><rhs>'#REQUIRED' 
|&nbsp;'#IMPLIED' </rhs>
<vc name='Attribute Default Legal '>Attribute Default Legal </vc>
<!--*** 1916 *--><rhs>|<!--&nbsp;--> ((%'#FIXED' S)? %<nt def='NT-AttValue'>AttValue</nt>)</rhs>
<!--*** 1918 ***--></prod>
</scrap>
<kw>#REQUIRED</kw> means that 
<!--* it
is a <TERM def="dt-reportable">reportable error</TERM> *-->
the document is <term def="dt-valid">invalid</term>
should the processor
encounter a
<TERM def="dt-stag">start-tag</TERM> 
for the element type in question which specifies no value for
this attribute.
<!--* where this attribute is omitted,
i.e. could occur but
does not. *-->
<kw>#IMPLIED</kw> means that if the attribute is omitted
from an element of this type,
the XML processor must inform the application
that no value was specified; no constraint is placed on the behavior
of the application.</P>
<P><termdef id="dt-default" term="Attribute Default">If the attribute
is neither <kw>#REQUIRED</kw> nor <kw>#IMPLIED</kw>, then the
<ident>AttValue</ident> value contains the declared
<ident>default</ident> value. If the <kw>#FIXED</kw> is present, 
<!--* it is
a <TERM def="dt-reportable">reportable error</TERM> 
*-->
the document is <term def="dt-valid">invalid</term>
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 behave as though the attribute were present with its value being
the declared default value.</termdef></P>
<note type='V-Check' id='defattrvalid' n='Attribute Default Legal'>The 
declared
default value must meet the constraints of the declared attribute type.</note>

<p>Examples of attribute-list declarations:
<eg>&lt;!ATTLIST termdef
          id      ID      #REQUIRED
          name    CDATA   #IMPLIED>
&lt;!ATTLIST list
          type    (bullets|ordered|glossary)  "ordered">
&lt;!ATTLIST form
          method  CDATA   #FIXED "POST"></eg></p>
</DIV3>
<DIV3 id='AVNormalize' type="section">
<head>Attribute-Value Normalization</head>
<p>Before the value of an attribute is passed to the application, the
XML processor must normalize it as follows:
<list type="numbered">
<item><p>Line-end characters (or, on some systems, record boundaries)
must be replaced by single space (#x20) characters.
</p></item>
<item><p>Character references and references to internal text
entities must be expanded. References to external entities
are an <!-- a reportable --> error.
</p></item>
<item><p>If the attribute is not of type <kw>CDATA</kw>, all strings
of white space must be normalized to single space characters (#x20),
and leading and trailing white space must be removed.</p></item>
<item><p>Values of type <kw>ID</kw>,
<kw>IDREF</kw>,
<kw>IDREFS</kw>,
<kw>NMTOKEN</kw>,
<kw>NMTOKENS</kw>, or of enumerated or notation types, must be 
<term def='dt-casefold'>folded</term> to
uppercase.</p>
</item>
</list>
If no DTD is present, attributes should be treated as <kw>CDATA</kw>.
<!--* need note on how to treat attribute values if no DTD
is present or has been read.  Is this CDATA or is it 
implementation-specific? *-->
</p>
</DIV3>
</DIV2>
<div2 type="section"><head>Conditional Sections</head>
<p><termdef id='dt-cond-section' term='conditional section'
>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.</termdef>
<scrap lang='ebnf' name='Conditional section'>
<prod><lhs id='NT-conditionalSect'>conditionalSect</lhs>
<rhs><nt def='NT-includeSect'>includeSect</nt>
| <nt def='NT-ignoreSect'>ignoreSect</nt>
</rhs>
</prod>
<prod><lhs id='NT-includeSect'>includeSect</lhs>
<!--*** 1996 *--><rhs>'&lt;![' %'INCLUDE' '[' 
(%<nt def='NT-markupdecl'>markupdecl</nt>*)* ']]&gt;'</rhs>
</prod>
<prod><lhs id='NT-ignoreSect'>ignoreSect</lhs>
<!--*** 2000 *--><rhs>'&lt;![' %'IGNORE' '[' 
<nt def="NT-ignoreSectContents">ignoreSectContents</nt>*
<!--*** 2010 *-->']]&gt;'</rhs>
<!--*** 2011 *--></prod>

<prod><lhs id='NT-ignoreSectContents'>ignoreSectContents</lhs>
<rhs>
((<nt def='NT-SkipLit'>SkipLit</nt> 
| <nt def='NT-Comment'>Comment</nt>
| <nt def='NT-PI'>PI</nt>) - 
(<nt def='NT-Char'>Char</nt>* ']]&gt;' <nt def='NT-Char'>Char</nt>*))
</rhs>
<rhs>
| ('&lt;![' <nt def='NT-ignoreSectContents'>ignoreSectContents</nt>* ']]&gt;')
</rhs>
<rhs>
| (<nt def='NT-Char'>Char</nt> - (']' | [&lt;'"]))
</rhs>
<rhs>
| ('&lt;!' (<nt def='NT-Char'>Char</nt> - ('-' | '[')))
</rhs>
</prod>
</scrap>
</p>
<p>Like the internal and external DTD subsets, a conditional section
may contain one or more complete declarations,
comments, processing instructions, 
or nested conditional sections, intermingled with white space.
<!--* Conditional sections must not occur within declarations, except
the document-type declaration. *-->
</p>
<p>If the keyword of the conditional section is
<code>INCLUDE</code>, then the conditional section is read and
processed in the normal way.  If the keyword is
<code>IGNORE</code>, 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 <code>INCLUDE</code> occurs within a larger conditional
section with a keyword of <code>IGNORE</code>, both the outer and the
inner conditional sections are ignored.</p>
<p>If the keyword 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.</p>
<p>An example:
<eg>&lt;!ENTITY % draft 'INCLUDE' >
&lt;!ENTITY % final 'IGNORE' >
 
&lt;![%draft;[
&lt;!ELEMENT book (comments*, title, body, supplements?)>
]]&gt;
&lt;![%final;[
&lt;!ELEMENT book (title, body, supplements?)>
]]&gt;
</eg>
</p>
</div2>


<!--* 
<div2>
<head>XML Processor Treatment of Logical Structure</head>
<p>When an XML processor encounters a start-tag, it must make
at least the following information available to the application:<list>
<item>
<p>the element type's generic identifier</p>
</item>
<item>
<p>the names of attributes known to apply to this element type
(validating processors must make available names of all attributes
declared for the element type; non-validating processors must
make available at least the names of the attributes for which
values are specified.
</p>
</item>
</list>
</p>
</div2>
*--> 

</DIV1>
<!--* &Entities; *-->
 
<div1 type="section">
<head>Physical Structures</head>
 
<P><termdef id="dt-entity" term="Entity">An XML document may consist
of one or many virtual storage units.   These are called
<ident>entities</ident>; they are identified by name and have
<ident>content</ident>.</termdef> 
<!--* Added for CFG *-->
<!-- obscurity amputated by TWB -->
An entity may be stored in, <!--but need not be coterminous with, -->
but need not comprise the whole of, 
a single physical storage object such as a file or <!-- stream. -->
database field.
<!--* End sentence added for CFG *-->
Each XML document has one entity
called the <TERM def="dt-docent">document entity</TERM>, which serves
as the starting point for the <term def="dt-xml-proc">XML
processor</term> (and may contain the whole document).  </P>
<p>Entities may be either binary or text.
<termdef id="dt-textent" term="Text Entity">A text entity contains
<term def="dt-text">text</term> data which is considered as an
integral part of the document.</termdef>
<termdef id="dt-binent" term="Binary Entity">A binary entity contains
<term def="dt-binary">binary</term> data with an associated <term
def="dt-notation">notation</term>.</termdef>
Only text entities may be referred to using entity references;
only the names of binary entities may be given as the value of <kw>ENTITY</kw>
attributes.</p>
<!--* References to text and binary entities cannot be distinguished
by syntax; their types are established in their declarations.</p> *-->
 
<div2 id='sec-logphys' type='section'>
<head>Logical and Physical Structures</head>
<p>The logical and physical structures (elements and entities)
in an XML document must
be synchronous.
<term def='dt-stag'>Tags</term> and <term def='dt-element'>elements</term> must
each begin and end in the same <term def='dt-entity'>entity</term>,  but may
refer to other 
entities internally; <term def='dt-comment'>comments</term>, 
<term def='dt-pi'>processing instructions</term>, 
<term def='dt-charref'>character
references</term>, and 
<term def='dt-entref'>entity references</term> 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.</p></div2>
<DIV2 type="section">
<HEAD>Character and Entity References</HEAD>
<P><termdef id="dt-charref" term="Character Reference">
A <ident>character reference</ident> refers to a specific character in the
ISO/IEC 10646 character set, e.g. one not directly accessible from
available input devices:
<scrap lang='ebnf' name='Character reference'>
<prod><lhs id='NT-CharRef'>CharRef</lhs>
<rhs>'&amp;#' [0-9]+ ';' </rhs>
<rhs>| '&hcro;' [0-9a-fA-F]+ ';'</rhs></prod>
</scrap></termdef>
</P>
<!--* keep or drop next para? *-->
<!--*
<p>Character references of the form <code>&hcro;</code> followed by
one or more hexadecimal digits are provided in anticipation of their
adoption by ISO 8879.</p>
*-->
<P><termdef id="dt-entref" term="Entity Reference">An <ident>entity
reference</ident> refers to the content of a named entity.</termdef>
<termdef id='gen-entity' term='general entity'>General entities are
text entities for use within the document itself; references to them
use ampersand (<code>&amp;</code>) and semicolon (<code>;</code>) as
delimiters.  In this specification,  
general entities are sometimes referred to with the
unqualified term <mentioned>entity</mentioned> when this leads
to no ambiguity.</termdef> <termdef id='dt-param-entity' term='parameter
entity'>Parameter entities are text entities for use within the DTD,
or to control processing of 
<term def='dt-cond-section'>conditional sections</term>;
references to them use percent-sign (<code>%</code>) and semicolon
(<code>;</code>) as delimiters.</termdef>
<SCRAP name='Entity reference' LANG="EBNF">
<prod><lhs id='NT-Reference'>Reference</lhs>
<rhs><nt def='NT-EntityRef'>EntityRef</nt> 
| <nt def='NT-CharRef'>CharRef</nt></rhs></prod>
<prod><lhs id='NT-EntityRef'>EntityRef</lhs>
<rhs>'&amp;' <nt def='NT-Name'>Name</nt> ';'</rhs>
<wfc name='Entity Declared'>Entity Declared</wfc>
<wfc name='Text Entity '>Text Entity </wfc>
<wfc name='No Recursion'>No Recursion</wfc>
</prod>
<prod><lhs id='NT-PEReference'>PEReference</lhs>
<rhs>'%' <nt def='NT-Name'>Name</nt> ';'</rhs>
<wfc name='Entity Declared'>Entity Declared</wfc>
<wfc name='Text Entity '>Text Entity </wfc>
<wfc name='No Recursion'>No Recursion</wfc>
<wfc name='In DTD'>In DTD</wfc>
</prod>
</scrap>
</p>
<note type='WF-Check' id='entdeclared' n='Entity Declared'>
The <ident>Name</ident> given in the entity reference must <term
def="dt-exact">exactly match</term> the name given in the declaration
of the entity, except that well-formed documents need not declare
any of the following entities: &magicents;.  In valid
documents, these entities must be declared, in the form
specified in the <ref target="sec-escapes">section on
predefined entities</ref>.
In the case of parameter entities, the declaration
must precede the reference.
</note>
<note type='WF-Check' id='textent' n='Text Entity'>
An entity reference must not contain the name of a <term
def="dt-binent">binary entity</term>. Binary entities may be referred
to only in <term def="dt-attrval">attribute values</term> declared to
be of type <kw>ENTITY</kw> or <kw>ENTITIES</kw>.</note>
<note type='WF-Check' id='norecursion' n='No Recursion'>
A text or parameter entity must not contain a recursive reference to itself,
either directly or indirectly.</note>
<note type='WF-Check' id='indtd' n='In DTD'>
In the external DTD subset, a parameter-entity reference is 
recognized only at the locations where
the nonterminal <ident def="NT-PEReference">PEReference</ident> or the
special operator <code>%</code> appears in a production of the
grammar.  In the internal subset, parameter-entity references
are recognized only when they match 
the <ident def="NT-InternalPERef">InternalPERef</ident> non-terminal
in the production for <ident def="NT-markupdecl">markupdecl</ident>.
<!--* are recognized only where the special operator <code>%</code> appears in
production number 29 of the grammar. *-->
</note>
<p>Examples of character and entity references:
<eg>Type &lt;key>less-than&lt;/key> (&hcro;3C;) to save options.
This document was prepared on &amp;docdate; and
is classified &amp;security-level;.</eg></p>
<p>Example of a parameter-entity reference:
<eg>&lt;!ENTITY % ISOLat2
         SYSTEM "http://www.xml.com/iso/isolat2-xml.entities" >
%ISOLat2;
</eg></p>
</DIV2>
 
<DIV2 type="section">
<HEAD>Entity Declarations</HEAD>
 
<P>Entities are declared thus:
<SCRAP name='Entity declaration' LANG="ebnf">
<prod><lhs id='NT-EntityDecl'>EntityDecl</lhs>
<!--*** 2188 *--><rhs>'&lt;!ENTITY' <nt def='NT-S'>S</nt> %<nt def='NT-Name'>Name</nt> 
<nt def='NT-S'>S</nt> %<nt def='NT-EntityDef'>EntityDef</nt> 
<nt def='NT-S'>S</nt>? '&gt;'</rhs>
<com>General entities</com>
<rhs>| '&lt;!ENTITY' <nt def='NT-S'>S</nt> '%' <nt def='NT-S'>S</nt> 
<!--*** 2193 *-->%<nt def='NT-Name'>Name</nt> <nt def='NT-S'>S</nt> 
%<nt def='NT-EntityDef'>EntityDef</nt> <nt def='NT-S'>S</nt>? '&gt;'</rhs>
<com>Parameter entities</com>
</prod>
<prod><lhs id='NT-EntityDef'>EntityDef</lhs>
<!--*** 2198 *--><rhs><nt def='NT-EntityValue'>EntityValue</nt> 
| <nt def='NT-ExternalDef'>ExternalDef</nt></rhs></prod>
</scrap>
The <ident>Name</ident> is that by which the entity is invoked by
<term def="dt-exact">exact match</term> in an <term def="dt-entref">entity
reference</term>.
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.
</P>
 
<div3 type="section">
<head>Internal Entities</head>
 
<p>If the entity definition is an <ident>EntityValue</ident>, the 
defined entity is
called an <ident>internal</ident> entity.  There is no separate physical
storage object, and the replacement text of the entity is given in the
declaration. Within the <ident def="NT-EntityValue">EntityValue</ident>,
parameter-entity references and character references are recognized
and expanded immediately. General-entity references within the
replacement text are not recognized
at the time the entity declaration is parsed, though they may be
recognized when the entity itself is referred to.
</p>
<p>An internal entity is a <term def="dt-textent">text entity</term>.</p>
<p>Example of an internal entity declaration:
<eg>&lt;!ENTITY Pub-Status "This is a pre-release of the
 specification."></eg></p>
</div3>
 
<div3 type="section">
<head>External Entities</head>
 
<p><termdef id="dt-extent" term="External Entity">If the entity is not
internal, it is an <ident>external
entity</ident>, declared as follows:
<scrap lang='ebnf' name='External entity declaration'>
<prod><lhs id='NT-ExternalDef'>ExternalDef</lhs>
<rhs><nt def='NT-ExternalID'>ExternalID</nt> 
%<nt def='NT-NDataDecl'>NDataDecl</nt>?</rhs></prod>
<prod>
<lhs id='NT-ExternalID'>ExternalID</lhs>
<rhs>'SYSTEM' <nt def='NT-S'>S</nt> 
<nt def='NT-SystemLiteral'>SystemLiteral</nt></rhs>
<rhs>|&nbsp; 'PUBLIC' <nt def='NT-S'>S</nt> 
<nt def='NT-PubidLiteral'>PubidLiteral</nt> 
<nt def='NT-S'>S</nt> 
<nt def='NT-SystemLiteral'>SystemLiteral</nt>
</rhs>
</prod>

<prod><lhs id='NT-NDataDecl'>NDataDecl</lhs>
<!--*** 2249 *--><rhs><nt def='NT-S'>S</nt> %'NDATA' <nt def='NT-S'>S</nt> 
%<nt def='NT-Name'>Name</nt></rhs>
<!--*** 2251 *--><vc name='Notation Declared '>Notation Declared </vc></prod>
</scrap>
If the <ident>NDataDecl</ident> is present, this is a <term
def="dt-binent">binary
data entity</term>, otherwise a text entity.</termdef></p>
<note type='V-Check' id='not-declared' n='Notation Declared'>
The <ident>Name</ident> must match the declared name of a
<term def="dt-notation">notation</term>.
</note>
<p><termdef id="dt-sysid" term="System Identifier">The
<ident>SystemLiteral</ident>  that follows the keyword <kw>SYSTEM</kw>
is called the entity's <ident>system identifier</ident>. It is a URL,
which may be used to retrieve the entity.</termdef>
Unless otherwise provided by information outside the scope of this
specification (e.g. a special XML element defined by a particular
DTD, or a processing instruction defined by a particular application
specification), 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.
</p>
<p><termdef id="dt-pubid" term="Public identifier">
In addition to a system literal, an external identifier may
include a public identifier.</termdef>  
An XML processor may use the public
identifier to try to generate an alternative URL.  If the processor
is unable to do so, it must use the URL specified in the system
literal.</p>
<p>Examples of external entity declarations:
<eg>&lt;!ENTITY open-hatch
         SYSTEM "http://www.textuality.com/boilerplate/OpenHatch.xml">
&lt;!ENTITY open-hatch
         PUBLIC "-//Textuality//TEXT Standard open-hatch boilerplate//EN"
         "http://www.textuality.com/boilerplate/OpenHatch.xml">
&lt;!ENTITY hatch-pic
         SYSTEM "../grafix/OpenHatch.gif"
         NDATA gif ></eg></p>
</DIV3>
 
<DIV3 type="section" id='charencoding'>
<HEAD>Character Encoding in Entities</HEAD>
 
<P>Each external 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 UTF-8 or UCS-2. 
It is recognized that for some purposes, the use of additional
ISO/IEC 10646 planes other than the Basic Multilingual Plane
may be required.  
<!-- Characters in these additional planes may be 
encoded using UCS-4 or UTF-16 (or, of course, UTF-8); the 
correct handling of these encoding schemes is therefore a -->
A facility for handling characters in these planes is therefore a
desirable characteristic in XML processors and applications.
<!--* It is recognized that for some
purposes, particularly work with Asian languages, the use of the
UTF-16 transformation is required, and correct handling of this
encoding is a desirable characteristic in XML processor
implementations.
*-->
</P>
<P>
Entities encoded in UCS-2 must
begin with the Byte Order Mark described by ISO/IEC 10646 Annex E and
Unicode Appendix B (the ZERO WIDTH NO-BREAK SPACE character, #xFEFF).
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.</P>
<p>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 encodings.
For this purpose, XML provides an encoding declaration
<term def="dt-pi">processing instruction</term>, which, if it occurs, 
must appear at the
beginning of a system entity, before any
other <term def="dt-chardata">character data</term> or <term
def="dt-markup">markup</term>.  In the document entity, the encoding
declaration is part of the <term def="dt-xmldecl">XML declaration</term>;
in other entities, it is part of an encoding processing instruction:
<SCRAP name='Encoding declaration' LANG="EBNF">
<prod><lhs id='NT-EncodingDecl'>EncodingDecl</lhs>
<rhs>
<nt def='NT-S'>S</nt> 'encoding' <nt def='NT-Eq'>Eq</nt> 
<nt def='NT-QEncoding'>QEncoding</nt> 
</rhs>
<wfc name="Start of System Entity">Start of System Entity</wfc>
</prod>
<prod><lhs id='NT-EncodingPI'>EncodingPI</lhs>
<rhs>&xmlpio; <nt def='NT-S'>S</nt> 'encoding' <nt def='NT-Eq'>Eq</nt> 
<nt def='NT-QEncoding'>QEncoding</nt> 
<nt def='NT-S'>S</nt>? &pic;</rhs></prod>
<prod><lhs id='NT-QEncoding'>QEncoding</lhs>
<rhs>'"' <nt def='NT-Encoding'>Encoding</nt> '"' | "'" 
<nt def='NT-Encoding'>Encoding</nt> "'"</rhs></prod>
<prod><lhs id='NT-Encoding'>Encoding</lhs>
<rhs><nt def='NT-LatinName'>LatinName</nt></rhs>
</prod>
<prod><lhs id='NT-LatinName'>LatinName</lhs>
<rhs>[A-Za-z] ([A-Za-z0-9._] | '-')*</rhs>
<com>Name containing only Latin characters</com>
</prod>
</scrap></p>
<note id="wf-encdecl" n="Start of System Entity" type="wf-check">
An XML encoding declaration may occur at the beginning of a
system entity; it must 
not occur within the body of any entity. 
</note>
<!--* FINAL EDIT:  check name of IANA and charset names *-->
<p>The values
<code>UTF-8</code>,
<code>UTF-16</code>,
<code>ISO-10646-UCS-2</code>, and
<code>ISO-10646-UCS-4</code> should be 
used for the various encodings and transformations of Unicode /
ISO/IEC 10646, the values
<code>ISO-8859-1</code>,
<code>ISO-8859-2</code>, ...
<code>ISO-8859-9</code> should be used for the parts of ISO 8859, and
the values
<code>ISO-2022-JP</code>,
<code>Shift_JIS</code>, and
<code>EUC-JP</code>
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 (as <term>charset</term>s) 
with the Internet Assigned Numbers
Authority (IANA), other than those just listed, should be referred to
using their registered names.
</p>
<p>It is an <term def="dt-error">error</term> for an entity including
an encoding declaration to be presented to the XML processor 
in an encoding other than that
named in the declaration. </p>

<p>An entity which begins with neither a Byte Order Mark nor an encoding
declaration must be in the UTF-8 encoding.</p>
<p>
While XML provides mechanisms for distinguishing encodings,
it is recognized that in a heterogeneous networked environment, 
it may be difficult to signal the encoding of an entity reliably.
<!--* there is often difficulty in reliably signaling the
 encoding of an entity. *-->
Errors in this area fall into two categories:
<list type="numbered">
<item><p>failing to read an entity because of inability to recognize
its actual encoding, and </p></item>
<item><p>reading an entity incorrectly because
of an incorrect guess of its proper encoding.</p></item></list>
The first class of error is extremely damaging, and given a
correct encoding declaration, 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:
<list type="bullets"><item><p>Using information from an HTTP header</p></item>
<item><p>Using a MIME header obtained other than through HTTP</p></item>
<item><p>Metadata provided by the native OS file system or by document
management software</p></item>
<item><p>Analysing the bit patterns at the front of an entity to determine if
the application of any known encoding yields a valid encoding
declaration.  See <ref target='sec-guessing'>the appendix on
autodetection of character sets</ref> 
for a fuller description.</p></item></list>
If an XML processor encounters an entity with an encoding that it is
unable to process, it may
<!--* must *-->
inform the application of this fact and 
may 
allow the application to
request either that the entity should be treated as an <TERM
def="dt-binent">binary entity</TERM>, or that processing should
cease.</P>
<p>Examples of encoding declarations:
<eg>&lt;?XML ENCODING='UTF-8'?>
&lt;?XML ENCODING='EUC-JP'?></eg></p>
</DIV3>
 
<DIV3 type="section">
<HEAD>Document Entity</HEAD>
 
<P><termdef id="dt-docent" term="Document Entity">The <ident>document
entity</ident> serves as the root of the entity
tree and a starting-point for an <term def="dt-xml-proc">XML
processor</term>.</termdef>
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.</P>
</DIV3>
</DIV2>
 
<DIV2 type="section" id='entproc'>
<head>XML Processor Treatment of Entities</head>
 
<p>XML allows character and general-entity references in two places:
the content of elements (<ident def="NT-content">content</ident>) and
attribute values (<ident def="NT-AttValue">AttValue</ident>).
When an <term def="dt-xml-proc">XML processor</term> encounters
such a reference, or the name of an external binary entity as the value
of an <kw>ENTITY</kw> or <kw>ENTITIES</kw> attribute, then:
<list type="numbered">

<item><p>In all cases, the XML processor may 
<!--* must *-->
inform the application of the reference's occurrence and its identifier
(for an entity reference, the name; for a character
reference, 
<!--* the "<code>&amp;...;</code>" string *-->
the character number in decimal, hexadecimal, or binary form).</p></item>

<item><p>For both character and entity references, the processor must
<!--*not pass the reference itself to the application.*-->
remove the reference itself from the <term def="dt-text">text</term> data
before passing the data to the application.
</p></item>

<item><p>For character references, the processor must 
pass the character indicated
<!--* the indicated ISO/IEC 10646 bit pattern *-->
to the application in
place of the reference.
</p></item>

<item><p>For an external entity, the processor must inform the
application of the entity's <term def="dt-sysid">system
identifier</term> and <term def="dt-pubid">public identifier</term> 
if any.</p></item>

<item><p>If the external entity is binary, the processor must inform the
application of the associated <term def="dt-notation">notation</term> name,
and the notation's associated system and public (if any)
identifiers.</p></item>

<item><p><termdef id="dt-include" term="Include">For an internal
(text) entity, the processor must <ident>include</ident> the 
entity; that is, retrieve its replacement text 
and process it as a part of the document 
(i.e. as <ident def="NT-content">content</ident> or <ident
def="NT-AttValue">AttValue</ident>, whichever was being processed when
the reference was recognized), passing the result to the application
in place of the reference.  The replacement text may contain both text
and <term def="dt-markup">markup</term>, which must be recognized in
the usual way, except that the replacement text of entities used to escape
markup delimiters (the entities &magicents;) is always treated as
data.  (The string <code>AT&amp;amp;T</code> expands to
<code>AT&amp;T</code>; the remaining ampersand is not recognized
as an entity-reference delimiter.) </termdef></p>
<p>Since the entity  may contain other entity references,
an XML processor may have to repeat the inclusion process recursively.</p>
<!--*
<p>When a parameter entity is <term def="dt-include">included</term>, the XML
processor must attach a space character (#x20) to the beginning and the end
of the replacement text before processing it.</p>*-->
</item>

<item><p>If the entity is an external text entity, then in order to
<term def="dt-valid">validate</term> the XML document, the processor must
<term def="dt-include">include</term> the content of the
entity.</p></item>

<item><p>If the entity is an external text entity, and the processor is not
attempting to <term def="dt-valid">validate</term> the XML document, the
processor <term def="dt-may">may</term>, but need not, <term
def="dt-include">include</term> the entity's content.</p>
<p>This rule is based on the recognition that the automatic inclusion
provided by the SGML and XML text entity mechanism, primarily designed
to support modularity in authoring, is not necessarily 
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, *-->
<!--at load time,-->
<!--* it is compliant with this specification. *-->
</p></item>
<!--* n.b. This behavior doesn't prevent an application from
validating the document; it just affects the time when 
validation is possible. You can't validate until the
user has asked you to fetch all the parts... *-->
</list>
</p>
<p><termdef id="dt-escape" term="escape">Entity and character
references can both be used to escape the left angle bracket,
ampersand, and other delimiters.   A set of general entities
(&magicents;) is specified for this purpose.
Numeric character references may also be used; they are
expanded immediately when recognized, and must be treated as
character data, so the numeric character references
<code>&amp;#60;</code> and <code>&amp;#38;</code> may be used to 
escape <code>&lt;</code> and <code>&amp;</code> when they occur
in character data.</termdef></p>
<p>XML allows parameter-entity references in a variety of places
within the DTD. Parameter-entity references are always expanded
immediately upon being recognized, and the DTD must match the relevant
rules of the grammar after all parameter-entity references have been
expanded.  In addition, parameter entities referred to in specific
contexts are required to satisfy certain constraints in their
replacement text; for example, a parameter entity referred to within
the internal DTD subset must match the rule for <ident
def="NT-markupdecl">markupdecl</ident>.  
</p>
<p>Implementors of XML processors need to know the rules for
expansion of references in more detail.  These rules only come into
play when the replacement text for an internal entity itself contains
other references.
<list type="numbered">
<item><p>In the replacement text of an internal entity, parameter-entity
references and character references in the replacement text 
are recognized and resolved 
when the entity declaration is parsed,
<!--* , but general-entity references are not resolved, *-->
before the replacement text is stored in
the processor's symbol table.
General-entity references in the replacement text are not 
resolved when the entity declaration is parsed.</p></item>
<item><p>In the document, when a general-entity reference is
resolved, its replacement text is parsed.  Character references 
encountered in the replacement text are
resolved immediately; general-entity references encountered in the
replacement text may be resolved or left unresolved, as described 
<ref target="entproc">above</ref>.
Character and general-entity references must be
contained entirely within the entity's replacement text.  
</p></item>
</list>
<!--*
For example, if the entity <ident>amp-esc</ident> is declared 
<eg><![CDATA[<!ENTITY amp-esc "Escape an ampersand (&#38;) using a 
numeric character reference (&#38;#38;).">]]></eg>
its replacement text will be
<eg><![CDATA[Escape an ampersand (&) using a 
numeric character reference (&#38;).]]></eg>
The same effect can be achieved with a general-entity reference,
if the appropriate declaration has been given:
<eg><![CDATA[<!ENTITY amp-esc 
"Escape an ampersand (&amp;) using a 
numeric character reference (&amp;#38;)
or a general-entity reference (&amp;amp;).">]]></eg>
*-->
</p>
<!--*
<p>
Since the replacement text of a general entity is parsed once
when the general entity is declared and once when it is referred to, 
simple character references do not suffice to escape 
delimiters within the replacement text.  Instead, delimiters
must be escaped using a general-entity reference (which is not
expanded when the declaration is parsed) or a doubly-escaped
character reference.
-->
<p>Simple character references do not suffice to escape delimiters
within the replacement text of an internal entity:  they will be
expanded when the entity declaration is parsed, before the replacement
text is stored in the symbol table.  When the entity itself is
referred to, the replacement text will be parsed again, and the
delimiters (no longer character references) 
will be recognized as delimiters.  To escape the
characters &magicents; in an entity replacement text, use
a general-entity reference or a doubly-escaped character reference.
See <ref target='sec-entexpand'>the appendix on expansion 
of entity references</ref> 
for detailed examples.</p>
</div2>
<div2>
<head>Predefined Entities</head>
<p>As mentioned in the discussion of <ref target="syntax">
Character Data and Markup</ref>, the characters used as markup
delimiters by XML may all be escaped using entity references
(for the entities &magicents;).  
</p>
<p>All XML processors must recognize these entities whether they
are declared or not.  Valid XML documents must declare these
entities, like any others, before using them.</p>
<p>
If the entities in question are declared, they must be declared
as internal entities whose replacement text is the single
character being escaped, as shown below.
<eg><![CDATA[<!ENTITY lt     "&#60;"> 
<!ENTITY gt     "&#62;"> 
<!ENTITY amp    "&#38;"> 
<!ENTITY apos   "'"> 
<!ENTITY quot   '"'> 
]]></eg></p>
</div2>
 
<DIV2 type="section" id='Notations'>
<HEAD>Notation Declarations</HEAD>
 
<P>
<termdef id="dt-notation" term="Notation"><ident>Notations</ident> identify by
name the format of <term def="dt-extent">external binary
entities</term>, or the application to which  
<term def="dt-pi">processing instructions</term> are addressed.</termdef></P>
<p><termdef id="dt-notdecl" term="Notation Declaration">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.
<scrap name='Notation declarations' lang='ebnf'>
<prod><lhs id='NT-NotationDecl'>NotationDecl</lhs>
<!--*** 2608 *--><rhs>'&lt;!NOTATION' <nt def='NT-S'>S</nt> %<nt def='NT-Name'>Name</nt> 
<nt def='NT-S'>S</nt> %<nt def='NT-ExternalID'>ExternalID</nt> 
<nt def='NT-S'>S</nt>? '>'</rhs></prod>
</scrap>
</termdef></p>
<p>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
<term def="dt-sysid">system identifier</term>,
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.)</p>
</DIV2>
</div1>
<!--* &Conformance; *-->
 
<div1 type="section">
<head>Conformance </head>
 
<p>Conforming <term def="dt-xml-proc">XML processors</term> fall into two
classes: validating and non-validating.</p>
<p>Validating and non-validating systems alike must report
violations of the well-formedness constraints
given in this specification.</p>
<p><termdef id="dt-validating" term="Validating Processor">
Validating processors must report 
locations in which the document
does not comply with
the constraints expressed by the declarations in the
<term def="dt-dtd">DTD</term>.
They must also report all failures to fulfill the validity constraints given
in this specification.
</termdef>
</p>
</div1>
</BODY>
<BACK>
<!--* &SGML; *-->
 
<div1 type="section">
<head>XML and SGML</head>
 
<p>XML is designed to be a subset of SGML, in that every
<term def="dt-valid">valid</term> XML document should also be a conformant 
SGML
document, using
the same <term def="dt-dtd">DTD</term>, 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.</p>
<!--* 
<p>Despite this, there is a small number of cases where XML fails to be a
pure subset of SGML, including: <list type="bullets">
<item><p>XML's white-space handling rules are much less elaborate than those
of SGML.  One effect is that for elements using the <kw>PRESERVE</kw>
mode for white-space handling, an XML processor will pass through a
few record separators that an SGML processor will suppress.</p></item>
<item><p>XML defines, for documents, the property of being
<term def="dt-wellformed">well-formed</term>; this
does not really correspond to any SGML concept.
*-->
<!--*
While a well-formed XML document that contains the string
<eg><![CDATA[<!DOCTYPE root-element SYSTEM>]]></eg>
may, according to the letter of the SGML standard, actually be a
valid SGML document, few existing SGML systems are likely to 
be in a position to perform useful work with it.*-->
<!--* </p></item> *-->
<!--* <item><p>XML allows the same declared attribute value to appear
in more than one enumerated attribute value declaration, unlike
SGML.</p></item>
*-->
<!--* </list></p> *-->
<!--*
<p>The following list describes features which are available in SGML but not
in XML.  It may not be complete.
<list type="numbered" spacing="compact"><item><p>Tag omission</p></item>
<item><p>The <kw>CONCUR</kw>, <kw>LINK</kw>, <kw>DATATAG</kw>, 
<kw>OMITTAG</kw>, <kw>RANK</kw>, and <kw>SHORTREF</kw> features</p></item>
<item><p>The <kw>AND</kw> connector in content models</p></item>
<item><p>Inclusions and exclusions in content models</p></item>
<item><p><kw>CURRENT</kw> and <kw>CONREF</kw> 
defaults for attributes</p></item>
<item><p>Attribute types <kw>NAME</kw>, <kw>NAMES</kw>, <kw>NUMBER</kw>, 
<kw>NUMBERS</kw>, <kw>NUTOKEN</kw>, and <kw>NUTOKENS</kw>
</p></item>
<item><p>The <kw>NET</kw> construct</p></item>
<item><p>Abstract syntax</p></item>
<item><p>Capacities and quantities</p></item>
<item><p>Comments appearing within other markup declarations</p></item>
<item><p>Multiple comments in a single comment declaration</p></item>
<item><p>Public Identifiers</p></item>
<item><p>Omission of quotes on attribute values</p></item></list></p>
*-->
<p>
The following list describes syntactic characteristics which XML does not
allow but which are legal in SGML.  The list may not be complete.
</p>
<p>
<list spacing="compact">
<item>
<p>No tag omission.</p>
</item>
<item>
<p>Special tag-form for empty elements<!-- , required for elements
declared <kw>EMPTY</kw> and optional for other empty elements -->.</p>
</item>
<item>
<p>
Comment declarations must have the delimiters <code>&lt;!&como; comment text 
&comc;&gt;</code>
and can't have spaces within the markup of <code>&lt;!&como;</code> or 
<code>&comc;&gt;</code>.
</p>
</item>
<item>
<p>
No comments (<code>&como;</code> ... <code>&comc;</code>) 
inside markup declarations.
</p>
</item>
<item>
<p>
Comment declarations can't jump in and out of comments with 
<code>&como;</code> <code>&comc;</code>.
</p>
</item>
<item>
<p>
No name groups for declaring multiple elements or making 
a single <kw>ATTLIST</kw> declaration apply to multiple elements.
</p>
</item>
<item>
<p>No <kw>RANK</kw> feature.</p>
</item>
<item>
<p>
No <kw>CDATA</kw> or <kw>RCDATA</kw> declared content in element declarations.
(Use CDATA sections instead.)
</p>
</item>
<item>
<p>
No exclusions or inclusions on content models.
</p>
</item>
<item>
<p>
No minimization parameters on element declarations.
</p>
</item>
<item>
<p>
Mixed content models must be optional-repeatable <kw>OR</kw>-groups, with 
<kw>#PCDATA</kw> first.
</p>
</item>
<item>
<p>
No <kw>AND</kw> (&amp;) content model groups.
</p>
</item>
<item>
<p>
No <kw>NAME[S]</kw>, <kw>NUMBER[S]</kw>, or <kw>NUTOKEN[S]</kw> 
declared values for attributes.  (Use <kw>NMTOKEN[S]</kw> or
<kw>CDATA</kw> with application-specific validation instead.)
</p>
</item>
<item>
<p>
No <kw>#CURRENT</kw> or <kw>#CONREF</kw> declared values for attributes.
</p>
</item>
<item>
<p>
Attribute default values must be quoted.
</p>
</item>
<item>
<p>
Marked sections can't have spaces within the markup of 
<code>&lt;![<ident>keyword</ident>[</code> or 
<code>]]&gt;</code>.
</p>
</item>
<item>
<p>
No <kw>RCDATA</kw>, <kw>TEMP</kw>, <kw>IGNORE</kw>, or <kw>INCLUDE</kw> 
marked sections in document instances.
</p>
</item>
<item>
<p>
Marked sections in document instances must use the <kw>CDATA</kw> 
keyword literally, not a
parameter entity.
</p>
</item>
<item>
<p>
No <kw>CDATA</kw>, <kw>RCDATA</kw>, or <kw>TEMP</kw> 
marked sections in the DTD.
</p>
</item>
<item>
<p>Some restrictions on the content of ignored marked-sections:
comments, literals, and processing instructions in ignored sections
may not contain the delimiter string <code>]]&gt;</code>; this helps
ensure that the end-point of the conditional section does not
change when the section is changed from <kw>IGNORE</kw> to 
<kw>INCLUDE</kw>.</p>
</item>
<item>
<p>
No <kw>SDATA</kw>, <kw>CDATA</kw>, or bracketed internal entities.
</p>
</item>
<item>
<p>
No <kw>SUBDOC</kw>, <kw>CDATA</kw>, or <kw>SDATA</kw> external entities.
</p>
</item>
<item>
<p>External entities must have a system identifier.</p>
</item>
<item>
<p>Parameter-entity references in the internal DTD subset may occur
only between declarations.</p>
</item>
<item>
<p>Parameter-entity references in the external DTD subset are
restricted to certain positions in the grammar, and must replace
whole non-terminals of the grammar; this ensures that all valid XML
documents are valid SGML, and makes the restrictions on parameter-entity
replacement easier to understand and implement.
</p>
</item>
<item>
<p>
No data attributes on <kw>NOTATION</kw>s or 
attribute value specifications on <kw>ENTITY</kw>
declarations.
</p>
</item>
<item>
<p>
No <kw>SHORTREF</kw> declarations.
</p>
</item>
<item>
<p>
No <kw>USEMAP</kw> declarations.
</p>
</item>
<item>
<p>
No <kw>LINKTYPE</kw> declarations.
</p>
</item>
<item>
<p>
No <kw>LINK</kw> declarations.
</p>
</item>
<item>
<p>
No <kw>USELINK</kw> declarations.
</p>
</item>
<item>
<p>
No <kw>IDLINK</kw> declarations.
</p>
</item>
<item>
<p>
No SGML declarations.
</p>
</item>
</list>
</p>

<p>In most current SGML systems, XML documents should be able
to use the following SGML declaration. 
Some systems (those which take the document character set to
be a description of the input stream) may require different
declarations, depending on the character set and the capacities
and quantities required.
 
<eg><![CDATA[<!SGML -- SGML Declaration for XML --
    "ISO 8879:1986 (ENR)"

    CHARSET
        BASESET
            "ISO Registration Number 176//CHARSET
            ISO/IEC 10646-1:1993 UCS-2 with implementation 
            level 3//ESC 2/5 2/15 4/5"
        DESCSET
            0       9 UNUSED
            9       2 9
            11      2 UNUSED
            13      1 13
            14     18 UNUSED
            32     95 32
            127     1 UNUSED
            128    32 UNUSED
            160 65376 160
]]></eg><eg><![CDATA[    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
]]></eg><eg><![CDATA[    SCOPE DOCUMENT

    SYNTAX
        SHUNCHAR NONE
        BASESET "ISO Registration Number 176//CHARSET
                ISO/IEC 10646-1:1993 UCS-2 with implementation 
                level 3//ESC 2/5 2/15 4/5"
        DESCSET
            0 65536 0
        FUNCTION
            RE    13
            RS    10
            SPACE 32
            TAB   SEPCHAR 9
            ITAB  SEPCHAR 12288 -- ideographic space --
]]></eg><eg><![CDATA[        NAMING
            LCNMSTRT
                224-246 248-255 257 259 261 263 265 267 269 271 273
                275 277 279 281 283 285 287 289 291 293 295 297 299
                301 303 305 307 309 311 314 316 318 320 322 324 326
                328 331 333 335 337 339 341 343 345 347 349 351 353
                355 357 359 361 363 365 367 369 371 373 375 378 380
                382 383 387 389 392 396 402 409 417 419 421 424 429
                432 436 438 441 445 453 454 456 457 459 460 462 464
                466 468 470 472 474 476 479 481 483 485 487 489 491
                493 495 498 499 501 507 509 511 513 515 517 519 521
                523 525 527 529 531 533 535 595 596 598-601 603 608
                611 616 617 623 626 643 648 650 651 658 940-943
                945-961 963-974 976 977 981 982 995 997 999 1001
                1003 1005 1007-1009 1072-1103 1105-1116 1118 1119
                1121 1123 1125 1127 1129 1131 1133 1135 1137 1139
                1141 1143 1145 1147 1149 1151 1153 1169 1171 1173
                1175 1177 1179 1181 1183 1185 1187 1189 1191 1193
                1195 1197 1199 1201 1203 1205 1207 1209 1211 1213
                1215 1218 1220 1224 1228 1233 1235 1237 1239 1241
                1243 1245 1247 1249 1251 1253 1255 1257 1259 1263
                1265 1267 1269 1273 1377-1414 7681 7683 7685 7687
                7689 7691 7693 7695 7697 7699 7701 7703 7705 7707
                7709 7711 7713 7715 7717 7719 7721 7723 7725 7727
                7729 7731 7733 7735 7737 7739 7741 7743 7745 7747
                7749 7751 7753 7755 7757 7759 7761 7763 7765 7767
                7769 7771 7773 7775 7777 7779 7781 7783 7785 7787
                7789 7791 7793 7795 7797 7799 7801 7803 7805 7807
                7809 7811 7813 7815 7817 7819 7821 7823 7825 7827
                7829 7841 7843 7845 7847 7849 7851 7853 7855 7857
                7859 7861 7863 7865 7867 7869 7871 7873 7875 7877
                7879 7881 7883 7885 7887 7889 7891 7893 7895 7897
                7899 7901 7903 7905 7907 7909 7911 7913 7915 7917
                7919 7921 7923 7925 7927 7929 7936-7943 7952-7957
                7968-7975 7984-7991 8000-8005 8017 8019 8021 8023
                8032-8039 8048-8061 8064-8071 8080-8087 8096-8103
                8112 8113 8115 8131 8144 8145 8160 8161 8165 8179
                8560-8575 65345-65370
]]></eg><eg><![CDATA[            UCNMSTRT
                -- 305 and 383 should be 73 and 83 respectively, 
                but SGML does not allow a letter to be assigned 
                to UCNMSTRT --
                192-214 216-222 376 256 258 260 262 264 266 268 270
                272 274 276 278 280 282 284 286 288 290 292 294 296
                298 300 302 305 306 308 310 313 315 317 319 321 323
                325 327 330 332 334 336 338 340 342 344 346 348 350
                352 354 356 358 360 362 364 366 368 370 372 374 377
                379 381 383 386 388 391 395 401 408 416 418 420 423
                428 431 435 437 440 444 452 452 455 455 458 458 461
                463 465 467 469 471 473 475 478 480 482 484 486 488
                490 492 494 497 497 500 506 508 510 512 514 516 518
                520 522 524 526 528 530 532 534 385 390 393 394 398
                399 400 403 404 407 406 412 413 425 430 433 434 439
                902 904-906 913-929 931-939 908 910 911 914 920 934
                928 994 996 998 1000 1002 1004 1006 922 929
                1040-1071 1025-1036 1038 1039 1120 1122 1124 1126
                1128 1130 1132 1134 1136 1138 1140 1142 1144 1146
                1148 1150 1152 1168 1170 1172 1174 1176 1178 1180
                1182 1184 1186 1188 1190 1192 1194 1196 1198 1200
                1202 1204 1206 1208 1210 1212 1214 1217 1219 1223
                1227 1232 1234 1236 1238 1240 1242 1244 1246 1248
                1250 1252 1254 1256 1258 1262 1264 1266 1268 1272
                1329-1366 7680 7682 7684 7686 7688 7690 7692 7694
                7696 7698 7700 7702 7704 7706 7708 7710 7712 7714
                7716 7718 7720 7722 7724 7726 7728 7730 7732 7734
                7736 7738 7740 7742 7744 7746 7748 7750 7752 7754
                7756 7758 7760 7762 7764 7766 7768 7770 7772 7774
                7776 7778 7780 7782 7784 7786 7788 7790 7792 7794
                7796 7798 7800 7802 7804 7806 7808 7810 7812 7814
                7816 7818 7820 7822 7824 7826 7828 7840 7842 7844
                7846 7848 7850 7852 7854 7856 7858 7860 7862 7864
                7866 7868 7870 7872 7874 7876 7878 7880 7882 7884
                7886 7888 7890 7892 7894 7896 7898 7900 7902 7904
                7906 7908 7910 7912 7914 7916 7918 7920 7922 7924
                7926 7928 7944-7951 7960-7965 7976-7983 7992-7999
                8008-8013 8025 8027 8029 8031 8040-8047 8122 8123
                8136-8139 8154 8155 8184 8185 8170 8171 8186 8187
                8072-8079 8088-8095 8104-8111 8120 8121 8124 8140
                8152 8153 8168 8169 8172 8188 8544-8559 65313-65338
]]></eg><eg><![CDATA[            NAMESTRT
                58 95
                170 181 186 223 304 312 329 384 397 405 410 411 414
                415 422 426 427 442 443 446-451 477 496 592-594 597
                602 604-607 609 610 612-615 618-622 624 625 627-642
                644-647 649 652-657 659-680 688-696 699-705 736-740
                768-837 864 865 890 912 944 962 978-980 986 988 990
                992 1010 1011 1155-1158 1216 1369 1415 1425-1441
                1443-1465 1467-1469 1471 1473 1474 1476 1488-1514
                1520-1522 1569-1594 1601-1618 1648-1719 1722-1726
                1728-1742 1744-1747 1749-1768 1770-1773 2305-2307
                2309-2361 2364-2381 2385-2388 2392-2403 2433-2435
                2437-2444 2447 2448 2451-2472 2474-2480 2482
                2486-2489 2492 2494-2500 2503 2504 2507-2509 2519
                2524 2525 2527-2531 2544 2545 2562 2565-2570 2575
                2576 2579-2600 2602-2608 2610 2611 2613 2614 2616
                2617 2620 2622-2626 2631 2632 2635-2637 2649-2652
                2654 2672-2676 2689-2691 2693-2699 2701 2703-2705
                2707-2728 2730-2736 2738 2739 2741-2745 2748-2757
                2759-2761 2763-2765 2784 2817-2819 2821-2828 2831
                2832 2835-2856 2858-2864 2866 2867 2870-2873
                2876-2883 2887 2888 2891-2893 2902 2903 2908 2909
                2911-2913 2946 2947 2949-2954 2958-2960 2962-2965
                2969 2970 2972 2974 2975 2979 2980 2984-2986
                2990-2997 2999-3001 3006-3010 3014-3016 3018-3021
                3031 3073-3075 3077-3084 3086-3088 3090-3112
                3114-3123 3125-3129 3134-3140 3142-3144 3146-3149
                3157 3158 3168 3169 3202 3203 3205-3212 3214-3216
                3218-3240 3242-3251 3253-3257 3262-3268 3270-3272
                3274-3277 3285 3286 3294 3296 3297 3330 3331
                3333-3340 3342-3344 3346-3368 3370-3385 3390-3395
                3398-3400 3402-3405 3415 3424 3425 3585-3630
                3632-3642 3648-3653 3655-3662 3713 3714 3716 3719
                3720 3722 3725 3732-3735 3737-3743 3745-3747 3749
                3751 3754 3755 3757 3758 3760-3769 3771-3773
                3776-3780 3784-3789 3804 3805 3864 3865 3893 3895
                3897 3902-3911 3913-3945 3953-3972 3974-3979
                3984-3989 3991 3993-4013 4017-4023 4025 4256-4293
                4304-4342 4352-4441 4447-4514 4520-4601 7830-7835
                8016 8018 8020 8022 8114 8116 8118 8119 8126 8130
                8132 8134 8135 8146 8147 8150 8151 8162-8164 8166
                8167 8178 8180 8182 8183 8319 8400-8412 8417 8450
                8455 8458-8467 8469 8472-8477 8484 8486 8488
                8490-8497 8499-8504 8576-8578 12295 12321-12335
                12353-12436 12441 12442 12449-12538 12549-12588
                12593-12686 19968-40869 44032-55203 63744-64045
                64256-64262 64275-64279 64286-64296 64298-64310
                64312-64316 64318 64320 64321 64323 64324
                64326-64433 64467-64829 64848-64911 64914-64967
                65008-65019 65056-65059 65136-65138 65140
                65142-65276 65382-65391 65393-65437 65440-65470
                65474-65479 65482-65487 65490-65495 65498-65500
]]></eg><eg><![CDATA[            LCNMCHAR "-."
            UCNMCHAR "-."
]]></eg><eg><![CDATA[            NAMECHAR
                183 720 721 1600 1632-1641 1776-1785 2406-2415
                2534-2543 2662-2671 2790-2799 2918-2927 3047-3055
                3174-3183 3302-3311 3430-3439 3654 3664-3673 3782
                3792-3801 3872-3881 8204-8207 8234-8238 8298-8303
                12293 12337-12341 12443-12446 12540-12542 65279
                65296-65305 65392 65438 65439
            NAMECASE
                GENERAL YES
                ENTITY  NO
]]></eg><eg><![CDATA[        DELIM
            GENERAL SGMLREF
            NET "/>"
            PIC "?>"
            SHORTREF NONE
        NAMES
            SGMLREF
]]></eg><eg><![CDATA[        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
            -- no need to change NORMSEP --
            PILEN       99999999
            TAGLEN      99999999
            TAGLVL      99999999
]]></eg><eg><![CDATA[    FEATURES
        MINIMIZE
            DATATAG NO
            OMITTAG NO
            RANK NO
            SHORTTAG YES -- SHORTTAG is needed for NET --
        LINK
            SIMPLE NO
            IMPLICIT NO
            EXPLICIT NO
        OTHER
            CONCUR NO
            SUBDOC NO
            FORMAL NO
    APPINFO NONE
>
]]></eg>
</p>
</div1>
<!--* &Biblio; *-->
<div1 id='CharClasses'>
<head>Character Classes</head>
<p>Following the characteristics defined in the Unicode standard,
characters are classed as base characters (among others, these
contain the alphabetic characters of the Latin alphabet, without
diacritics), ideographic characters, combining characters (among
others, this class contains most diacritics); these classes combine
to form the class of letters.  Digits, extenders, and characters
which should be ignored for purposes of recognizing identifiers are
also distinguished.
<SCRAP LANG="EBNF" ID="CHARACTERS" NAME="Characters" REND="HEAVY">
<PROD> 
<LHS ID="NT-Basechar">BaseChar</LHS> 
<RHS>[#x41-#x5A] |&nbsp;[#x61-#x7A]</RHS> 
<COM>Latin 1 upper and lowercase </COM>
<RHS>|&nbsp;#xAA |&nbsp;#xB5 |&nbsp;#xBA |&nbsp;[#xC0-#xD6]
|&nbsp;[#xD8-#xF6]
|&nbsp;[#xF8-#xFF]</RHS> 
<COM>Latin 1 supplementary </COM>
<RHS>|&nbsp;[#x0100-#x017F]
|&nbsp;[#x0180-#x01F5] |&nbsp;[#x01FA-#x0217]</RHS> 
<COM>Extended Latin-A and B</COM>
<RHS>|&nbsp;[#x0250-#x02A8]</RHS> 
<COM>IPA Extensions</COM> 
<RHS>|&nbsp;[#x02B0-#x02B8] |&nbsp;[#x02BB-#x02C1]
|&nbsp;[#x02E0-#x02E4]</RHS> 
<COM>Spacing Modifiers</COM>
<RHS>|&nbsp;#x037A |&nbsp;#x0386 |&nbsp;[#x0388-#x038A] |&nbsp;#x038C
|&nbsp;[#x038E-#x03A1] |&nbsp;[#x03A3-#x03CE] |&nbsp;[#x03D0-#x03D6]
|&nbsp;#x03DA |&nbsp;#x03DC |&nbsp;#x03DE |&nbsp;#x03E0
|&nbsp;[#x03E2-#x03F3]</RHS> 
<COM>Greek and Coptic</COM>
<RHS>|&nbsp;[#x0401-#x040C] |&nbsp;[#x040E-#x044F] |&nbsp;[#x0451-#x045C]
|&nbsp;[#x045E-#x0481] |&nbsp;[#x0490-#x04C4] |&nbsp;[#x04C7-#x04C8]
|&nbsp;[#x04CB-#x04CC] |&nbsp;[#x04D0-#x04EB] |&nbsp;[#x04EE-#x04F5]
|&nbsp;[#x04F8-#x04F9]</RHS> 
<COM>Cyrillic</COM>
<RHS>|&nbsp;[#x0531-#x0556] |&nbsp;#x0559
|&nbsp;[#x0561-#x0587]</RHS> 
<COM>Armenian</COM>
<RHS>|&nbsp;[#x05D0-#x05EA] |&nbsp;[#x05F0-#x05F2]</RHS> 
<COM>Hebrew</COM>
<RHS>|&nbsp;[#x0621-#x063A] |&nbsp;[#x0641-#x064A] |&nbsp;[#x0671-#x06B7]
|&nbsp;[#x06BA-#x06BE] |&nbsp;[#x06C0-#x06CE] |&nbsp;[#x06D0-#x06D3]
|&nbsp;#x06D5 |&nbsp;[#x06E5-#x06E6]</RHS> 
<COM>Arabic</COM>
<RHS>|&nbsp;[#x0905-#x0939] |&nbsp;#x093D |&nbsp;[#x0958-#x0961]</RHS>
<COM>Devanagari</COM> 
<RHS>|&nbsp;[#x0985-#x098C] |&nbsp;[#x098F-#x0990]
|&nbsp;[#x0993-#x09A8] |&nbsp;[#x09AA-#x09B0] |&nbsp;#x09B2
|&nbsp;[#x09B6-#x09B9] |&nbsp;[#x09DC-#x09DD] |&nbsp;[#x09DF-#x09E1]
|&nbsp;[#x09F0-#x09F1]</RHS> 
<COM>Bengali</COM>
<RHS>|&nbsp;[#x0A05-#x0A0A] |&nbsp;[#x0A0F-#x0A10] |&nbsp;[#x0A13-#x0A28]
|&nbsp;[#x0A2A-#x0A30] |&nbsp;[#x0A32-#x0A33] |&nbsp;[#x0A35-#x0A36]
|&nbsp;[#x0A38-#x0A39]
|&nbsp;[#x0A59-#x0A5C]
|&nbsp;#x0A5E
|&nbsp;[#x0A72-#x0A74]
|&nbsp;[#x0A85-#x0A8B]
|&nbsp;#x0A8D
</RHS> 
<COM>Gurmukhi</COM>
<RHS>|&nbsp;[#x0A8F-#x0A91] |&nbsp;[#x0A93-#x0AA8] |&nbsp;[#x0AAA-#x0AB0]
|&nbsp;[#x0AB2-#x0AB3] |&nbsp;[#x0AB5-#x0AB9] |&nbsp;#x0ABD
|&nbsp;#x0AE0
</RHS>
<COM>Gujarati</COM> 
<RHS>|&nbsp;[#x0B05-#x0B0C] |&nbsp;[#x0B0F-#x0B10] |&nbsp;[#x0B13-#x0B28]
|&nbsp;[#x0B2A-#x0B30] |&nbsp;[#x0B32-#x0B33] |&nbsp;[#x0B36-#x0B39]
|&nbsp;#x0B3D |&nbsp;[#x0B5C-#x0B5D] |&nbsp;[#x0B5F-#x0B61]</RHS>
<COM>Oriya</COM> 
<RHS>|&nbsp;[#x0B85-#x0B8A] |&nbsp;[#x0B8E-#x0B90] |&nbsp;[#x0B92-#x0B95]
|&nbsp;[#x0B99-#x0B9A] |&nbsp;#x0B9C |&nbsp;[#x0B9E-#x0B9F]
|&nbsp;[#x0BA3-#x0BA4] |&nbsp;[#x0BA8-#x0BAA] |&nbsp;[#x0BAE-#x0BB5]
|&nbsp;[#x0BB7-#x0BB9]</RHS>
<COM>Tamil</COM> 
<RHS>|&nbsp;[#x0C05-#x0C0C] |&nbsp;[#x0C0E-#x0C10] |&nbsp;[#x0C12-#x0C28]
|&nbsp;[#x0C2A-#x0C33] |&nbsp;[#x0C35-#x0C39] |&nbsp;[#x0C60-#x0C61]</RHS>
<COM>Telugu</COM> 
<RHS>|&nbsp;[#x0C85-#x0C8C] |&nbsp;[#x0C8E-#x0C90] |&nbsp;[#x0C92-#x0CA8]
|&nbsp;[#x0CAA-#x0CB3] |&nbsp;[#x0CB5-#x0CB9] |&nbsp;#x0CDE
|&nbsp;[#x0CE0-#x0CE1]</RHS>
<COM>Kannada</COM> 
<RHS>|&nbsp;[#x0D05-#x0D0C] |&nbsp;[#x0D0E-#x0D10] |&nbsp;[#x0D12-#x0D28]
|&nbsp;[#x0D2A-#x0D39] |&nbsp;[#x0D60-#x0D61]</RHS>
<COM>Malayalam</COM> 
<RHS>|&nbsp;[#x0E01-#x0E2E] |&nbsp;#x0E30 |&nbsp;[#x0E32-#x0E33]
|&nbsp;[#x0E40-#x0E45]</RHS> 
<COM>Thai</COM>
<RHS>|&nbsp;[#x0E81-#x0E82] |&nbsp;#x0E84 |&nbsp;[#x0E87-#x0E88] |&nbsp;#x0E8A
|&nbsp;#x0E8D |&nbsp;[#x0E94-#x0E97] |&nbsp;[#x0E99-#x0E9F]
|&nbsp;[#x0EA1-#x0EA3] |&nbsp;#x0EA5 |&nbsp;#x0EA7 |&nbsp;[#x0EAA-#x0EAB]
|&nbsp;[#x0EAD-#x0EAE] |&nbsp;#x0EB0 |&nbsp;[#x0EB2-#x0EB3] |&nbsp;#x0EBD
|&nbsp;[#x0EC0-#x0EC4] |&nbsp;[#x0EDC-#x0EDD]</RHS> 
<COM>Lao</COM>
<RHS>|&nbsp;[#x0F40-#x0F47] |&nbsp;[#x0F49-#x0F69]</RHS>
<COM>Tibetan</COM> 
<RHS>|&nbsp;[#x10A0-#x10C5] |&nbsp;[#x10D0-#x10F6]</RHS>
<COM>Georgian</COM>
<RHS>|&nbsp;[#x1100-#x1159] |&nbsp;[#x115F-#x11A2]
|&nbsp;[#x11A8-#x11F9]</RHS> 
<COM>Hangul Jamo</COM>
<RHS>|&nbsp;[#x1E00-#x1E9B] |&nbsp;[#x1EA0-#x1EF9]</RHS> 
<COM>Add'l Extended Latin</COM> 
<RHS>|&nbsp;[#x1F00-#x1F15] |&nbsp;[#x1F18-#x1F1D] |&nbsp;[#x1F20-#x1F45]
|&nbsp;[#x1F48-#x1F4D] |&nbsp;[#x1F50-#x1F57] |&nbsp;#x1F59 |&nbsp;#x1F5B
|&nbsp;#x1F5D |&nbsp;[#x1F5F-#x1F7D] |&nbsp;[#x1F80-#x1FB4]
|&nbsp;[#x1FB6-#x1FBC] |&nbsp;#x1FBE |&nbsp;[#x1FC2-#x1FC4]
|&nbsp;[#x1FC6-#x1FCC] |&nbsp;[#x1FD0-#x1FD3] |&nbsp;[#x1FD6-#x1FDB]
|&nbsp;[#x1FE0-#x1FEC] |&nbsp;[#x1FF2-#x1FF4] |&nbsp;[#x1FF6-#x1FFC]</RHS>
<COM>Greek Extensions</COM>
<RHS>|&nbsp;#x207F</RHS> 
<COM>Super-, subscripts</COM> 
<RHS>|&nbsp;#x2102 |&nbsp;#x2107 |&nbsp;[#x210A-#x2113] |&nbsp;#x2115
|&nbsp;[#x2118-#x211D] |&nbsp;#x2124 |&nbsp;#x2126 |&nbsp;#x2128
|&nbsp;[#x212A-#x2131]
|&nbsp;[#x2133-#x2138]</RHS> 
<COM>Letterlike Symbols</COM> 
<RHS>|&nbsp;[#x2160-#x2182]</RHS>
<COM>Number forms</COM>
<RHS>|&nbsp;[#x3041-#x3094]</RHS> <COM>Hiragana</COM>
<RHS>|&nbsp;[#x30A1-#x30FA]</RHS> <COM>Katakana</COM>
<RHS>|&nbsp;[#x3105-#x312C]</RHS> <COM>Bopomofo</COM>
<RHS>|&nbsp;[#x3131-#x318E]</RHS> <COM>Hangul Jamo</COM>
<RHS>|&nbsp;[#xAC00-#xD7A3]</RHS> <COM>Hangul syllables</COM> 
<RHS>|&nbsp;[#xFB00-#xFB06] |&nbsp;[#xFB13-#xFB17]
|&nbsp;[#xFB1F-#xFB28] |&nbsp;[#xFB2A-#xFB36] |&nbsp;[#xFB38-#xFB3C]
|&nbsp;#xFB3E |&nbsp;[#xFB40-#xFB41] |&nbsp;[#xFB43-#xFB44]
|&nbsp;[#xFB46-#xFB4F]</RHS> 
<COM>Alphabetic presentation forms</COM> 
<RHS>|&nbsp;[#xFB50-#xFBB1] |&nbsp;[#xFBD3-#xFD3D]
|&nbsp;[#xFD50-#xFD8F] |&nbsp;[#xFD92-#xFDC7] |&nbsp;[#xFDF0-#xFDFB]
|&nbsp;[#xFE70-#xFE72] |&nbsp;#xFE74 |&nbsp;[#xFE76-#xFEFC]</RHS>
<COM>Arabic presentation forms</COM>
<RHS>|&nbsp;[#xFF21-#xFF3A] |&nbsp;[#xFF41-#xFF5A] |&nbsp;[#xFF66-#xFF6F]
|&nbsp;[#xFE71-#xFF9D] |&nbsp;[#xFFA0-#xFFBE] |&nbsp;[#xFFC2-#xFFC7]
|&nbsp;[#xFFCA-#xFFCF] |&nbsp;[#xFFD2-#xFFD7] |&nbsp;[#xFFDA-#xFFDC]</RHS>
<COM>Half- and fullwidth forms</COM> </PROD>
<PROD> 
<LHS ID="NT-Ideographic">Ideographic</LHS> 
<RHS>[#x4E00-#x9FA5] |&nbsp;[#xF900-#xFA2D] |&nbsp;#x3007
|&nbsp;[#x3021-#x3029]</RHS> </PROD>
<PROD> 
<LHS ID="NT-Combiningchar">CombiningChar</LHS>
<RHS>[#x0300-#x0345] |&nbsp;[#x0360-#x0361] 
|&nbsp;[#x0483-#x0486] 
|&nbsp;[#x0591-#x05A1]
|&nbsp;[#x05A3-#x05B9]
|&nbsp;[#x05BB-#x05BD]
|&nbsp;#x05BF
|&nbsp;[#x05C1-#x05C2]
|&nbsp;#x05C4
|&nbsp;[#x064B-#x0652] |&nbsp;#x0670 |&nbsp;[#x06D6-#x06DC]
|&nbsp;[#x06DD-#x06DF] |&nbsp;[#x06E0-#x06E4] |&nbsp;[#x06E7-#x06E8]
|&nbsp;[#x06EA-#x06ED] |&nbsp;[#x0901-#x0903] 
|&nbsp;#x093C
|&nbsp;[#x093E-#x094C]
|&nbsp;#x094D |&nbsp;[#x0951-#x0954] |&nbsp;[#x0962-#x0963]
|&nbsp;[#x0981-#x0983] |&nbsp;#x09BC |&nbsp;#x09BE |&nbsp;#x09BF
|&nbsp;[#x09C0-#x09C4] |&nbsp;[#x09C7-#x09C8] |&nbsp;[#x09CB-#x09CD]
|&nbsp;#x09D7 |&nbsp;[#x09E2-#x09E3] |&nbsp;#x0A02 |&nbsp;#x0A3C
|&nbsp;#x0A3E |&nbsp;#x0A3F |&nbsp;[#x0A40-#x0A42]
|&nbsp;[#x0A47-#x0A48] |&nbsp;[#x0A4B-#x0A4D] |&nbsp;[#x0A70-#x0A71]
|&nbsp;[#x0A81-#x0A83] |&nbsp;#x0ABC |&nbsp;[#x0ABE-#x0AC5]
|&nbsp;[#x0AC7-#x0AC9] |&nbsp;[#x0ACB-#x0ACD]
|&nbsp;[#x0B01-#x0B03] |&nbsp;#x0B3C |&nbsp;[#x0B3E-#x0B43]
|&nbsp;[#x0B47-#x0B48] |&nbsp;[#x0B4B-#x0B4D] |&nbsp;[#x0B56-#x0B57]
|&nbsp;[#x0B82-#x0B83] |&nbsp;[#x0BBE-#x0BC2] |&nbsp;[#x0BC6-#x0BC8]
|&nbsp;[#x0BCA-#x0BCD] |&nbsp;#x0BD7 |&nbsp;[#x0C01-#x0C03]
|&nbsp;[#x0C3E-#x0C44] |&nbsp;[#x0C46-#x0C48] |&nbsp;[#x0C4A-#x0C4D]
|&nbsp;[#x0C55-#x0C56] |&nbsp;[#x0C82-#x0C83] |&nbsp;[#x0CBE-#x0CC4]
|&nbsp;[#x0CC6-#x0CC8] |&nbsp;[#x0CCA-#x0CCD] |&nbsp;[#x0CD5-#x0CD6]
|&nbsp;[#x0D02-#x0D03] |&nbsp;[#x0D3E-#x0D43] |&nbsp;[#x0D46-#x0D48]
|&nbsp;[#x0D4A-#x0D4D] |&nbsp;#x0D57 |&nbsp;#x0E31
|&nbsp;[#x0E34-#x0E3A] |&nbsp;[#x0E47-#x0E4E] |&nbsp;#x0EB1
|&nbsp;[#x0EB4-#x0EB9] |&nbsp;[#x0EBB-#x0EBC] |&nbsp;[#x0EC8-#x0ECD]
|&nbsp;[#x0F18-#x0F19] |&nbsp;#x0F35 |&nbsp;#x0F37 |&nbsp;#x0F39
|&nbsp;#x0F3E |&nbsp;#x0F3F |&nbsp;[#x0F71-#x0F84]
|&nbsp;[#x0F86-#x0F8B] |&nbsp;[#x0F90-#x0F95] |&nbsp;#x0F97
|&nbsp;[#x0F99-#x0FAD] |&nbsp;[#x0FB1-#x0FB7] |&nbsp;#x0FB9
|&nbsp;[#x20D0-#x20DC]   |&nbsp;#x20E1 |&nbsp;[#x302A-#x302F]
|&nbsp;#x3099 |&nbsp;#x309A |&nbsp;#xFB1E |&nbsp;[#xFE20-#xFE23]</RHS>
</PROD>
<PROD> 
<LHS ID="NT-Letter">Letter</LHS>
<RHS><NT DEF="NT-Basechar">BaseChar</NT> 
<!--* <NT DEF="NT-Combiningchar">CombiningChar</NT>*) *--> 
|&nbsp;<NT DEF="NT-Ideographic">Ideographic</NT></RHS> </PROD>
<PROD> 
<LHS ID="NT-Digit">Digit</LHS> 
<RHS>[#x30-#x39]</RHS> <COM>ISO 646 digits </COM> 
<RHS>|&nbsp;[#x0660-#x0669]</RHS> <COM>Arabic-Indic digits</COM> 
<RHS>|&nbsp;[#x06F0-#x06F9]</RHS> <COM>Eastern Arabic-Indic digits </COM>
<RHS>|&nbsp;[#x0966-#x096F]</RHS> <COM>Devanagari digits</COM> 
<RHS>|&nbsp;[#x09E6-#x09EF]</RHS> <COM>Bengali digits </COM>
<RHS>|&nbsp;[#x0A66-#x0A6F]</RHS> <COM>Gurmukhi digits </COM>
<RHS>|&nbsp;[#x0AE6-#x0AEF]</RHS> <COM>Gujarati digits </COM>
<RHS>|&nbsp;[#x0B66-#x0B6F]</RHS> <COM>Oriya digits </COM>
<RHS>|&nbsp;[#x0BE7-#x0BEF]</RHS> <COM>Tamil digits (no zero) </COM>
<RHS>|&nbsp;[#x0C66-#x0C6F]</RHS> <COM>Telugu digits </COM>
<RHS>|&nbsp;[#x0CE6-#x0CEF]</RHS> <COM>Kannada digits </COM>
<RHS>|&nbsp;[#x0D66-#x0D6F]</RHS> <COM>Malayalam digits </COM>
<RHS>|&nbsp;[#x0E50-#x0E59]</RHS> <COM>Thai digits </COM>
<RHS>|&nbsp;[#x0ED0-#x0ED9]</RHS> <COM>Lao digits </COM>
<RHS>|&nbsp;[#x0F20-#x0F29]</RHS> <COM>Tibetan digits </COM>
<RHS>|&nbsp;[#xFF10-#xFF19]</RHS> <COM>Fullwidth digits</COM> </PROD>
<PROD> 
<LHS ID="NT-Ignorable">Ignorable</LHS>
<RHS>[#x200C-#x200F]</RHS> <COM>zw layout</COM>
<RHS>|&nbsp;[#x202A-#x202E]</RHS> <COM>bidi formatting</COM>
<RHS>|&nbsp;[#x206A-#x206F]</RHS> <COM>alt formatting</COM>
<RHS>|&nbsp;#xFEFF</RHS> <COM>zw nonbreak space</COM> </PROD>
<PROD>
<LHS ID="NT-Extender">Extender</LHS> 
<RHS>#xB7 |&nbsp;#x02D0 |&nbsp;#x02D1 |&nbsp;#x0387 |&nbsp;#x0640
|&nbsp;#x0E46 |&nbsp;#x0EC6 |&nbsp;#x3005 |&nbsp;[#x3031-#x3035]
|&nbsp;[#x309B-#x309E] |&nbsp;[#x30FC-#x30FE] |&nbsp;#xFF70
|&nbsp;#xFF9E |&nbsp;#xFF9F</RHS>
</PROD></SCRAP></P>
</div1>
<div1 id='sec-entexpand'>
<head>Expansion of Entity and Character References</head>
<p>This appendix contains some examples illustrating the
sequence of entity- and character-reference recognition and
expansion.</p>
<p>
If the DTD contains the declaration 
<eg><![CDATA[<!ENTITY example "<p>An ampersand (&#38;#38;) may be escaped
numerically (&#38;#38;#38;) or with a general entity
(&amp;amp;).</p>" >
]]></eg>
then the XML processor will recognize the character references 
when it parses the entity declaration, and resolve them before 
storing the following string as the
value of the entity <ident>example</ident>:
<eg><![CDATA[<p>An ampersand (&#38;) may be escaped
numerically (&#38;#38;) or with a general entity
(&amp;amp;).</p>
]]></eg>
A reference in the document to <code>&amp;example;</code> 
will cause the text to be reparsed, at which time the 
start- and end-tags of the <ident>p</ident> element will be recognized 
and the three references will be recognized and expanded, 
resulting in a <ident>p</ident> element with the following content
(all data, no delimiters or markup):
<eg><![CDATA[An ampersand (&) may be escaped
numerically (&#38;) or with a general entity
(&amp;).
]]></eg>
</p>
<p>A more complex example will illustrate the rules and their
effects fully.  In the following example, the line numbers are
solely for reference.
<eg><![CDATA[1 <?XML version='1.0'?>
2 <!DOCTYPE test [
3 <!ELEMENT test (#PCDATA) >
4 <!ENTITY % xx '&#37;zz;'>
5 <!ENTITY % zz '&#60;!ENTITY tricky "error-prone" >' >
6 %xx;
7 ]>
8 <test>This sample shows a &tricky; method.</test>
]]></eg>
This produces the following
<!--* perhaps unexpected results: *-->
<list>
<item><p>in line 4, the reference to character 37 is expanded immediately,
and the parameter entity <ident>xx</ident> is stored in the symbol
table with the value <code>%zz;</code>.  Since the replacement text
is not rescanned, the reference to parameter entity <ident>zz</ident>
is not recognized.  (And it would be an error if it were, since
<ident>zz</ident> is not yet declared.)</p></item>
<item><p>in line 5, the character reference <code>&amp;#60;</code> is
expanded immediately and the parameter entity <ident>zz</ident> is
stored with the replacement text 
<code>&lt;!ENTITY tricky "error-prone" ></code>,
which is a well-formed entity declaration.</p></item>
<item><p>in line 6, the reference to <ident>xx</ident> is recognized,
and the replacement text of <ident>xx</ident> (namely 
<code>%zz;</code>) is parsed.  The reference to <ident>zz</ident>
is recognized in its turn, and its replacement text 
(<code>&lt;!ENTITY tricky "error-prone" ></code>) is parsed.
The general entity <ident>tricky</ident> has now been
declared, with the replacement text <code>error-prone</code>.</p></item>
<item><p>
in line 8, the reference to the general entity <ident>tricky</ident> is
recognized, and it is expanded, so the full content of the
<ident>test</ident> element is the self-describing (and ungrammatical) string
<mentioned>This sample shows a error-prone method.</mentioned>
</p></item>
</list>
</p>
</div1> 
<div1 type="section" id="determinism">
<head>Deterministic Content Models</head>
<p><term def='dt-compat'>For compatibility</term>, 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.</p>
<p>For example, the content model <code>((b, c) | (b, d))</code> is
non-deterministic, because given an initial <ident>b</ident> the parser
cannot know which <ident>b</ident> in the model is being matched without
looking ahead to see which element follows the <ident>b</ident>.
In this case, the two references to
<ident>b</ident> can be collapsed 
into a single reference, making the model read
<code>(b, (c | d))</code>.  An initial <ident>b</ident> now clearly
matches only a single name in the content model.  The parser doesn't
need to look ahead to see what follows; either <ident>c</ident> or
<ident>d</ident> would be accepted.</p>
<p>Algorithms exist which allow many but not all non-deterministic
content models to be reduced automatically to equivalent deterministic
models; see <ref target='ABK'>Brüggemann-Klein 1991</ref>.</p>
</div1>
<div1 id='sec-guessing'>
<head>Autodetection of Character Encodings</head>
<p>The XML encoding declaration functions as an internal label on each
entity, indicating which character encoding is in use.  Before an XML
processor can read the internal label, however, it apparently has to
know what character encoding is in use&mdash;which is what the internal label
is trying to indicate.  In the general case, this is a hopeless
situation. It is not entirely hopeless in XML, however, because XML
limits the general case in two ways:  each implementation is assumed
to support only a  finite set of character encodings, and the XML
encoding declaration is restricted in position and content in order to
make it feasible to autodetect the character encoding in use in each
entity in normal cases.
</p>
<p>
Because each XML entity not in UTF-8 or UCS-2 format <emph>must</emph>
begin with an XML encoding declaration, in which the first  characters
must be '<code>&lt;?XML</code>', any conforming processor can detect,
after two to four octets of input, which of the following cases apply (in
reading this list, it may help to know that in UCS-4, '&lt;' is
<code>#x0000003C</code> and '?' is <code>#x0000003F</code>, and the Byte
Order Mark required of UCS-2 data streams is <code>#xFEFF</code>):
</p>
<p><list>
<item>
<p><code>00 00 00 3C</code>: UCS-4, big-endian machine (1234 order)</p>
</item>
<item>
<p><code>3C 00 00 00</code>: UCS-4, little-endian machine (4321 order)</p>
</item>
<item>
<p><code>00 00 3C 00</code>: UCS-4, unusual octet order (2143)</p>
</item>
<item>
<p><code>00 3C 00 00</code>: UCS-4, unusual octet order (3412)</p>
</item>
<item>
<p><code>FE FF</code>: UCS-2, big-endian</p>
</item>
<item>
<p><code>FF FE</code>: UCS-2, little-endian</p>
</item>
<item>
<p><code>00 3C 00 3F</code>: UCS-2, big-endian, no Byte Order Mark
(and thus, strictly speaking, in error)</p>
</item>
<item>
<p><code>3C 00 3F 00</code>: UCS-2, little-endian, no Byte Order Mark
(and thus, strictly speaking, in error)</p>
</item>
<item>
<p><code>3C 3F 58 4D</code>: UTF-8, ISO 646, ASCII, some part of ISO 8859, 
Shift-JIS, EUC, or any other 7-bit, 8-bit, or mixed-width encoding
which ensures that the characters of ASCII have their normal positions,
width,
and values; the actual encoding declaration must be read to 
detect which of these applies, but since all of these encodings
use the same bit patterns for the ASCII characters, the encoding 
declaration itself may be read reliably
</p>
</item>
<item>
<p><code>4C 6F E7 D4</code>: EBCDIC (in some flavor; the full
encoding declaration must be read to tell which code page is in 
use)</p>
</item>
<item>
<p>other:  UTF-8 without an encoding declaration, or else 
the data are corrupt, fragmentary, or enclosed in
a wrapper of some kind</p>
</item>
</list>
</p>
<p>
This level of autodetection is enough to read the XML encoding
declaration and parse the character-encoding identifier, which is
still necessary to distinguish the individual members of each family
of encodings (e.g. to tell  UTF-8 from 8859, and the parts of 8859
from each other, or to distinguish the  specific EBCDIC code page in
use, and so on).
</p>
<p>
Because the contents of the encoding declaration are restricted to
ASCII characters, a processor can reliably read the entire encoding
declaration as soon as it has detected which family of encodings is in
use.  Since in practice, all widely used character encodings fall into
one of the categories above, the XML encoding declaration allows
reasonably reliable in-line labeling of character encodings, even when
external sources of information at the operating-system or
transport-protocol level are unreliable.
</p>
<p>
Once the processor has detected the character encoding in use, it can
act appropriately, whether by invoking a separate input routine for
each case, or by calling the proper conversion function on each
character of input. 
</p>
<p>
Like any self-labeling system, the XML encoding declaration will
not work if any software changes the entity's character set or encoding 
without updating the encoding declaration.  Implementors of 
character-encoding routines should be careful to ensure the accuracy
of the internal and external information used to label the
entity.
</p>
</div1>
<div1>
<head>A Trivial Grammar for XML Documents</head>
<p>The grammar given in the body of this specification is relatively
simple, but for some purposes it is convenient to have an even simpler
one.  
A very simple, though non-conforming, <term def="dt-xml-proc">XML
processor</term> could parse a <term
def="dt-wellformed">well-formed</term> XML document using the
following simplified grammar, recognizing all element boundaries
correctly, though not expanding entity references and not detecting
all <!--reportable--> errors:

<scrap lang="ebnf" name='Trivial text grammar'>
<prod><lhs id='NT-simpleDoc'>simpleDoc</lhs>
<rhs>(<nt def='NT-SimpleData'>SimpleData</nt> 
| <nt def='NT-Markup'>Markup</nt>)*</rhs></prod>
<prod>
<lhs id="NT-SimpleData">SimpleData</lhs>
<rhs>[^&lt;&amp;]*</rhs>
<com>cf. PCData</com>
</prod>
<prod>
<lhs id="NT-SimpleLit">SimpleLit</lhs>
<rhs>('"' [^"]* '"')</rhs>
<rhs>|&nbsp;("'" [^']* "'")</rhs>
<com>cf. SkipLit</com>
</prod>
<prod><lhs id='NT-Markup'>Markup</lhs>
<rhs>'&lt;' <nt def='NT-Name'>Name</nt> 
(<nt def='NT-S'>S</nt> 
<nt def='NT-Name'>Name</nt> 
<nt def='NT-S'>S</nt>? '=' <nt def='NT-S'>S</nt>?
<nt def='NT-SimpleLit'>SimpleLit</nt>)* 
<nt def='NT-S'>S</nt>? '&gt;'</rhs><com>start-tags </com>
<rhs>| '&lt;' <nt def='NT-Name'>Name</nt> 
(<nt def='NT-S'>S</nt> 
<nt def='NT-Name'>Name</nt> 
<nt def='NT-S'>S</nt>? '=' <nt def='NT-S'>S</nt>?
<nt def='NT-SimpleLit'>SimpleLit</nt>)* 
<nt def='NT-S'>S</nt>? '/&gt;'</rhs><com>empty elements</com>
<rhs>| '&lt;/' 
<nt def='NT-Name'>Name</nt> 
<nt def='NT-S'>S</nt>? '&gt;'</rhs>
<com>end-tags </com>
<rhs>| '&amp;' <nt def='NT-Name'>Name</nt> ';'</rhs>
<com>entity references </com>
<rhs>| '&amp;#' [0-9]+ ';'</rhs>
<com>decimal character references </com>
<rhs>| '&hcro;' [0-9a-fA-F]+ ';'</rhs>
<com>hexadecimal character references </com>
<rhs>| '&lt;!&como;' 
(<nt def='NT-Char'>Char</nt>* - 
(<nt def='NT-Char'>Char</nt>* '&comc;' <nt def='NT-Char'>Char</nt>*))
'&comc;&gt;'</rhs>
<com>comments </com>
<rhs>| '&lt;?'
(<nt def='NT-Char'>Char</nt>* - 
(<nt def='NT-Char'>Char</nt>* &pic; <nt def='NT-Char'>Char</nt>*))
'&pic;'</rhs>
<com>processing instructions </com>
<rhs>| '&lt;![CDATA[' 
(<nt def='NT-Char'>Char</nt>* - 
(<nt def='NT-Char'>Char</nt>* ']]&gt;' <nt def='NT-Char'>Char</nt>*))
']]&gt;'</rhs>
<com>CDATA sections</com>
<rhs>| '&lt;!DOCTYPE' 
(<nt def="NT-Char">Char</nt> - ('[' | ']'))+
('[' 
<nt def="NT-simpleDTD">simpleDTD</nt>*
']')? '&gt;'</rhs>
<com>doc type declaration</com>
</prod>
<prod>
<lhs id="NT-simpleDTD">simpleDTD</lhs>
<rhs>'&lt;!&como;' 
(<nt def='NT-Char'>Char</nt>* - 
(<nt def='NT-Char'>Char</nt>* '&comc;' <nt def='NT-Char'>Char</nt>*))
'&comc;&gt;'</rhs>
<com>comment </com>
<rhs>| '&lt;?'
(<nt def='NT-Char'>Char</nt>* - 
(<nt def='NT-Char'>Char</nt>* &pic; <nt def='NT-Char'>Char</nt>*))
'&pic;'</rhs>
<com>processing instruction </com>
<!--* <rhs>'&lt;![' <nt def="NT-simpleDTD">simpleDTD</nt>* ']]&gt;'</rhs>
<com>conditional section</com> *-->
<rhs><nt def="NT-SimpleLit">SimpleLit</nt></rhs>
<rhs>(<nt def="NT-Char">Char</nt> - (']' | '&lt;' | '"' | "'"))+
</rhs>
<!--* <rhs>'&lt;!' (<nt def="NT-Char">Char</nt> - ('-' | '['))+</rhs>
<com>declarations other than comment, conditional section</com> *-->
<rhs>'&lt;!' (<nt def="NT-Char">Char</nt> - ('-'))+</rhs>
<com>declarations other than comment</com>
</prod>
</scrap>
Most processors will require the more complex
grammar given in the body of this specification.

</p>
</div1>
 
<div1 type="section">
<head>References</head>
 
<listbibl>
<bibl id='Dragon' n='Aho/Ullman'>Aho, Alfred V., 
Ravi Sethi, and Jeffrey D. Ullman.
<title>Compilers:  Principles, Techniques, and Tools</title>.
Reading:  Addison-Wesley, 1986, rpt. corr. 1988.</bibl>
<bibl id='ABK' n='Brüggemann-Klein'>Brüggemann-Klein, Anne.
<title>Regular Expressions into Finite Automata</title>.
Universität Freiburg, Institut für Informatik,
Bericht 33, Juli 1991.
</bibl>
<bibl id='ABKDW' n='Brüggemann-Klein'>Brüggemann-Klein, Anne,
and Derick Wood.
<title>Deterministic Regular Languages</title>.
Universität Freiburg, Institut für Informatik,
Bericht 38, Oktober 1991.
</bibl>
<bibl id='ISO8879' n='ISO/IEC 8879'>ISO
(International Organization for Standardization).
<title>ISO/IEC 8879-1986 (E).  Information processing &mdash; Text and Office
Systems &mdash; Standard Generalized Markup Language (SGML).</title>  First
edition &mdash; 1986-10-15.  [Geneva]:  International Organization for
Standardization, 1986.
</bibl>
<bibl id='ISO10646' n='ISO/IEC 10646'>ISO
(International Organization for Standardization).
<title>ISO/IEC 10646-1993 (E).  Information technology &mdash; Universal
Multiple-Octet Coded Character Set (UCS) &mdash; Part 1:
Architecture and Basic Multilingual Plane.</title>
[Geneva]:  International Organization for
Standardization, 1993 (plus amendments AM 1 through AM 5).
</bibl>
<bibl id='ISO10744' n='ISO/IEC 10744'>ISO
(International Organization for Standardization).
<title>ISO/IEC 10744-1992 (E).  Information technology &mdash;
Hypermedia/Time-based Structuring Language (HyTime).
</title>
[Geneva]:  International Organization for
Standardization, 1992.
<title>Extended Facilities Annexe.</title>
[Geneva]:  International Organization for
Standardization, 1996. 
</bibl>
<bibl id='RFC1738' N='IETF RFC 1738'>
IETF (Internet Engineering Task Force).
<title>RFC 1738:  Uniform Resource Locators</title>.
1991.
</bibl>
<bibl id='Unicode' n='Unicode'>The Unicode Consortium.
<title>The Unicode Standard, Version 2.0.</title>
Reading, Mass.:  Addison-Wesley Developers Press, 1996.</bibl>
</listbibl>
</div1>
 
<div1 type="section">
<head>W3C XML Working Group</head>
 
<p>This specification was prepared and approved for publication by the
W3C XML Working Group (WG).  WG approval of this specification does
not necessarily imply that all WG members voted for its approval.  At
the time it approved this specification, the XML WG comprised the
following members:</p>
 
<wglist>
<wgm><wgname>Jon Bosak, Sun</wgname><role> (Chair)</role></wgm>
<wgm><wgname>James Clark</wgname><role> (Technical Lead)</role></wgm>
<wgm><wgname>Tim Bray, Textuality and Netscape</wgname><role> (XML Co-editor)</role></wgm>
<wgm><wgname>Jean Paoli, Microsoft</wgname><role> (XML Co-editor)</role></wgm>
<wgm><wgname>C. M. Sperberg-McQueen, U. of Ill.</wgname><role> (XML Co-editor)</role></wgm>
<wgm><wgname>Steve DeRose, INSO</wgname></wgm>
<wgm><wgname>Dave Hollander, HP</wgname></wgm>
<wgm><wgname>Eliot Kimber, Highland</wgname></wgm>
<wgm><wgname>Tom Magliery, NCSA</wgname></wgm>
<wgm><wgname>Eve Maler, ArborText</wgname></wgm>
<wgm><wgname>Murray Maloney, Grif</wgname></wgm>
<wgm><wgname>Peter Sharpe, SoftQuad</wgname></wgm>
</wglist>

</div1>
</BACK>
 
</TEXT>
</spec>
<!--* Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-default-dtd-file:"~/sgml/spec.ced"
sgml-omittag:t
sgml-shorttag:t
End:
*-->
