1<?xml version="1.0" encoding="ISO-8859-1" standalone="no"?> 2<!DOCTYPE spec SYSTEM "dtds/spec.dtd" [ 3<!-- LAST TOUCHED BY: Tim Bray, 8 February 1997 --><!-- The words 'FINAL EDIT' in comments mark places where changes 4need to be made after approval of the document by the ERB, before 5publication. --><!ENTITY XML.version "1.0"> 6<!ENTITY doc.date "10 February 1998"> 7<!ENTITY iso6.doc.date "19980210"> 8<!ENTITY w3c.doc.date "02-Feb-1998"> 9<!ENTITY draft.day "10"> 10<!ENTITY draft.month "February"> 11<!ENTITY draft.year "1998"> 12<!ENTITY WebSGML "WebSGML Adaptations Annex to ISO 8879"> 13<!ENTITY lt "<"> 14<!ENTITY gt ">"> 15<!ENTITY xmlpio "'<?xml'"> 16<!ENTITY pic "'?>'"> 17<!ENTITY br "\n"> 18<!ENTITY cellback "#c0d9c0"> 19<!ENTITY mdash "--"> 20<!-- —, but nsgmls doesn't grok hex --><!ENTITY com "--"> 21<!ENTITY como "--"> 22<!ENTITY comc "--"> 23<!ENTITY hcro "&#x"> 24<!-- <!ENTITY nbsp "�"> --><!ENTITY nbsp " "> 25<!ENTITY magicents "<code>amp</code>, 26<code>lt</code>, 27<code>gt</code>, 28<code>apos</code>, 29<code>quot</code>"> 30<!-- audience and distribution status: for use at publication time --><!ENTITY doc.audience "public review and discussion"> 31<!ENTITY doc.distribution "may be distributed freely, as long as 32all text and legal notices remain intact"> 33]> 34<!-- for Panorama *--> 35<?VERBATIM "eg" ?> 36<spec> 37<header> 38<title>Extensible Markup Language (XML) 1.0</title> 39<version/> 40<w3c-designation>REC-xml-&iso6.doc.date;</w3c-designation> 41<w3c-doctype>W3C Recommendation</w3c-doctype> 42<pubdate><day>&draft.day;</day><month>&draft.month;</month><year>&draft.year;</year></pubdate> 43 44<publoc> 45<loc href="http://www.w3.org/TR/1998/REC-xml-&iso6.doc.date;"> 46http://www.w3.org/TR/1998/REC-xml-&iso6.doc.date;</loc> 47<loc href="http://www.w3.org/TR/1998/REC-xml-&iso6.doc.date;.xml"> 48http://www.w3.org/TR/1998/REC-xml-&iso6.doc.date;.xml</loc> 49<loc href="http://www.w3.org/TR/1998/REC-xml-&iso6.doc.date;.html"> 50http://www.w3.org/TR/1998/REC-xml-&iso6.doc.date;.html</loc> 51<loc href="http://www.w3.org/TR/1998/REC-xml-&iso6.doc.date;.pdf"> 52http://www.w3.org/TR/1998/REC-xml-&iso6.doc.date;.pdf</loc> 53<loc href="http://www.w3.org/TR/1998/REC-xml-&iso6.doc.date;.ps"> 54http://www.w3.org/TR/1998/REC-xml-&iso6.doc.date;.ps</loc> 55</publoc> 56<latestloc> 57<loc href="http://www.w3.org/TR/REC-xml"> 58http://www.w3.org/TR/REC-xml</loc> 59</latestloc> 60<prevlocs> 61<loc href="http://www.w3.org/TR/PR-xml-971208"> 62http://www.w3.org/TR/PR-xml-971208</loc> 63<!-- 64<loc href='http://www.w3.org/TR/WD-xml-961114'> 65http://www.w3.org/TR/WD-xml-961114</loc> 66<loc href='http://www.w3.org/TR/WD-xml-lang-970331'> 67http://www.w3.org/TR/WD-xml-lang-970331</loc> 68<loc href='http://www.w3.org/TR/WD-xml-lang-970630'> 69http://www.w3.org/TR/WD-xml-lang-970630</loc> 70<loc href='http://www.w3.org/TR/WD-xml-970807'> 71http://www.w3.org/TR/WD-xml-970807</loc> 72<loc href='http://www.w3.org/TR/WD-xml-971117'> 73http://www.w3.org/TR/WD-xml-971117</loc>--> 74</prevlocs> 75<authlist> 76<author><name>Tim Bray</name> 77<affiliation>Textuality and Netscape</affiliation> 78<email href="mailto:tbray@textuality.com">tbray@textuality.com</email></author> 79<author><name>Jean Paoli</name> 80<affiliation>Microsoft</affiliation> 81<email href="mailto:jeanpa@microsoft.com">jeanpa@microsoft.com</email></author> 82<author><name>C. M. Sperberg-McQueen</name> 83<affiliation>University of Illinois at Chicago</affiliation> 84<email href="mailto:cmsmcq@uic.edu">cmsmcq@uic.edu</email></author> 85</authlist> 86<abstract> 87<p>The Extensible Markup Language (XML) is a subset of 88SGML that is completely described in this document. Its goal is to 89enable generic SGML to be served, received, and processed on the Web 90in the way that is now possible with HTML. XML has been designed for 91ease of implementation and for interoperability with both SGML and 92HTML.</p> 93</abstract> 94<status> 95<p>This document has been reviewed by W3C Members and 96other interested parties and has been endorsed by the 97Director as a W3C Recommendation. It is a stable 98document and may be used as reference material or cited 99as a normative reference from another document. W3C's 100role in making the Recommendation is to draw attention 101to the specification and to promote its widespread 102deployment. This enhances the functionality and 103interoperability of the Web.</p> 104<p> 105This document specifies a syntax created by subsetting an existing, 106widely used international text processing standard (Standard 107Generalized Markup Language, ISO 8879:1986(E) as amended and 108corrected) for use on the World Wide Web. It is a product of the W3C 109XML Activity, details of which can be found at <loc href="http://www.w3.org/XML">http://www.w3.org/XML</loc>. A list of 110current W3C Recommendations and other technical documents can be found 111at <loc href="http://www.w3.org/TR">http://www.w3.org/TR</loc>. 112</p> 113<p>This specification uses the term URI, which is defined by <bibref ref="Berners-Lee"/>, a work in progress expected to update <bibref ref="RFC1738"/> and <bibref ref="RFC1808"/>. 114</p> 115<p>The list of known errors in this specification is 116available at 117<loc href="http://www.w3.org/XML/xml-19980210-errata">http://www.w3.org/XML/xml-19980210-errata</loc>.</p> 118<p>Please report errors in this document to 119<loc href="mailto:xml-editor@w3.org">xml-editor@w3.org</loc>. 120</p> 121</status> 122 123 124<pubstmt> 125<p>Chicago, Vancouver, Mountain View, et al.: 126World-Wide Web Consortium, XML Working Group, 1996, 1997.</p> 127</pubstmt> 128<sourcedesc> 129<p>Created in electronic form.</p> 130</sourcedesc> 131<langusage> 132<language id="EN">English</language> 133<language id="ebnf">Extended Backus-Naur Form (formal grammar)</language> 134</langusage> 135<revisiondesc> 136<slist> 137<sitem>1997-12-03 : CMSMcQ : yet further changes</sitem> 138<sitem>1997-12-02 : TB : further changes (see TB to XML WG, 1392 December 1997)</sitem> 140<sitem>1997-12-02 : CMSMcQ : deal with as many corrections and 141comments from the proofreaders as possible: 142entify hard-coded document date in pubdate element, 143change expansion of entity WebSGML, 144update status description as per Dan Connolly (am not sure 145about refernece to Berners-Lee et al.), 146add 'The' to abstract as per WG decision, 147move Relationship to Existing Standards to back matter and 148combine with References, 149re-order back matter so normative appendices come first, 150re-tag back matter so informative appendices are tagged informdiv1, 151remove XXX XXX from list of 'normative' specs in prose, 152move some references from Other References to Normative References, 153add RFC 1738, 1808, and 2141 to Other References (they are not 154normative since we do not require the processor to enforce any 155rules based on them), 156add reference to 'Fielding draft' (Berners-Lee et al.), 157move notation section to end of body, 158drop URIchar non-terminal and use SkipLit instead, 159lose stray reference to defunct nonterminal 'markupdecls', 160move reference to Aho et al. into appendix (Tim's right), 161add prose note saying that hash marks and fragment identifiers are 162NOT part of the URI formally speaking, and are NOT legal in 163system identifiers (processor 'may' signal an error). 164Work through: 165Tim Bray reacting to James Clark, 166Tim Bray on his own, 167Eve Maler, 168 169NOT DONE YET: 170change binary / text to unparsed / parsed. 171handle James's suggestion about < in attriubte values 172uppercase hex characters, 173namechar list, 174</sitem> 175<sitem>1997-12-01 : JB : add some column-width parameters</sitem> 176<sitem>1997-12-01 : CMSMcQ : begin round of changes to incorporate 177recent WG decisions and other corrections: 178binding sources of character encoding info (27 Aug / 3 Sept), 179correct wording of Faust quotation (restore dropped line), 180drop SDD from EncodingDecl, 181change text at version number 1.0, 182drop misleading (wrong!) sentence about ignorables and extenders, 183modify definition of PCData to make bar on msc grammatical, 184change grammar's handling of internal subset (drop non-terminal markupdecls), 185change definition of includeSect to allow conditional sections, 186add integral-declaration constraint on internal subset, 187drop misleading / dangerous sentence about relationship of 188entities with system storage objects, 189change table body tag to htbody as per EM change to DTD, 190add rule about space normalization in public identifiers, 191add description of how to generate our name-space rules from 192Unicode character database (needs further work!). 193</sitem> 194<sitem>1997-10-08 : TB : Removed %-constructs again, new rules 195for PE appearance.</sitem> 196<sitem>1997-10-01 : TB : Case-sensitive markup; cleaned up 197element-type defs, lotsa little edits for style</sitem> 198<sitem>1997-09-25 : TB : Change to elm's new DTD, with 199substantial detail cleanup as a side-effect</sitem> 200<sitem>1997-07-24 : CMSMcQ : correct error (lost *) in definition 201of ignoreSectContents (thanks to Makoto Murata)</sitem> 202<sitem>Allow all empty elements to have end-tags, consistent with 203SGML TC (as per JJC).</sitem> 204<sitem>1997-07-23 : CMSMcQ : pre-emptive strike on pending corrections: 205introduce the term 'empty-element tag', note that all empty elements 206may use it, and elements declared EMPTY must use it. 207Add WFC requiring encoding decl to come first in an entity. 208Redefine notations to point to PIs as well as binary entities. 209Change autodetection table by removing bytes 3 and 4 from 210examples with Byte Order Mark. 211Add content model as a term and clarify that it applies to both 212mixed and element content. 213</sitem> 214<sitem>1997-06-30 : CMSMcQ : change date, some cosmetic changes, 215changes to productions for choice, seq, Mixed, NotationType, 216Enumeration. Follow James Clark's suggestion and prohibit 217conditional sections in internal subset. TO DO: simplify 218production for ignored sections as a result, since we don't 219need to worry about parsers which don't expand PErefs finding 220a conditional section.</sitem> 221<sitem>1997-06-29 : TB : various edits</sitem> 222<sitem>1997-06-29 : CMSMcQ : further changes: 223Suppress old FINAL EDIT comments and some dead material. 224Revise occurrences of % in grammar to exploit Henry Thompson's pun, 225especially markupdecl and attdef. 226Remove RMD requirement relating to element content (?). 227</sitem> 228<sitem>1997-06-28 : CMSMcQ : Various changes for 1 July draft: 229Add text for draconian error handling (introduce 230the term Fatal Error). 231RE deleta est (changing wording from 232original announcement to restrict the requirement to validating 233parsers). 234Tag definition of validating processor and link to it. 235Add colon as name character. 236Change def of %operator. 237Change standard definitions of lt, gt, amp. 238Strip leading zeros from #x00nn forms.</sitem> 239<sitem>1997-04-02 : CMSMcQ : final corrections of editorial errors 240found in last night's proofreading. Reverse course once more on 241well-formed: Webster's Second hyphenates it, and that's enough 242for me.</sitem> 243<sitem>1997-04-01 : CMSMcQ : corrections from JJC, EM, HT, and self</sitem> 244<sitem>1997-03-31 : Tim Bray : many changes</sitem> 245<sitem>1997-03-29 : CMSMcQ : some Henry Thompson (on entity handling), 246some Charles Goldfarb, some ERB decisions (PE handling in miscellaneous 247declarations. Changed Ident element to accept def attribute. 248Allow normalization of Unicode characters. move def of systemliteral 249into section on literals.</sitem> 250<sitem>1997-03-28 : CMSMcQ : make as many corrections as possible, from 251Terry Allen, Norbert Mikula, James Clark, Jon Bosak, Henry Thompson, 252Paul Grosso, and self. Among other things: give in on "well formed" 253(Terry is right), tentatively rename QuotedCData as AttValue 254and Literal as EntityValue to be more informative, since attribute 255values are the <emph>only</emph> place QuotedCData was used, and 256vice versa for entity text and Literal. (I'd call it Entity Text, 257but 8879 uses that name for both internal and external entities.)</sitem> 258<sitem>1997-03-26 : CMSMcQ : resynch the two forks of this draft, reapply 259my changes dated 03-20 and 03-21. Normalize old 'may not' to 'must not' 260except in the one case where it meant 'may or may not'.</sitem> 261<sitem>1997-03-21 : TB : massive changes on plane flight from Chicago 262to Vancouver</sitem> 263<sitem>1997-03-21 : CMSMcQ : correct as many reported errors as possible. 264</sitem> 265<sitem>1997-03-20 : CMSMcQ : correct typos listed in CMSMcQ hand copy of spec.</sitem> 266<sitem>1997-03-20 : CMSMcQ : cosmetic changes preparatory to revision for 267WWW conference April 1997: restore some of the internal entity 268references (e.g. to docdate, etc.), change character xA0 to &nbsp; 269and define nbsp as &#160;, and refill a lot of paragraphs for 270legibility.</sitem> 271<sitem>1996-11-12 : CMSMcQ : revise using Tim's edits: 272Add list type of NUMBERED and change most lists either to 273BULLETS or to NUMBERED. 274Suppress QuotedNames, Names (not used). 275Correct trivial-grammar doc type decl. 276Rename 'marked section' as 'CDATA section' passim. 277Also edits from James Clark: 278Define the set of characters from which [^abc] subtracts. 279Charref should use just [0-9] not Digit. 280Location info needs cleaner treatment: remove? (ERB 281question). 282One example of a PI has wrong pic. 283Clarify discussion of encoding names. 284Encoding failure should lead to unspecified results; don't 285prescribe error recovery. 286Don't require exposure of entity boundaries. 287Ignore white space in element content. 288Reserve entity names of the form u-NNNN. 289Clarify relative URLs. 290And some of my own: 291Correct productions for content model: model cannot 292consist of a name, so "elements ::= cp" is no good. 293</sitem> 294<sitem>1996-11-11 : CMSMcQ : revise for style. 295Add new rhs to entity declaration, for parameter entities.</sitem> 296<sitem>1996-11-10 : CMSMcQ : revise for style. 297Fix / complete section on names, characters. 298Add sections on parameter entities, conditional sections. 299Still to do: Add compatibility note on deterministic content models. 300Finish stylistic revision.</sitem> 301<sitem>1996-10-31 : TB : Add Entity Handling section</sitem> 302<sitem>1996-10-30 : TB : Clean up term & termdef. Slip in 303ERB decision re EMPTY.</sitem> 304<sitem>1996-10-28 : TB : Change DTD. Implement some of Michael's 305suggestions. Change comments back to //. Introduce language for 306XML namespace reservation. Add section on white-space handling. 307Lots more cleanup.</sitem> 308<sitem>1996-10-24 : CMSMcQ : quick tweaks, implement some ERB 309decisions. Characters are not integers. Comments are /* */ not //. 310Add bibliographic refs to 10646, HyTime, Unicode. 311Rename old Cdata as MsData since it's <emph>only</emph> seen 312in marked sections. Call them attribute-value pairs not 313name-value pairs, except once. Internal subset is optional, needs 314'?'. Implied attributes should be signaled to the app, not 315have values supplied by processor.</sitem> 316<sitem>1996-10-16 : TB : track down & excise all DSD references; 317introduce some EBNF for entity declarations.</sitem> 318<sitem>1996-10-?? : TB : consistency check, fix up scraps so 319they all parse, get formatter working, correct a few productions.</sitem> 320<sitem>1996-10-10/11 : CMSMcQ : various maintenance, stylistic, and 321organizational changes: 322Replace a few literals with xmlpio and 323pic entities, to make them consistent and ensure we can change pic 324reliably when the ERB votes. 325Drop paragraph on recognizers from notation section. 326Add match, exact match to terminology. 327Move old 2.2 XML Processors and Apps into intro. 328Mention comments, PIs, and marked sections in discussion of 329delimiter escaping. 330Streamline discussion of doctype decl syntax. 331Drop old section of 'PI syntax' for doctype decl, and add 332section on partial-DTD summary PIs to end of Logical Structures 333section. 334Revise DSD syntax section to use Tim's subset-in-a-PI 335mechanism.</sitem> 336<sitem>1996-10-10 : TB : eliminate name recognizers (and more?)</sitem> 337<sitem>1996-10-09 : CMSMcQ : revise for style, consistency through 2.3 338(Characters)</sitem> 339<sitem>1996-10-09 : CMSMcQ : re-unite everything for convenience, 340at least temporarily, and revise quickly</sitem> 341<sitem>1996-10-08 : TB : first major homogenization pass</sitem> 342<sitem>1996-10-08 : TB : turn "current" attribute on div type into 343CDATA</sitem> 344<sitem>1996-10-02 : TB : remould into skeleton + entities</sitem> 345<sitem>1996-09-30 : CMSMcQ : add a few more sections prior to exchange 346 with Tim.</sitem> 347<sitem>1996-09-20 : CMSMcQ : finish transcribing notes.</sitem> 348<sitem>1996-09-19 : CMSMcQ : begin transcribing notes for draft.</sitem> 349<sitem>1996-09-13 : CMSMcQ : made outline from notes of 09-06, 350do some housekeeping</sitem> 351</slist> 352</revisiondesc> 353</header> 354<body> 355<div1 id="sec-intro"> 356<head>Introduction</head> 357<p>Extensible Markup Language, abbreviated XML, describes a class of 358data objects called <termref def="dt-xml-doc">XML documents</termref> and 359partially describes the behavior of 360computer programs which process them. XML is an application profile or 361restricted form of SGML, the Standard Generalized Markup 362Language <bibref ref="ISO8879"/>. 363By construction, XML documents 364are conforming SGML documents. 365</p> 366<p>XML documents are made up of storage units called <termref def="dt-entity">entities</termref>, which contain either parsed 367or unparsed data. 368Parsed data is made up of <termref def="dt-character">characters</termref>, 369some 370of which form <termref def="dt-chardata">character data</termref>, 371and some of which form <termref def="dt-markup">markup</termref>. 372Markup encodes a description of the document's storage layout and 373logical structure. XML provides a mechanism to impose constraints on 374the storage layout and logical structure.</p> 375<p><termdef id="dt-xml-proc" term="XML Processor">A software module 376called an <term>XML processor</term> is used to read XML documents 377and provide access to their content and structure.</termdef> <termdef id="dt-app" term="Application">It is assumed that an XML processor is 378doing its work on behalf of another module, called the 379<term>application</term>.</termdef> This specification describes the 380required behavior of an XML processor in terms of how it must read XML 381data and the information it must provide to the application.</p> 382 383<div2 id="sec-origin-goals"> 384<head>Origin and Goals</head> 385<p>XML was developed by an XML Working Group (originally known as the 386SGML Editorial Review Board) formed under the auspices of the World 387Wide Web Consortium (W3C) in 1996. 388It was chaired by Jon Bosak of Sun 389Microsystems with the active participation of an XML Special 390Interest Group (previously known as the SGML Working Group) also 391organized by the W3C. The membership of the XML Working Group is given 392in an appendix. Dan Connolly served as the WG's contact with the W3C. 393</p> 394<p>The design goals for XML are:<olist> 395<item><p>XML shall be straightforwardly usable over the 396Internet.</p></item> 397<item><p>XML shall support a wide variety of applications.</p></item> 398<item><p>XML shall be compatible with SGML.</p></item> 399<item><p>It shall be easy to write programs which process XML 400documents.</p></item> 401<item><p>The number of optional features in XML is to be kept to the 402absolute minimum, ideally zero.</p></item> 403<item><p>XML documents should be human-legible and reasonably 404clear.</p></item> 405<item><p>The XML design should be prepared quickly.</p></item> 406<item><p>The design of XML shall be formal and concise.</p></item> 407<item><p>XML documents shall be easy to create.</p></item> 408<item><p>Terseness in XML markup is of minimal importance.</p></item></olist> 409</p> 410<p>This specification, 411together with associated standards 412(Unicode and ISO/IEC 10646 for characters, 413Internet RFC 1766 for language identification tags, 414ISO 639 for language name codes, and 415ISO 3166 for country name codes), 416provides all the information necessary to understand 417XML Version &XML.version; 418and construct computer programs to process it.</p> 419<p>This version of the XML specification 420<!-- is for &doc.audience;.--> 421&doc.distribution;.</p> 422 423</div2> 424 425 426 427 428<div2 id="sec-terminology"> 429<head>Terminology</head> 430 431<p>The terminology used to describe XML documents is defined in the body of 432this specification. 433The terms defined in the following list are used in building those 434definitions and in describing the actions of an XML processor: 435<glist> 436<gitem> 437<label>may</label> 438<def><p><termdef id="dt-may" term="May">Conforming documents and XML 439processors are permitted to but need not behave as 440described.</termdef></p></def> 441</gitem> 442<gitem> 443<label>must</label> 444<def><p>Conforming documents and XML processors 445are required to behave as described; otherwise they are in error. 446<!-- do NOT change this! this is what defines a violation of 447a 'must' clause as 'an error'. -MSM --> 448</p></def> 449</gitem> 450<gitem> 451<label>error</label> 452<def><p><termdef id="dt-error" term="Error">A violation of the rules of this 453specification; results are 454undefined. Conforming software may detect and report an error and may 455recover from it.</termdef></p></def> 456</gitem> 457<gitem> 458<label>fatal error</label> 459<def><p><termdef id="dt-fatal" term="Fatal Error">An error 460which a conforming <termref def="dt-xml-proc">XML processor</termref> 461must detect and report to the application. 462After encountering a fatal error, the 463processor may continue 464processing the data to search for further errors and may report such 465errors to the application. In order to support correction of errors, 466the processor may make unprocessed data from the document (with 467intermingled character data and markup) available to the application. 468Once a fatal error is detected, however, the processor must not 469continue normal processing (i.e., it must not 470continue to pass character data and information about the document's 471logical structure to the application in the normal way). 472</termdef></p></def> 473</gitem> 474<gitem> 475<label>at user option</label> 476<def><p>Conforming software may or must (depending on the modal verb in the 477sentence) behave as described; if it does, it must 478provide users a means to enable or disable the behavior 479described.</p></def> 480</gitem> 481<gitem> 482<label>validity constraint</label> 483<def><p>A rule which applies to all 484<termref def="dt-valid">valid</termref> XML documents. 485Violations of validity constraints are errors; they must, at user option, 486be reported by 487<termref def="dt-validating">validating XML processors</termref>.</p></def> 488</gitem> 489<gitem> 490<label>well-formedness constraint</label> 491<def><p>A rule which applies to all <termref def="dt-wellformed">well-formed</termref> XML documents. 492Violations of well-formedness constraints are 493<termref def="dt-fatal">fatal errors</termref>.</p></def> 494</gitem> 495 496<gitem> 497<label>match</label> 498<def><p><termdef id="dt-match" term="match">(Of strings or names:) 499Two strings or names being compared must be identical. 500Characters with multiple possible representations in ISO/IEC 10646 (e.g. 501characters with 502both precomposed and base+diacritic forms) match only if they have the 503same representation in both strings. 504At user option, processors may normalize such characters to 505some canonical form. 506No case folding is performed. 507(Of strings and rules in the grammar:) 508A string matches a grammatical production if it belongs to the 509language generated by that production. 510(Of content and content models:) 511An element matches its declaration when it conforms 512in the fashion described in the constraint 513<specref ref="elementvalid"/>. 514</termdef> 515</p></def> 516</gitem> 517<gitem> 518<label>for compatibility</label> 519<def><p><termdef id="dt-compat" term="For Compatibility">A feature of 520XML included solely to ensure that XML remains compatible with SGML. 521</termdef></p></def> 522</gitem> 523<gitem> 524<label>for interoperability</label> 525<def><p><termdef id="dt-interop" term="For interoperability">A 526non-binding recommendation included to increase the chances that XML 527documents can be processed by the existing installed base of SGML 528processors which predate the 529&WebSGML;.</termdef></p></def> 530</gitem> 531</glist> 532</p> 533</div2> 534 535 536</div1> 537<!-- &Docs; --> 538 539<div1 id="sec-documents"> 540<head>Documents</head> 541 542<p><termdef id="dt-xml-doc" term="XML Document"> 543A data object is an 544<term>XML document</term> if it is 545<termref def="dt-wellformed">well-formed</termref>, as 546defined in this specification. 547A well-formed XML document may in addition be 548<termref def="dt-valid">valid</termref> if it meets certain further 549constraints.</termdef></p> 550 551<p>Each XML document has both a logical and a physical structure. 552Physically, the document is composed of units called <termref def="dt-entity">entities</termref>. An entity may <termref def="dt-entref">refer</termref> to other entities to cause their 553inclusion in the document. A document begins in a "root" or <termref def="dt-docent">document entity</termref>. 554Logically, the document is composed of declarations, elements, 555comments, 556character references, and 557processing 558instructions, all of which are indicated in the document by explicit 559markup. 560The logical and physical structures must nest properly, as described 561in <specref ref="wf-entities"/>. 562</p> 563 564<div2 id="sec-well-formed"> 565<head>Well-Formed XML Documents</head> 566 567<p><termdef id="dt-wellformed" term="Well-Formed"> 568A textual object is 569a well-formed XML document if:</termdef> 570<olist> 571<item><p>Taken as a whole, it 572matches the production labeled <nt def="NT-document">document</nt>.</p></item> 573<item><p>It 574meets all the well-formedness constraints given in this specification.</p> 575</item> 576<item><p>Each of the <termref def="dt-parsedent">parsed entities</termref> 577which is referenced directly or indirectly within the document is 578<titleref href="wf-entities">well-formed</titleref>.</p></item> 579</olist></p> 580<p> 581<scrap lang="ebnf" id="document"> 582<head>Document</head> 583<prod id="NT-document"><lhs>document</lhs> 584<rhs><nt def="NT-prolog">prolog</nt> 585<nt def="NT-element">element</nt> 586<nt def="NT-Misc">Misc</nt>*</rhs></prod> 587</scrap> 588</p> 589<p>Matching the <nt def="NT-document">document</nt> production 590implies that: 591<olist> 592<item><p>It contains one or more 593<termref def="dt-element">elements</termref>.</p> 594</item> 595<!--* N.B. some readers (notably JC) find the following 596paragraph awkward and redundant. I agree it's logically redundant: 597it *says* it is summarizing the logical implications of 598matching the grammar, and that means by definition it's 599logically redundant. I don't think it's rhetorically 600redundant or unnecessary, though, so I'm keeping it. It 601could however use some recasting when the editors are feeling 602stronger. -MSM *--> 603<item><p><termdef id="dt-root" term="Root Element">There is exactly 604one element, called the <term>root</term>, or document element, no 605part of which appears in the <termref def="dt-content">content</termref> of any other element.</termdef> 606For all other elements, if the start-tag is in the content of another 607element, the end-tag is in the content of the same element. More 608simply stated, the elements, delimited by start- and end-tags, nest 609properly within each other. 610</p></item> 611</olist> 612</p> 613<p><termdef id="dt-parentchild" term="Parent/Child">As a consequence 614of this, 615for each non-root element 616<code>C</code> in the document, there is one other element <code>P</code> 617in the document such that 618<code>C</code> is in the content of <code>P</code>, but is not in 619the content of any other element that is in the content of 620<code>P</code>. 621<code>P</code> is referred to as the 622<term>parent</term> of <code>C</code>, and <code>C</code> as a 623<term>child</term> of <code>P</code>.</termdef></p></div2> 624 625<div2 id="charsets"> 626<head>Characters</head> 627 628<p><termdef id="dt-text" term="Text">A parsed entity contains 629<term>text</term>, a sequence of 630<termref def="dt-character">characters</termref>, 631which may represent markup or character data.</termdef> 632<termdef id="dt-character" term="Character">A <term>character</term> 633is an atomic unit of text as specified by 634ISO/IEC 10646 <bibref ref="ISO10646"/>. 635Legal characters are tab, carriage return, line feed, and the legal 636graphic characters of Unicode and ISO/IEC 10646. 637The use of "compatibility characters", as defined in section 6.8 638of <bibref ref="Unicode"/>, is discouraged. 639</termdef> 640<scrap lang="ebnf" id="char32"> 641<head>Character Range</head> 642<prodgroup pcw2="4" pcw4="17.5" pcw5="11"> 643<prod id="NT-Char"><lhs>Char</lhs> 644<rhs>#x9 | #xA | #xD | [#x20-#xD7FF] | [#xE000-#xFFFD] 645| [#x10000-#x10FFFF]</rhs> 646<com>any Unicode character, excluding the 647surrogate blocks, FFFE, and FFFF.</com> </prod> 648</prodgroup> 649</scrap> 650</p> 651 652<p>The mechanism for encoding character code points into bit patterns may 653vary from entity to entity. All XML processors must accept the UTF-8 654and UTF-16 encodings of 10646; the mechanisms for signaling which of 655the two is in use, or for bringing other encodings into play, are 656discussed later, in <specref ref="charencoding"/>. 657</p> 658<!-- 659<p>Regardless of the specific encoding used, any character in the ISO/IEC 66010646 character set may be referred to by the decimal or hexadecimal 661equivalent of its 662UCS-4 code value. 663</p>--> 664</div2> 665 666<div2 id="sec-common-syn"> 667<head>Common Syntactic Constructs</head> 668 669<p>This section defines some symbols used widely in the grammar.</p> 670<p><nt def="NT-S">S</nt> (white space) consists of one or more space (#x20) 671characters, carriage returns, line feeds, or tabs. 672 673<scrap lang="ebnf" id="white"> 674<head>White Space</head> 675<prodgroup pcw2="4" pcw4="17.5" pcw5="11"> 676<prod id="NT-S"><lhs>S</lhs> 677<rhs>(#x20 | #x9 | #xD | #xA)+</rhs> 678</prod> 679</prodgroup> 680</scrap></p> 681<p>Characters are classified for convenience as letters, digits, or other 682characters. Letters consist of an alphabetic or syllabic 683base character possibly 684followed by one or more combining characters, or of an ideographic 685character. 686Full definitions of the specific characters in each class 687are given in <specref ref="CharClasses"/>.</p> 688<p><termdef id="dt-name" term="Name">A <term>Name</term> is a token 689beginning with a letter or one of a few punctuation characters, and continuing 690with letters, digits, hyphens, underscores, colons, or full stops, together 691known as name characters.</termdef> 692Names beginning with the string "<code>xml</code>", or any string 693which would match <code>(('X'|'x') ('M'|'m') ('L'|'l'))</code>, are 694reserved for standardization in this or future versions of this 695specification. 696</p> 697<note> 698<p>The colon character within XML names is reserved for experimentation with 699name spaces. 700Its meaning is expected to be 701standardized at some future point, at which point those documents 702using the colon for experimental purposes may need to be updated. 703(There is no guarantee that any name-space mechanism 704adopted for XML will in fact use the colon as a name-space delimiter.) 705In practice, this means that authors should not use the colon in XML 706names except as part of name-space experiments, but that XML processors 707should accept the colon as a name character.</p> 708</note> 709<p>An 710<nt def="NT-Nmtoken">Nmtoken</nt> (name token) is any mixture of 711name characters. 712<scrap lang="ebnf"> 713<head>Names and Tokens</head> 714<prod id="NT-NameChar"><lhs>NameChar</lhs> 715<rhs><nt def="NT-Letter">Letter</nt> 716| <nt def="NT-Digit">Digit</nt> 717| '.' | '-' | '_' | ':' 718| <nt def="NT-CombiningChar">CombiningChar</nt> 719| <nt def="NT-Extender">Extender</nt></rhs> 720</prod> 721<prod id="NT-Name"><lhs>Name</lhs> 722<rhs>(<nt def="NT-Letter">Letter</nt> | '_' | ':') 723(<nt def="NT-NameChar">NameChar</nt>)*</rhs></prod> 724<prod id="NT-Names"><lhs>Names</lhs> 725<rhs><nt def="NT-Name">Name</nt> 726(<nt def="NT-S">S</nt> <nt def="NT-Name">Name</nt>)*</rhs></prod> 727<prod id="NT-Nmtoken"><lhs>Nmtoken</lhs> 728<rhs>(<nt def="NT-NameChar">NameChar</nt>)+</rhs></prod> 729<prod id="NT-Nmtokens"><lhs>Nmtokens</lhs> 730<rhs><nt def="NT-Nmtoken">Nmtoken</nt> (<nt def="NT-S">S</nt> <nt def="NT-Nmtoken">Nmtoken</nt>)*</rhs></prod> 731</scrap> 732</p> 733<p>Literal data is any quoted string not containing 734the quotation mark used as a delimiter for that string. 735Literals are used 736for specifying the content of internal entities 737(<nt def="NT-EntityValue">EntityValue</nt>), 738the values of attributes (<nt def="NT-AttValue">AttValue</nt>), 739and external identifiers 740(<nt def="NT-SystemLiteral">SystemLiteral</nt>). 741Note that a <nt def="NT-SystemLiteral">SystemLiteral</nt> 742can be parsed without scanning for markup. 743<scrap lang="ebnf"> 744<head>Literals</head> 745<prod id="NT-EntityValue"><lhs>EntityValue</lhs> 746<rhs>'"' 747([^%&"] 748| <nt def="NT-PEReference">PEReference</nt> 749| <nt def="NT-Reference">Reference</nt>)* 750'"' 751</rhs> 752<rhs>| 753"'" 754([^%&'] 755| <nt def="NT-PEReference">PEReference</nt> 756| <nt def="NT-Reference">Reference</nt>)* 757"'"</rhs> 758</prod> 759<prod id="NT-AttValue"><lhs>AttValue</lhs> 760<rhs>'"' 761([^<&"] 762| <nt def="NT-Reference">Reference</nt>)* 763'"' 764</rhs> 765<rhs>| 766"'" 767([^<&'] 768| <nt def="NT-Reference">Reference</nt>)* 769"'"</rhs> 770</prod> 771<prod id="NT-SystemLiteral"><lhs>SystemLiteral</lhs> 772<rhs>('"' [^"]* '"') | ("'" [^']* "'") 773</rhs> 774</prod> 775<prod id="NT-PubidLiteral"><lhs>PubidLiteral</lhs> 776<rhs>'"' <nt def="NT-PubidChar">PubidChar</nt>* 777'"' 778| "'" (<nt def="NT-PubidChar">PubidChar</nt> - "'")* "'"</rhs> 779</prod> 780<prod id="NT-PubidChar"><lhs>PubidChar</lhs> 781<rhs>#x20 | #xD | #xA 782| [a-zA-Z0-9] 783| [-'()+,./:=?;!*#@$_%]</rhs> 784</prod> 785</scrap> 786</p> 787 788</div2> 789 790<div2 id="syntax"> 791<head>Character Data and Markup</head> 792 793<p><termref def="dt-text">Text</termref> consists of intermingled 794<termref def="dt-chardata">character 795data</termref> and markup. 796<termdef id="dt-markup" term="Markup"><term>Markup</term> takes the form of 797<termref def="dt-stag">start-tags</termref>, 798<termref def="dt-etag">end-tags</termref>, 799<termref def="dt-empty">empty-element tags</termref>, 800<termref def="dt-entref">entity references</termref>, 801<termref def="dt-charref">character references</termref>, 802<termref def="dt-comment">comments</termref>, 803<termref def="dt-cdsection">CDATA section</termref> delimiters, 804<termref def="dt-doctype">document type declarations</termref>, and 805<termref def="dt-pi">processing instructions</termref>. 806</termdef> 807</p> 808<p><termdef id="dt-chardata" term="Character Data">All text that is not markup 809constitutes the <term>character data</term> of 810the document.</termdef></p> 811<p>The ampersand character (&) and the left angle bracket (<) 812may appear in their literal form <emph>only</emph> when used as markup 813delimiters, or within a <termref def="dt-comment">comment</termref>, a 814<termref def="dt-pi">processing instruction</termref>, 815or a <termref def="dt-cdsection">CDATA section</termref>. 816 817They are also legal within the <termref def="dt-litentval">literal entity 818value</termref> of an internal entity declaration; see 819<specref ref="wf-entities"/>. 820<!-- FINAL EDIT: restore internal entity decl or leave it out. --> 821If they are needed elsewhere, 822they must be <termref def="dt-escape">escaped</termref> 823using either <termref def="dt-charref">numeric character references</termref> 824or the strings 825"<code>&amp;</code>" and "<code>&lt;</code>" respectively. 826The right angle 827bracket (>) may be represented using the string 828"<code>&gt;</code>", and must, <termref def="dt-compat">for 829compatibility</termref>, 830be escaped using 831"<code>&gt;</code>" or a character reference 832when it appears in the string 833"<code>]]></code>" 834in content, 835when that string is not marking the end of 836a <termref def="dt-cdsection">CDATA section</termref>. 837</p> 838<p> 839In the content of elements, character data 840is any string of characters which does 841not contain the start-delimiter of any markup. 842In a CDATA section, character data 843is any string of characters not including the CDATA-section-close 844delimiter, "<code>]]></code>".</p> 845<p> 846To allow attribute values to contain both single and double quotes, the 847apostrophe or single-quote character (') may be represented as 848"<code>&apos;</code>", and the double-quote character (") as 849"<code>&quot;</code>". 850<scrap lang="ebnf"> 851<head>Character Data</head> 852<prod id="NT-CharData"> 853<lhs>CharData</lhs> 854<rhs>[^<&]* - ([^<&]* ']]>' [^<&]*)</rhs> 855</prod> 856</scrap> 857</p> 858</div2> 859 860<div2 id="sec-comments"> 861<head>Comments</head> 862 863<p><termdef id="dt-comment" term="Comment"><term>Comments</term> may 864appear anywhere in a document outside other 865<termref def="dt-markup">markup</termref>; in addition, 866they may appear within the document type declaration 867at places allowed by the grammar. 868They are not part of the document's <termref def="dt-chardata">character 869data</termref>; an XML 870processor may, but need not, make it possible for an application to 871retrieve the text of comments. 872<termref def="dt-compat">For compatibility</termref>, the string 873"<code>--</code>" (double-hyphen) must not occur within 874comments. 875<scrap lang="ebnf"> 876<head>Comments</head> 877<prod id="NT-Comment"><lhs>Comment</lhs> 878<rhs>'<!--' 879((<nt def="NT-Char">Char</nt> - '-') 880| ('-' (<nt def="NT-Char">Char</nt> - '-')))* 881'-->'</rhs> 882</prod> 883</scrap> 884</termdef></p> 885<p>An example of a comment: 886<eg><!&como; declarations for <head> & <body> &comc;></eg> 887</p> 888</div2> 889 890<div2 id="sec-pi"> 891<head>Processing Instructions</head> 892 893<p><termdef id="dt-pi" term="Processing instruction"><term>Processing 894instructions</term> (PIs) allow documents to contain instructions 895for applications. 896 897<scrap lang="ebnf"> 898<head>Processing Instructions</head> 899<prod id="NT-PI"><lhs>PI</lhs> 900<rhs>'<?' <nt def="NT-PITarget">PITarget</nt> 901(<nt def="NT-S">S</nt> 902(<nt def="NT-Char">Char</nt>* - 903(<nt def="NT-Char">Char</nt>* &pic; <nt def="NT-Char">Char</nt>*)))? 904&pic;</rhs></prod> 905<prod id="NT-PITarget"><lhs>PITarget</lhs> 906<rhs><nt def="NT-Name">Name</nt> - 907(('X' | 'x') ('M' | 'm') ('L' | 'l'))</rhs> 908</prod> 909</scrap></termdef> 910PIs are not part of the document's <termref def="dt-chardata">character 911data</termref>, but must be passed through to the application. The 912PI begins with a target (<nt def="NT-PITarget">PITarget</nt>) used 913to identify the application to which the instruction is directed. 914The target names "<code>XML</code>", "<code>xml</code>", and so on are 915reserved for standardization in this or future versions of this 916specification. 917The 918XML <termref def="dt-notation">Notation</termref> mechanism 919may be used for 920formal declaration of PI targets. 921</p> 922</div2> 923 924<div2 id="sec-cdata-sect"> 925<head>CDATA Sections</head> 926 927<p><termdef id="dt-cdsection" term="CDATA Section"><term>CDATA sections</term> 928may occur 929anywhere character data may occur; they are 930used to escape blocks of text containing characters which would 931otherwise be recognized as markup. CDATA sections begin with the 932string "<code><![CDATA[</code>" and end with the string 933"<code>]]></code>": 934<scrap lang="ebnf"> 935<head>CDATA Sections</head> 936<prod id="NT-CDSect"><lhs>CDSect</lhs> 937<rhs><nt def="NT-CDStart">CDStart</nt> 938<nt def="NT-CData">CData</nt> 939<nt def="NT-CDEnd">CDEnd</nt></rhs></prod> 940<prod id="NT-CDStart"><lhs>CDStart</lhs> 941<rhs>'<![CDATA['</rhs> 942</prod> 943<prod id="NT-CData"><lhs>CData</lhs> 944<rhs>(<nt def="NT-Char">Char</nt>* - 945(<nt def="NT-Char">Char</nt>* ']]>' <nt def="NT-Char">Char</nt>*)) 946</rhs> 947</prod> 948<prod id="NT-CDEnd"><lhs>CDEnd</lhs> 949<rhs>']]>'</rhs> 950</prod> 951</scrap> 952 953Within a CDATA section, only the <nt def="NT-CDEnd">CDEnd</nt> string is 954recognized as markup, so that left angle brackets and ampersands may occur in 955their literal form; they need not (and cannot) be escaped using 956"<code>&lt;</code>" and "<code>&amp;</code>". CDATA sections 957cannot nest.</termdef> 958</p> 959 960<p>An example of a CDATA section, in which "<code><greeting></code>" and 961"<code></greeting></code>" 962are recognized as <termref def="dt-chardata">character data</termref>, not 963<termref def="dt-markup">markup</termref>: 964<eg><![CDATA[<greeting>Hello, world!</greeting>]]></eg> 965</p> 966</div2> 967 968<div2 id="sec-prolog-dtd"> 969<head>Prolog and Document Type Declaration</head> 970 971<p><termdef id="dt-xmldecl" term="XML Declaration">XML documents 972may, and should, 973begin with an <term>XML declaration</term> which specifies 974the version of 975XML being used.</termdef> 976For example, the following is a complete XML document, <termref def="dt-wellformed">well-formed</termref> but not 977<termref def="dt-valid">valid</termref>: 978<eg><![CDATA[<?xml version="1.0"?> 979<greeting>Hello, world!</greeting> 980]]></eg> 981and so is this: 982<eg><![CDATA[<greeting>Hello, world!</greeting> 983]]></eg> 984</p> 985 986<p>The version number "<code>1.0</code>" should be used to indicate 987conformance to this version of this specification; it is an error 988for a document to use the value "<code>1.0</code>" 989if it does not conform to this version of this specification. 990It is the intent 991of the XML working group to give later versions of this specification 992numbers other than "<code>1.0</code>", but this intent does not 993indicate a 994commitment to produce any future versions of XML, nor if any are produced, to 995use any particular numbering scheme. 996Since future versions are not ruled out, this construct is provided 997as a means to allow the possibility of automatic version recognition, should 998it become necessary. 999Processors may signal an error if they receive documents labeled with 1000versions they do not support. 1001</p> 1002<p>The function of the markup in an XML document is to describe its 1003storage and logical structure and to associate attribute-value pairs 1004with its logical structures. XML provides a mechanism, the <termref def="dt-doctype">document type declaration</termref>, to define 1005constraints on the logical structure and to support the use of 1006predefined storage units. 1007 1008<termdef id="dt-valid" term="Validity">An XML document is 1009<term>valid</term> if it has an associated document type 1010declaration and if the document 1011complies with the constraints expressed in it.</termdef></p> 1012<p>The document type declaration must appear before 1013the first <termref def="dt-element">element</termref> in the document. 1014<scrap lang="ebnf" id="xmldoc"> 1015<head>Prolog</head> 1016<prodgroup pcw2="6" pcw4="17.5" pcw5="9"> 1017<prod id="NT-prolog"><lhs>prolog</lhs> 1018<rhs><nt def="NT-XMLDecl">XMLDecl</nt>? 1019<nt def="NT-Misc">Misc</nt>* 1020(<nt def="NT-doctypedecl">doctypedecl</nt> 1021<nt def="NT-Misc">Misc</nt>*)?</rhs></prod> 1022<prod id="NT-XMLDecl"><lhs>XMLDecl</lhs> 1023<rhs>&xmlpio; 1024<nt def="NT-VersionInfo">VersionInfo</nt> 1025<nt def="NT-EncodingDecl">EncodingDecl</nt>? 1026<nt def="NT-SDDecl">SDDecl</nt>? 1027<nt def="NT-S">S</nt>? 1028&pic;</rhs> 1029</prod> 1030<prod id="NT-VersionInfo"><lhs>VersionInfo</lhs> 1031<rhs><nt def="NT-S">S</nt> 'version' <nt def="NT-Eq">Eq</nt> 1032(' <nt def="NT-VersionNum">VersionNum</nt> ' 1033| " <nt def="NT-VersionNum">VersionNum</nt> ")</rhs> 1034</prod> 1035<prod id="NT-Eq"><lhs>Eq</lhs> 1036<rhs><nt def="NT-S">S</nt>? '=' <nt def="NT-S">S</nt>?</rhs></prod> 1037<prod id="NT-VersionNum"> 1038<lhs>VersionNum</lhs> 1039<rhs>([a-zA-Z0-9_.:] | '-')+</rhs> 1040</prod> 1041<prod id="NT-Misc"><lhs>Misc</lhs> 1042<rhs><nt def="NT-Comment">Comment</nt> | <nt def="NT-PI">PI</nt> | 1043<nt def="NT-S">S</nt></rhs></prod> 1044</prodgroup> 1045</scrap></p> 1046 1047<p><termdef id="dt-doctype" term="Document Type Declaration">The XML 1048<term>document type declaration</term> 1049contains or points to 1050<termref def="dt-markupdecl">markup declarations</termref> 1051that provide a grammar for a 1052class of documents. 1053This grammar is known as a document type definition, 1054or <term>DTD</term>. 1055The document type declaration can point to an external subset (a 1056special kind of 1057<termref def="dt-extent">external entity</termref>) containing markup 1058declarations, or can 1059contain the markup declarations directly in an internal subset, or can do 1060both. 1061The DTD for a document consists of both subsets taken 1062together.</termdef> 1063</p> 1064<p><termdef id="dt-markupdecl" term="markup declaration"> 1065A <term>markup declaration</term> is 1066an <termref def="dt-eldecl">element type declaration</termref>, 1067an <termref def="dt-attdecl">attribute-list declaration</termref>, 1068an <termref def="dt-entdecl">entity declaration</termref>, or 1069a <termref def="dt-notdecl">notation declaration</termref>. 1070</termdef> 1071These declarations may be contained in whole or in part 1072within <termref def="dt-PE">parameter entities</termref>, 1073as described in the well-formedness and validity constraints below. 1074For fuller information, see 1075<specref ref="sec-physical-struct"/>.</p> 1076<scrap lang="ebnf" id="dtd"> 1077<head>Document Type Definition</head> 1078<prodgroup pcw2="6" pcw4="17.5" pcw5="9"> 1079<prod id="NT-doctypedecl"><lhs>doctypedecl</lhs> 1080<rhs>'<!DOCTYPE' <nt def="NT-S">S</nt> 1081<nt def="NT-Name">Name</nt> (<nt def="NT-S">S</nt> 1082<nt def="NT-ExternalID">ExternalID</nt>)? 1083<nt def="NT-S">S</nt>? ('[' 1084(<nt def="NT-markupdecl">markupdecl</nt> 1085| <nt def="NT-PEReference">PEReference</nt> 1086| <nt def="NT-S">S</nt>)* 1087']' 1088<nt def="NT-S">S</nt>?)? '>'</rhs> 1089<vc def="vc-roottype"/> 1090</prod> 1091<prod id="NT-markupdecl"><lhs>markupdecl</lhs> 1092<rhs><nt def="NT-elementdecl">elementdecl</nt> 1093| <nt def="NT-AttlistDecl">AttlistDecl</nt> 1094| <nt def="NT-EntityDecl">EntityDecl</nt> 1095| <nt def="NT-NotationDecl">NotationDecl</nt> 1096| <nt def="NT-PI">PI</nt> 1097| <nt def="NT-Comment">Comment</nt> 1098</rhs> 1099<vc def="vc-PEinMarkupDecl"/> 1100<wfc def="wfc-PEinInternalSubset"/> 1101</prod> 1102 1103</prodgroup> 1104</scrap> 1105 1106<p>The markup declarations may be made up in whole or in part of 1107the <termref def="dt-repltext">replacement text</termref> of 1108<termref def="dt-PE">parameter entities</termref>. 1109The productions later in this specification for 1110individual nonterminals (<nt def="NT-elementdecl">elementdecl</nt>, 1111<nt def="NT-AttlistDecl">AttlistDecl</nt>, and so on) describe 1112the declarations <emph>after</emph> all the parameter entities have been 1113<termref def="dt-include">included</termref>.</p> 1114 1115<vcnote id="vc-roottype"> 1116<head>Root Element Type</head> 1117<p> 1118The <nt def="NT-Name">Name</nt> in the document type declaration must 1119match the element type of the <termref def="dt-root">root element</termref>. 1120</p> 1121</vcnote> 1122 1123<vcnote id="vc-PEinMarkupDecl"> 1124<head>Proper Declaration/PE Nesting</head> 1125<p>Parameter-entity 1126<termref def="dt-repltext">replacement text</termref> must be properly nested 1127with markup declarations. 1128That is to say, if either the first character 1129or the last character of a markup 1130declaration (<nt def="NT-markupdecl">markupdecl</nt> above) 1131is contained in the replacement text for a 1132<termref def="dt-PERef">parameter-entity reference</termref>, 1133both must be contained in the same replacement text.</p> 1134</vcnote> 1135<wfcnote id="wfc-PEinInternalSubset"> 1136<head>PEs in Internal Subset</head> 1137<p>In the internal DTD subset, 1138<termref def="dt-PERef">parameter-entity references</termref> 1139can occur only where markup declarations can occur, not 1140within markup declarations. (This does not apply to 1141references that occur in 1142external parameter entities or to the external subset.) 1143</p> 1144</wfcnote> 1145<p> 1146Like the internal subset, the external subset and 1147any external parameter entities referred to in the DTD 1148must consist of a series of complete markup declarations of the types 1149allowed by the non-terminal symbol 1150<nt def="NT-markupdecl">markupdecl</nt>, interspersed with white space 1151or <termref def="dt-PERef">parameter-entity references</termref>. 1152However, portions of the contents 1153of the 1154external subset or of external parameter entities may conditionally be ignored 1155by using 1156the <termref def="dt-cond-section">conditional section</termref> 1157construct; this is not allowed in the internal subset. 1158 1159<scrap id="ext-Subset"> 1160<head>External Subset</head> 1161<prodgroup pcw2="6" pcw4="17.5" pcw5="9"> 1162<prod id="NT-extSubset"><lhs>extSubset</lhs> 1163<rhs><nt def="NT-TextDecl">TextDecl</nt>? 1164<nt def="NT-extSubsetDecl">extSubsetDecl</nt></rhs></prod> 1165<prod id="NT-extSubsetDecl"><lhs>extSubsetDecl</lhs> 1166<rhs>( 1167<nt def="NT-markupdecl">markupdecl</nt> 1168| <nt def="NT-conditionalSect">conditionalSect</nt> 1169| <nt def="NT-PEReference">PEReference</nt> 1170| <nt def="NT-S">S</nt> 1171)*</rhs> 1172</prod> 1173</prodgroup> 1174</scrap></p> 1175<p>The external subset and external parameter entities also differ 1176from the internal subset in that in them, 1177<termref def="dt-PERef">parameter-entity references</termref> 1178are permitted <emph>within</emph> markup declarations, 1179not only <emph>between</emph> markup declarations.</p> 1180<p>An example of an XML document with a document type declaration: 1181<eg><![CDATA[<?xml version="1.0"?> 1182<!DOCTYPE greeting SYSTEM "hello.dtd"> 1183<greeting>Hello, world!</greeting> 1184]]></eg> 1185The <termref def="dt-sysid">system identifier</termref> 1186"<code>hello.dtd</code>" gives the URI of a DTD for the document.</p> 1187<p>The declarations can also be given locally, as in this 1188example: 1189<eg><![CDATA[<?xml version="1.0" encoding="UTF-8" ?> 1190<!DOCTYPE greeting [ 1191 <!ELEMENT greeting (#PCDATA)> 1192]> 1193<greeting>Hello, world!</greeting> 1194]]></eg> 1195If both the external and internal subsets are used, the 1196internal subset is considered to occur before the external subset. 1197<!-- 'is considered to'? boo. whazzat mean? --> 1198This has the effect that entity and attribute-list declarations in the 1199internal subset take precedence over those in the external subset. 1200</p> 1201</div2> 1202 1203<div2 id="sec-rmd"> 1204<head>Standalone Document Declaration</head> 1205<p>Markup declarations can affect the content of the document, 1206as passed from an <termref def="dt-xml-proc">XML processor</termref> 1207to an application; examples are attribute defaults and entity 1208declarations. 1209The standalone document declaration, 1210which may appear as a component of the XML declaration, signals 1211whether or not there are such declarations which appear external to 1212the <termref def="dt-docent">document entity</termref>. 1213<scrap lang="ebnf" id="fulldtd"> 1214<head>Standalone Document Declaration</head> 1215<prodgroup pcw2="4" pcw4="19.5" pcw5="9"> 1216<prod id="NT-SDDecl"><lhs>SDDecl</lhs> 1217<rhs> 1218<nt def="NT-S">S</nt> 1219'standalone' <nt def="NT-Eq">Eq</nt> 1220(("'" ('yes' | 'no') "'") | ('"' ('yes' | 'no') '"')) 1221</rhs> 1222<vc def="vc-check-rmd"/></prod> 1223</prodgroup> 1224</scrap></p> 1225<p> 1226In a standalone document declaration, the value "<code>yes</code>" indicates 1227that there 1228are no markup declarations external to the <termref def="dt-docent">document 1229entity</termref> (either in the DTD external subset, or in an 1230external parameter entity referenced from the internal subset) 1231which affect the information passed from the XML processor to 1232the application. 1233The value "<code>no</code>" indicates that there are or may be such 1234external markup declarations. 1235Note that the standalone document declaration only 1236denotes the presence of external <emph>declarations</emph>; the presence, in a 1237document, of 1238references to external <emph>entities</emph>, when those entities are 1239internally declared, 1240does not change its standalone status.</p> 1241<p>If there are no external markup declarations, the standalone document 1242declaration has no meaning. 1243If there are external markup declarations but there is no standalone 1244document declaration, the value "<code>no</code>" is assumed.</p> 1245<p>Any XML document for which <code>standalone="no"</code> holds can 1246be converted algorithmically to a standalone document, 1247which may be desirable for some network delivery applications.</p> 1248<vcnote id="vc-check-rmd"> 1249<head>Standalone Document Declaration</head> 1250<p>The standalone document declaration must have 1251the value "<code>no</code>" if any external markup declarations 1252contain declarations of:</p><ulist> 1253<item><p>attributes with <termref def="dt-default">default</termref> values, if 1254elements to which 1255these attributes apply appear in the document without 1256specifications of values for these attributes, or</p></item> 1257<item><p>entities (other than &magicents;), 1258if <termref def="dt-entref">references</termref> to those 1259entities appear in the document, or</p> 1260</item> 1261<item><p>attributes with values subject to 1262<titleref href="AVNormalize">normalization</titleref>, where the 1263attribute appears in the document with a value which will 1264change as a result of normalization, or</p> 1265</item> 1266<item> 1267<p>element types with <termref def="dt-elemcontent">element content</termref>, 1268if white space occurs 1269directly within any instance of those types. 1270</p></item> 1271</ulist> 1272 1273</vcnote> 1274<p>An example XML declaration with a standalone document declaration:<eg><?xml version="&XML.version;" standalone='yes'?></eg></p> 1275</div2> 1276<div2 id="sec-white-space"> 1277<head>White Space Handling</head> 1278 1279<p>In editing XML documents, it is often convenient to use "white space" 1280(spaces, tabs, and blank lines, denoted by the nonterminal 1281<nt def="NT-S">S</nt> in this specification) to 1282set apart the markup for greater readability. Such white space is typically 1283not intended for inclusion in the delivered version of the document. 1284On the other hand, "significant" white space that should be preserved in the 1285delivered version is common, for example in poetry and 1286source code.</p> 1287<p>An <termref def="dt-xml-proc">XML processor</termref> 1288must always pass all characters in a document that are not 1289markup through to the application. A <termref def="dt-validating"> 1290validating XML processor</termref> must also inform the application 1291which of these characters constitute white space appearing 1292in <termref def="dt-elemcontent">element content</termref>. 1293</p> 1294<p>A special <termref def="dt-attr">attribute</termref> 1295named <kw>xml:space</kw> may be attached to an element 1296to signal an intention that in that element, 1297white space should be preserved by applications. 1298In valid documents, this attribute, like any other, must be 1299<termref def="dt-attdecl">declared</termref> if it is used. 1300When declared, it must be given as an 1301<termref def="dt-enumerated">enumerated type</termref> whose only 1302possible values are "<code>default</code>" and "<code>preserve</code>". 1303For example:<eg><![CDATA[ <!ATTLIST poem xml:space (default|preserve) 'preserve'>]]></eg></p> 1304<p>The value "<code>default</code>" signals that applications' 1305default white-space processing modes are acceptable for this element; the 1306value "<code>preserve</code>" indicates the intent that applications preserve 1307all the white space. 1308This declared intent is considered to apply to all elements within the content 1309of the element where it is specified, unless overriden with another instance 1310of the <kw>xml:space</kw> attribute. 1311</p> 1312<p>The <termref def="dt-root">root element</termref> of any document 1313is considered to have signaled no intentions as regards application space 1314handling, unless it provides a value for 1315this attribute or the attribute is declared with a default value. 1316</p> 1317 1318</div2> 1319<div2 id="sec-line-ends"> 1320<head>End-of-Line Handling</head> 1321<p>XML <termref def="dt-parsedent">parsed entities</termref> are often stored in 1322computer files which, for editing convenience, are organized into lines. 1323These lines are typically separated by some combination of the characters 1324carriage-return (#xD) and line-feed (#xA).</p> 1325<p>To simplify the tasks of <termref def="dt-app">applications</termref>, 1326wherever an external parsed entity or the literal entity value 1327of an internal parsed entity contains either the literal 1328two-character sequence "#xD#xA" or a standalone literal 1329#xD, an <termref def="dt-xml-proc">XML processor</termref> must 1330pass to the application the single character #xA. 1331(This behavior can 1332conveniently be produced by normalizing all 1333line breaks to #xA on input, before parsing.) 1334</p> 1335</div2> 1336<div2 id="sec-lang-tag"> 1337<head>Language Identification</head> 1338<p>In document processing, it is often useful to 1339identify the natural or formal language 1340in which the content is 1341written. 1342A special <termref def="dt-attr">attribute</termref> named 1343<kw>xml:lang</kw> may be inserted in 1344documents to specify the 1345language used in the contents and attribute values 1346of any element in an XML document. 1347In valid documents, this attribute, like any other, must be 1348<termref def="dt-attdecl">declared</termref> if it is used. 1349The values of the attribute are language identifiers as defined 1350by <bibref ref="RFC1766"/>, "Tags for the Identification of Languages": 1351<scrap lang="ebnf"> 1352<head>Language Identification</head> 1353<prod id="NT-LanguageID"><lhs>LanguageID</lhs> 1354<rhs><nt def="NT-Langcode">Langcode</nt> 1355('-' <nt def="NT-Subcode">Subcode</nt>)*</rhs></prod> 1356<prod id="NT-Langcode"><lhs>Langcode</lhs> 1357<rhs><nt def="NT-ISO639Code">ISO639Code</nt> | 1358<nt def="NT-IanaCode">IanaCode</nt> | 1359<nt def="NT-UserCode">UserCode</nt></rhs> 1360</prod> 1361<prod id="NT-ISO639Code"><lhs>ISO639Code</lhs> 1362<rhs>([a-z] | [A-Z]) ([a-z] | [A-Z])</rhs></prod> 1363<prod id="NT-IanaCode"><lhs>IanaCode</lhs> 1364<rhs>('i' | 'I') '-' ([a-z] | [A-Z])+</rhs></prod> 1365<prod id="NT-UserCode"><lhs>UserCode</lhs> 1366<rhs>('x' | 'X') '-' ([a-z] | [A-Z])+</rhs></prod> 1367<prod id="NT-Subcode"><lhs>Subcode</lhs> 1368<rhs>([a-z] | [A-Z])+</rhs></prod> 1369</scrap> 1370The <nt def="NT-Langcode">Langcode</nt> may be any of the following: 1371<ulist> 1372<item><p>a two-letter language code as defined by 1373<bibref ref="ISO639"/>, "Codes 1374for the representation of names of languages"</p></item> 1375<item><p>a language identifier registered with the Internet 1376Assigned Numbers Authority <bibref ref="IANA"/>; these begin with the 1377prefix "<code>i-</code>" (or "<code>I-</code>")</p></item> 1378<item><p>a language identifier assigned by the user, or agreed on 1379between parties in private use; these must begin with the 1380prefix "<code>x-</code>" or "<code>X-</code>" in order to ensure that they do not conflict 1381with names later standardized or registered with IANA</p></item> 1382</ulist></p> 1383<p>There may be any number of <nt def="NT-Subcode">Subcode</nt> segments; if 1384the first 1385subcode segment exists and the Subcode consists of two 1386letters, then it must be a country code from 1387<bibref ref="ISO3166"/>, "Codes 1388for the representation of names of countries." 1389If the first 1390subcode consists of more than two letters, it must be 1391a subcode for the language in question registered with IANA, 1392unless the <nt def="NT-Langcode">Langcode</nt> begins with the prefix 1393"<code>x-</code>" or 1394"<code>X-</code>". </p> 1395<p>It is customary to give the language code in lower case, and 1396the country code (if any) in upper case. 1397Note that these values, unlike other names in XML documents, 1398are case insensitive.</p> 1399<p>For example: 1400<eg><![CDATA[<p xml:lang="en">The quick brown fox jumps over the lazy dog.</p> 1401<p xml:lang="en-GB">What colour is it?</p> 1402<p xml:lang="en-US">What color is it?</p> 1403<sp who="Faust" desc='leise' xml:lang="de"> 1404 <l>Habe nun, ach! Philosophie,</l> 1405 <l>Juristerei, und Medizin</l> 1406 <l>und leider auch Theologie</l> 1407 <l>durchaus studiert mit hei�em Bem�h'n.</l> 1408 </sp>]]></eg></p> 1409<!--<p>The xml:lang value is considered to apply both to the contents of an 1410element and 1411(unless otherwise via attribute default values) to the 1412values of all of its attributes with free-text (CDATA) values. --> 1413<p>The intent declared with <kw>xml:lang</kw> is considered to apply to 1414all attributes and content of the element where it is specified, 1415unless overridden with an instance of <kw>xml:lang</kw> 1416on another element within that content.</p> 1417<!-- 1418If no 1419value is specified for xml:lang on an element, and no default value is 1420defined for it in the DTD, then the xml:lang attribute of any element 1421takes the same value it has in the parent element, if any. The two 1422technical terms in the following example both have the same effective 1423value for xml:lang: 1424 1425 <p xml:lang="en">Here the keywords are 1426 <term xml:lang="en">shift</term> and 1427 <term>reduce</term>. ...</p> 1428 1429The application, not the XML processor, is responsible for this ' 1430inheritance' of attribute values. 1431--> 1432<p>A simple declaration for <kw>xml:lang</kw> might take 1433the form 1434<eg>xml:lang NMTOKEN #IMPLIED</eg> 1435but specific default values may also be given, if appropriate. In a 1436collection of French poems for English students, with glosses and 1437notes in English, the xml:lang attribute might be declared this way: 1438<eg><![CDATA[ <!ATTLIST poem xml:lang NMTOKEN 'fr'> 1439 <!ATTLIST gloss xml:lang NMTOKEN 'en'> 1440 <!ATTLIST note xml:lang NMTOKEN 'en'>]]></eg> 1441</p> 1442 1443</div2> 1444</div1> 1445<!-- &Elements; --> 1446 1447<div1 id="sec-logical-struct"> 1448<head>Logical Structures</head> 1449 1450<p><termdef id="dt-element" term="Element">Each <termref def="dt-xml-doc">XML document</termref> contains one or more 1451<term>elements</term>, the boundaries of which are 1452either delimited by <termref def="dt-stag">start-tags</termref> 1453and <termref def="dt-etag">end-tags</termref>, or, for <termref def="dt-empty">empty</termref> elements, by an <termref def="dt-eetag">empty-element tag</termref>. Each element has a type, 1454identified by name, sometimes called its "generic 1455identifier" (GI), and may have a set of 1456attribute specifications.</termdef> Each attribute specification 1457has a <termref def="dt-attrname">name</termref> and a <termref def="dt-attrval">value</termref>. 1458</p> 1459<scrap lang="ebnf"><head>Element</head> 1460<prod id="NT-element"><lhs>element</lhs> 1461<rhs><nt def="NT-EmptyElemTag">EmptyElemTag</nt></rhs> 1462<rhs>| <nt def="NT-STag">STag</nt> <nt def="NT-content">content</nt> 1463<nt def="NT-ETag">ETag</nt></rhs> 1464<wfc def="GIMatch"/> 1465<vc def="elementvalid"/> 1466</prod> 1467</scrap> 1468<p>This specification does not constrain the semantics, use, or (beyond 1469syntax) names of the element types and attributes, except that names 1470beginning with a match to <code>(('X'|'x')('M'|'m')('L'|'l'))</code> 1471are reserved for standardization in this or future versions of this 1472specification. 1473</p> 1474<wfcnote id="GIMatch"> 1475<head>Element Type Match</head> 1476<p> 1477The <nt def="NT-Name">Name</nt> in an element's end-tag must match 1478the element type in 1479the start-tag. 1480</p> 1481</wfcnote> 1482<vcnote id="elementvalid"> 1483<head>Element Valid</head> 1484<p>An element is 1485valid if 1486there is a declaration matching 1487<nt def="NT-elementdecl">elementdecl</nt> where the 1488<nt def="NT-Name">Name</nt> matches the element type, and 1489one of the following holds:</p> 1490<olist> 1491<item><p>The declaration matches <kw>EMPTY</kw> and the element has no 1492<termref def="dt-content">content</termref>.</p></item> 1493<item><p>The declaration matches <nt def="NT-children">children</nt> and 1494the sequence of 1495<termref def="dt-parentchild">child elements</termref> 1496belongs to the language generated by the regular expression in 1497the content model, with optional white space (characters 1498matching the nonterminal <nt def="NT-S">S</nt>) between each pair 1499of child elements.</p></item> 1500<item><p>The declaration matches <nt def="NT-Mixed">Mixed</nt> and 1501the content consists of <termref def="dt-chardata">character 1502data</termref> and <termref def="dt-parentchild">child elements</termref> 1503whose types match names in the content model.</p></item> 1504<item><p>The declaration matches <kw>ANY</kw>, and the types 1505of any <termref def="dt-parentchild">child elements</termref> have 1506been declared.</p></item> 1507</olist> 1508</vcnote> 1509 1510<div2 id="sec-starttags"> 1511<head>Start-Tags, End-Tags, and Empty-Element Tags</head> 1512 1513<p><termdef id="dt-stag" term="Start-Tag">The beginning of every 1514non-empty XML element is marked by a <term>start-tag</term>. 1515<scrap lang="ebnf"> 1516<head>Start-tag</head> 1517<prodgroup pcw2="6" pcw4="15" pcw5="11.5"> 1518<prod id="NT-STag"><lhs>STag</lhs> 1519<rhs>'<' <nt def="NT-Name">Name</nt> 1520(<nt def="NT-S">S</nt> <nt def="NT-Attribute">Attribute</nt>)* 1521<nt def="NT-S">S</nt>? '>'</rhs> 1522<wfc def="uniqattspec"/> 1523</prod> 1524<prod id="NT-Attribute"><lhs>Attribute</lhs> 1525<rhs><nt def="NT-Name">Name</nt> <nt def="NT-Eq">Eq</nt> 1526<nt def="NT-AttValue">AttValue</nt></rhs> 1527<vc def="ValueType"/> 1528<wfc def="NoExternalRefs"/> 1529<wfc def="CleanAttrVals"/></prod> 1530</prodgroup> 1531</scrap> 1532The <nt def="NT-Name">Name</nt> in 1533the start- and end-tags gives the 1534element's <term>type</term>.</termdef> 1535<termdef id="dt-attr" term="Attribute"> 1536The <nt def="NT-Name">Name</nt>-<nt def="NT-AttValue">AttValue</nt> pairs are 1537referred to as 1538the <term>attribute specifications</term> of the element</termdef>, 1539<termdef id="dt-attrname" term="Attribute Name">with the 1540<nt def="NT-Name">Name</nt> in each pair 1541referred to as the <term>attribute name</term></termdef> and 1542<termdef id="dt-attrval" term="Attribute Value">the content of the 1543<nt def="NT-AttValue">AttValue</nt> (the text between the 1544<code>'</code> or <code>"</code> delimiters) 1545as the <term>attribute value</term>.</termdef> 1546</p> 1547<wfcnote id="uniqattspec"> 1548<head>Unique Att Spec</head> 1549<p> 1550No attribute name may appear more than once in the same start-tag 1551or empty-element tag. 1552</p> 1553</wfcnote> 1554<vcnote id="ValueType"> 1555<head>Attribute Value Type</head> 1556<p> 1557The attribute must have been declared; the value must be of the type 1558declared for it. 1559(For attribute types, see <specref ref="attdecls"/>.) 1560</p> 1561</vcnote> 1562<wfcnote id="NoExternalRefs"> 1563<head>No External Entity References</head> 1564<p> 1565Attribute values cannot contain direct or indirect entity references 1566to external entities. 1567</p> 1568</wfcnote> 1569<wfcnote id="CleanAttrVals"> 1570<head>No <code><</code> in Attribute Values</head> 1571<p>The <termref def="dt-repltext">replacement text</termref> of any entity 1572referred to directly or indirectly in an attribute 1573value (other than "<code>&lt;</code>") must not contain 1574a <code><</code>. 1575</p></wfcnote> 1576<p>An example of a start-tag: 1577<eg><termdef id="dt-dog" term="dog"></eg></p> 1578<p><termdef id="dt-etag" term="End Tag">The end of every element 1579that begins with a start-tag must 1580be marked by an <term>end-tag</term> 1581containing a name that echoes the element's type as given in the 1582start-tag: 1583<scrap lang="ebnf"> 1584<head>End-tag</head> 1585<prodgroup pcw2="6" pcw4="15" pcw5="11.5"> 1586<prod id="NT-ETag"><lhs>ETag</lhs> 1587<rhs>'</' <nt def="NT-Name">Name</nt> 1588<nt def="NT-S">S</nt>? '>'</rhs></prod> 1589</prodgroup> 1590</scrap> 1591</termdef></p> 1592<p>An example of an end-tag:<eg></termdef></eg></p> 1593<p><termdef id="dt-content" term="Content">The 1594<termref def="dt-text">text</termref> between the start-tag and 1595end-tag is called the element's 1596<term>content</term>: 1597<scrap lang="ebnf"> 1598<head>Content of Elements</head> 1599<prodgroup pcw2="6" pcw4="15" pcw5="11.5"> 1600<prod id="NT-content"><lhs>content</lhs> 1601<rhs>(<nt def="NT-element">element</nt> | <nt def="NT-CharData">CharData</nt> 1602| <nt def="NT-Reference">Reference</nt> | <nt def="NT-CDSect">CDSect</nt> 1603| <nt def="NT-PI">PI</nt> | <nt def="NT-Comment">Comment</nt>)*</rhs> 1604</prod> 1605</prodgroup> 1606</scrap> 1607</termdef></p> 1608<p><termdef id="dt-empty" term="Empty">If an element is <term>empty</term>, 1609it must be represented either by a start-tag immediately followed 1610by an end-tag or by an empty-element tag.</termdef> 1611<termdef id="dt-eetag" term="empty-element tag">An 1612<term>empty-element tag</term> takes a special form: 1613<scrap lang="ebnf"> 1614<head>Tags for Empty Elements</head> 1615<prodgroup pcw2="6" pcw4="15" pcw5="11.5"> 1616<prod id="NT-EmptyElemTag"><lhs>EmptyElemTag</lhs> 1617<rhs>'<' <nt def="NT-Name">Name</nt> (<nt def="NT-S">S</nt> 1618<nt def="NT-Attribute">Attribute</nt>)* <nt def="NT-S">S</nt>? 1619'/>'</rhs> 1620<wfc def="uniqattspec"/> 1621</prod> 1622</prodgroup> 1623</scrap> 1624</termdef></p> 1625<p>Empty-element tags may be used for any element which has no 1626content, whether or not it is declared using the keyword 1627<kw>EMPTY</kw>. 1628<termref def="dt-interop">For interoperability</termref>, the empty-element 1629tag must be used, and can only be used, for elements which are 1630<termref def="dt-eldecl">declared</termref> <kw>EMPTY</kw>.</p> 1631<p>Examples of empty elements: 1632<eg><IMG align="left" 1633 src="http://www.w3.org/Icons/WWW/w3c_home" /> 1634<br></br> 1635<br/></eg></p> 1636</div2> 1637 1638<div2 id="elemdecls"> 1639<head>Element Type Declarations</head> 1640 1641<p>The <termref def="dt-element">element</termref> structure of an 1642<termref def="dt-xml-doc">XML document</termref> may, for 1643<termref def="dt-valid">validation</termref> purposes, 1644be constrained 1645using element type and attribute-list declarations. 1646An element type declaration constrains the element's 1647<termref def="dt-content">content</termref>. 1648</p> 1649 1650<p>Element type declarations often constrain which element types can 1651appear as <termref def="dt-parentchild">children</termref> of the element. 1652At user option, an XML processor may issue a warning 1653when a declaration mentions an element type for which no declaration 1654is provided, but this is not an error.</p> 1655<p><termdef id="dt-eldecl" term="Element Type declaration">An <term>element 1656type declaration</term> takes the form: 1657<scrap lang="ebnf"> 1658<head>Element Type Declaration</head> 1659<prodgroup pcw2="5.5" pcw4="18" pcw5="9"> 1660<prod id="NT-elementdecl"><lhs>elementdecl</lhs> 1661<rhs>'<!ELEMENT' <nt def="NT-S">S</nt> 1662<nt def="NT-Name">Name</nt> 1663<nt def="NT-S">S</nt> 1664<nt def="NT-contentspec">contentspec</nt> 1665<nt def="NT-S">S</nt>? '>'</rhs> 1666<vc def="EDUnique"/></prod> 1667<prod id="NT-contentspec"><lhs>contentspec</lhs> 1668<rhs>'EMPTY' 1669| 'ANY' 1670| <nt def="NT-Mixed">Mixed</nt> 1671| <nt def="NT-children">children</nt> 1672</rhs> 1673</prod> 1674</prodgroup> 1675</scrap> 1676where the <nt def="NT-Name">Name</nt> gives the element type 1677being declared.</termdef> 1678</p> 1679 1680<vcnote id="EDUnique"> 1681<head>Unique Element Type Declaration</head> 1682<p> 1683No element type may be declared more than once. 1684</p> 1685</vcnote> 1686 1687<p>Examples of element type declarations: 1688<eg><!ELEMENT br EMPTY> 1689<!ELEMENT p (#PCDATA|emph)* > 1690<!ELEMENT %name.para; %content.para; > 1691<!ELEMENT container ANY></eg></p> 1692 1693<div3 id="sec-element-content"> 1694<head>Element Content</head> 1695 1696<p><termdef id="dt-elemcontent" term="Element content">An element <termref def="dt-stag">type</termref> has 1697<term>element content</term> when elements of that 1698type must contain only <termref def="dt-parentchild">child</termref> 1699elements (no character data), optionally separated by 1700white space (characters matching the nonterminal 1701<nt def="NT-S">S</nt>). 1702</termdef> 1703In this case, the 1704constraint includes a content model, a simple grammar governing 1705the allowed types of the child 1706elements and the order in which they are allowed to appear. 1707The grammar is built on 1708content particles (<nt def="NT-cp">cp</nt>s), which consist of names, 1709choice lists of content particles, or 1710sequence lists of content particles: 1711<scrap lang="ebnf"> 1712<head>Element-content Models</head> 1713<prodgroup pcw2="5.5" pcw4="16" pcw5="11"> 1714<prod id="NT-children"><lhs>children</lhs> 1715<rhs>(<nt def="NT-choice">choice</nt> 1716| <nt def="NT-seq">seq</nt>) 1717('?' | '*' | '+')?</rhs></prod> 1718<prod id="NT-cp"><lhs>cp</lhs> 1719<rhs>(<nt def="NT-Name">Name</nt> 1720| <nt def="NT-choice">choice</nt> 1721| <nt def="NT-seq">seq</nt>) 1722('?' | '*' | '+')?</rhs></prod> 1723<prod id="NT-choice"><lhs>choice</lhs> 1724<rhs>'(' <nt def="NT-S">S</nt>? cp 1725( <nt def="NT-S">S</nt>? '|' <nt def="NT-S">S</nt>? <nt def="NT-cp">cp</nt> )* 1726<nt def="NT-S">S</nt>? ')'</rhs> 1727<vc def="vc-PEinGroup"/></prod> 1728<prod id="NT-seq"><lhs>seq</lhs> 1729<rhs>'(' <nt def="NT-S">S</nt>? cp 1730( <nt def="NT-S">S</nt>? ',' <nt def="NT-S">S</nt>? <nt def="NT-cp">cp</nt> )* 1731<nt def="NT-S">S</nt>? ')'</rhs> 1732<vc def="vc-PEinGroup"/></prod> 1733 1734</prodgroup> 1735</scrap> 1736where each <nt def="NT-Name">Name</nt> is the type of an element which may 1737appear as a <termref def="dt-parentchild">child</termref>. 1738Any content 1739particle in a choice list may appear in the <termref def="dt-elemcontent">element content</termref> at the location where 1740the choice list appears in the grammar; 1741content particles occurring in a sequence list must each 1742appear in the <termref def="dt-elemcontent">element content</termref> in the 1743order given in the list. 1744The optional character following a name or list governs 1745whether the element or the content particles in the list may occur one 1746or more (<code>+</code>), zero or more (<code>*</code>), or zero or 1747one times (<code>?</code>). 1748The absence of such an operator means that the element or content particle 1749must appear exactly once. 1750This syntax 1751and meaning are identical to those used in the productions in this 1752specification.</p> 1753<p> 1754The content of an element matches a content model if and only if it is 1755possible to trace out a path through the content model, obeying the 1756sequence, choice, and repetition operators and matching each element in 1757the content against an element type in the content model. <termref def="dt-compat">For compatibility</termref>, it is an error 1758if an element in the document can 1759match more than one occurrence of an element type in the content model. 1760For more information, see <specref ref="determinism"/>. 1761<!-- appendix <specref ref="determinism"/>. --> 1762<!-- appendix on deterministic content models. --> 1763</p> 1764<vcnote id="vc-PEinGroup"> 1765<head>Proper Group/PE Nesting</head> 1766<p>Parameter-entity 1767<termref def="dt-repltext">replacement text</termref> must be properly nested 1768with parenthetized groups. 1769That is to say, if either of the opening or closing parentheses 1770in a <nt def="NT-choice">choice</nt>, <nt def="NT-seq">seq</nt>, or 1771<nt def="NT-Mixed">Mixed</nt> construct 1772is contained in the replacement text for a 1773<termref def="dt-PERef">parameter entity</termref>, 1774both must be contained in the same replacement text.</p> 1775<p><termref def="dt-interop">For interoperability</termref>, 1776if a parameter-entity reference appears in a 1777<nt def="NT-choice">choice</nt>, <nt def="NT-seq">seq</nt>, or 1778<nt def="NT-Mixed">Mixed</nt> construct, its replacement text 1779should not be empty, and 1780neither the first nor last non-blank 1781character of the replacement text should be a connector 1782(<code>|</code> or <code>,</code>). 1783</p> 1784</vcnote> 1785<p>Examples of element-content models: 1786<eg><!ELEMENT spec (front, body, back?)> 1787<!ELEMENT div1 (head, (p | list | note)*, div2*)> 1788<!ELEMENT dictionary-body (%div.mix; | %dict.mix;)*></eg></p> 1789</div3> 1790 1791<div3 id="sec-mixed-content"> 1792<head>Mixed Content</head> 1793 1794<p><termdef id="dt-mixed" term="Mixed Content">An element 1795<termref def="dt-stag">type</termref> has 1796<term>mixed content</term> when elements of that type may contain 1797character data, optionally interspersed with 1798<termref def="dt-parentchild">child</termref> elements.</termdef> 1799In this case, the types of the child elements 1800may be constrained, but not their order or their number of occurrences: 1801<scrap lang="ebnf"> 1802<head>Mixed-content Declaration</head> 1803<prodgroup pcw2="5.5" pcw4="16" pcw5="11"> 1804<prod id="NT-Mixed"><lhs>Mixed</lhs> 1805<rhs>'(' <nt def="NT-S">S</nt>? 1806'#PCDATA' 1807(<nt def="NT-S">S</nt>? 1808'|' 1809<nt def="NT-S">S</nt>? 1810<nt def="NT-Name">Name</nt>)* 1811<nt def="NT-S">S</nt>? 1812')*' </rhs> 1813<rhs>| '(' <nt def="NT-S">S</nt>? '#PCDATA' <nt def="NT-S">S</nt>? ')' 1814</rhs><vc def="vc-PEinGroup"/> 1815<vc def="vc-MixedChildrenUnique"/> 1816</prod> 1817 1818</prodgroup> 1819</scrap> 1820where the <nt def="NT-Name">Name</nt>s give the types of elements 1821that may appear as children. 1822</p> 1823<vcnote id="vc-MixedChildrenUnique"> 1824<head>No Duplicate Types</head> 1825<p>The same name must not appear more than once in a single mixed-content 1826declaration. 1827</p></vcnote> 1828<p>Examples of mixed content declarations: 1829<eg><!ELEMENT p (#PCDATA|a|ul|b|i|em)*> 1830<!ELEMENT p (#PCDATA | %font; | %phrase; | %special; | %form;)* > 1831<!ELEMENT b (#PCDATA)></eg></p> 1832</div3> 1833</div2> 1834 1835<div2 id="attdecls"> 1836<head>Attribute-List Declarations</head> 1837 1838<p><termref def="dt-attr">Attributes</termref> are used to associate 1839name-value pairs with <termref def="dt-element">elements</termref>. 1840Attribute specifications may appear only within <termref def="dt-stag">start-tags</termref> 1841and <termref def="dt-eetag">empty-element tags</termref>; 1842thus, the productions used to 1843recognize them appear in <specref ref="sec-starttags"/>. 1844Attribute-list 1845declarations may be used: 1846<ulist> 1847<item><p>To define the set of attributes pertaining to a given 1848element type.</p></item> 1849<item><p>To establish type constraints for these 1850attributes.</p></item> 1851<item><p>To provide <termref def="dt-default">default values</termref> 1852for attributes.</p></item> 1853</ulist> 1854</p> 1855<p><termdef id="dt-attdecl" term="Attribute-List Declaration"> 1856<term>Attribute-list declarations</term> specify the name, data type, and default 1857value (if any) of each attribute associated with a given element type: 1858<scrap lang="ebnf"> 1859<head>Attribute-list Declaration</head> 1860<prod id="NT-AttlistDecl"><lhs>AttlistDecl</lhs> 1861<rhs>'<!ATTLIST' <nt def="NT-S">S</nt> 1862<nt def="NT-Name">Name</nt> 1863<nt def="NT-AttDef">AttDef</nt>* 1864<nt def="NT-S">S</nt>? '>'</rhs> 1865</prod> 1866<prod id="NT-AttDef"><lhs>AttDef</lhs> 1867<rhs><nt def="NT-S">S</nt> <nt def="NT-Name">Name</nt> 1868<nt def="NT-S">S</nt> <nt def="NT-AttType">AttType</nt> 1869<nt def="NT-S">S</nt> <nt def="NT-DefaultDecl">DefaultDecl</nt></rhs> 1870</prod> 1871</scrap> 1872The <nt def="NT-Name">Name</nt> in the 1873<nt def="NT-AttlistDecl">AttlistDecl</nt> rule is the type of an element. At 1874user option, an XML processor may issue a warning if attributes are 1875declared for an element type not itself declared, but this is not an 1876error. The <nt def="NT-Name">Name</nt> in the 1877<nt def="NT-AttDef">AttDef</nt> rule is 1878the name of the attribute.</termdef></p> 1879<p> 1880When more than one <nt def="NT-AttlistDecl">AttlistDecl</nt> is provided for a 1881given element type, the contents of all those provided are merged. When 1882more than one definition is provided for the same attribute of a 1883given element type, the first declaration is binding and later 1884declarations are ignored. 1885<termref def="dt-interop">For interoperability,</termref> writers of DTDs 1886may choose to provide at most one attribute-list declaration 1887for a given element type, at most one attribute definition 1888for a given attribute name, and at least one attribute definition 1889in each attribute-list declaration. 1890For interoperability, an XML processor may at user option 1891issue a warning when more than one attribute-list declaration is 1892provided for a given element type, or more than one attribute definition 1893is provided 1894for a given attribute, but this is not an error. 1895</p> 1896 1897<div3 id="sec-attribute-types"> 1898<head>Attribute Types</head> 1899 1900<p>XML attribute types are of three kinds: a string type, a 1901set of tokenized types, and enumerated types. The string type may take 1902any literal string as a value; the tokenized types have varying lexical 1903and semantic constraints, as noted: 1904<scrap lang="ebnf"> 1905<head>Attribute Types</head> 1906<prodgroup pcw4="14" pcw5="11.5"> 1907<prod id="NT-AttType"><lhs>AttType</lhs> 1908<rhs><nt def="NT-StringType">StringType</nt> 1909| <nt def="NT-TokenizedType">TokenizedType</nt> 1910| <nt def="NT-EnumeratedType">EnumeratedType</nt> 1911</rhs> 1912</prod> 1913<prod id="NT-StringType"><lhs>StringType</lhs> 1914<rhs>'CDATA'</rhs> 1915</prod> 1916<prod id="NT-TokenizedType"><lhs>TokenizedType</lhs> 1917<rhs>'ID'</rhs> 1918<vc def="id"/> 1919<vc def="one-id-per-el"/> 1920<vc def="id-default"/> 1921<rhs>| 'IDREF'</rhs> 1922<vc def="idref"/> 1923<rhs>| 'IDREFS'</rhs> 1924<vc def="idref"/> 1925<rhs>| 'ENTITY'</rhs> 1926<vc def="entname"/> 1927<rhs>| 'ENTITIES'</rhs> 1928<vc def="entname"/> 1929<rhs>| 'NMTOKEN'</rhs> 1930<vc def="nmtok"/> 1931<rhs>| 'NMTOKENS'</rhs> 1932<vc def="nmtok"/></prod> 1933</prodgroup> 1934</scrap> 1935</p> 1936<vcnote id="id"> 1937<head>ID</head> 1938<p> 1939Values of type <kw>ID</kw> must match the 1940<nt def="NT-Name">Name</nt> production. 1941A name must not appear more than once in 1942an XML document as a value of this type; i.e., ID values must uniquely 1943identify the elements which bear them. 1944</p> 1945</vcnote> 1946<vcnote id="one-id-per-el"> 1947<head>One ID per Element Type</head> 1948<p>No element type may have more than one ID attribute specified.</p> 1949</vcnote> 1950<vcnote id="id-default"> 1951<head>ID Attribute Default</head> 1952<p>An ID attribute must have a declared default of <kw>#IMPLIED</kw> or 1953<kw>#REQUIRED</kw>.</p> 1954</vcnote> 1955<vcnote id="idref"> 1956<head>IDREF</head> 1957<p> 1958Values of type <kw>IDREF</kw> must match 1959the <nt def="NT-Name">Name</nt> production, and 1960values of type <kw>IDREFS</kw> must match 1961<nt def="NT-Names">Names</nt>; 1962each <nt def="NT-Name">Name</nt> must match the value of an ID attribute on 1963some element in the XML document; i.e. <kw>IDREF</kw> values must 1964match the value of some ID attribute. 1965</p> 1966</vcnote> 1967<vcnote id="entname"> 1968<head>Entity Name</head> 1969<p> 1970Values of type <kw>ENTITY</kw> 1971must match the <nt def="NT-Name">Name</nt> production, 1972values of type <kw>ENTITIES</kw> must match 1973<nt def="NT-Names">Names</nt>; 1974each <nt def="NT-Name">Name</nt> must 1975match the 1976name of an <termref def="dt-unparsed">unparsed entity</termref> declared in the 1977<termref def="dt-doctype">DTD</termref>. 1978</p> 1979</vcnote> 1980<vcnote id="nmtok"> 1981<head>Name Token</head> 1982<p> 1983Values of type <kw>NMTOKEN</kw> must match the 1984<nt def="NT-Nmtoken">Nmtoken</nt> production; 1985values of type <kw>NMTOKENS</kw> must 1986match <termref def="NT-Nmtokens">Nmtokens</termref>. 1987</p> 1988</vcnote> 1989<!-- why? 1990<p>The XML processor must normalize attribute values before 1991passing them to the application, as described in 1992<specref ref="AVNormalize"/>.</p>--> 1993<p><termdef id="dt-enumerated" term="Enumerated Attribute Values"><term>Enumerated attributes</term> can take one 1994of a list of values provided in the declaration</termdef>. There are two 1995kinds of enumerated types: 1996<scrap lang="ebnf"> 1997<head>Enumerated Attribute Types</head> 1998<prod id="NT-EnumeratedType"><lhs>EnumeratedType</lhs> 1999<rhs><nt def="NT-NotationType">NotationType</nt> 2000| <nt def="NT-Enumeration">Enumeration</nt> 2001</rhs></prod> 2002<prod id="NT-NotationType"><lhs>NotationType</lhs> 2003<rhs>'NOTATION' 2004<nt def="NT-S">S</nt> 2005'(' 2006<nt def="NT-S">S</nt>? 2007<nt def="NT-Name">Name</nt> 2008(<nt def="NT-S">S</nt>? '|' <nt def="NT-S">S</nt>? 2009<nt def="NT-Name">Name</nt>)* 2010<nt def="NT-S">S</nt>? ')' 2011</rhs> 2012<vc def="notatn"/></prod> 2013<prod id="NT-Enumeration"><lhs>Enumeration</lhs> 2014<rhs>'(' <nt def="NT-S">S</nt>? 2015<nt def="NT-Nmtoken">Nmtoken</nt> 2016(<nt def="NT-S">S</nt>? '|' 2017<nt def="NT-S">S</nt>? 2018<nt def="NT-Nmtoken">Nmtoken</nt>)* 2019<nt def="NT-S">S</nt>? 2020')'</rhs> 2021<vc def="enum"/></prod> 2022</scrap> 2023A <kw>NOTATION</kw> attribute identifies a 2024<termref def="dt-notation">notation</termref>, declared in the 2025DTD with associated system and/or public identifiers, to 2026be used in interpreting the element to which the attribute 2027is attached. 2028</p> 2029 2030<vcnote id="notatn"> 2031<head>Notation Attributes</head> 2032<p> 2033Values of this type must match 2034one of the <titleref href="Notations">notation</titleref> names included in 2035the declaration; all notation names in the declaration must 2036be declared. 2037</p> 2038</vcnote> 2039<vcnote id="enum"> 2040<head>Enumeration</head> 2041<p> 2042Values of this type 2043must match one of the <nt def="NT-Nmtoken">Nmtoken</nt> tokens in the 2044declaration. 2045</p> 2046</vcnote> 2047<p><termref def="dt-interop">For interoperability,</termref> the same 2048<nt def="NT-Nmtoken">Nmtoken</nt> should not occur more than once in the 2049enumerated attribute types of a single element type. 2050</p> 2051</div3> 2052 2053<div3 id="sec-attr-defaults"> 2054<head>Attribute Defaults</head> 2055 2056<p>An <termref def="dt-attdecl">attribute declaration</termref> provides 2057information on whether 2058the attribute's presence is required, and if not, how an XML processor should 2059react if a declared attribute is absent in a document. 2060<scrap lang="ebnf"> 2061<head>Attribute Defaults</head> 2062<prodgroup pcw4="14" pcw5="11.5"> 2063<prod id="NT-DefaultDecl"><lhs>DefaultDecl</lhs> 2064<rhs>'#REQUIRED' 2065| '#IMPLIED' </rhs> 2066<rhs>| (('#FIXED' S)? <nt def="NT-AttValue">AttValue</nt>)</rhs> 2067<vc def="RequiredAttr"/> 2068<vc def="defattrvalid"/> 2069<wfc def="CleanAttrVals"/> 2070<vc def="FixedAttr"/> 2071</prod> 2072</prodgroup> 2073</scrap> 2074 2075</p> 2076<p>In an attribute declaration, <kw>#REQUIRED</kw> means that the 2077attribute must always be provided, <kw>#IMPLIED</kw> that no default 2078value is provided. 2079<!-- not any more!! 2080<kw>#IMPLIED</kw> means that if the attribute is omitted 2081from an element of this type, 2082the XML processor must inform the application 2083that no value was specified; no constraint is placed on the behavior 2084of the application. --> 2085<termdef id="dt-default" term="Attribute Default">If the 2086declaration 2087is neither <kw>#REQUIRED</kw> nor <kw>#IMPLIED</kw>, then the 2088<nt def="NT-AttValue">AttValue</nt> value contains the declared 2089<term>default</term> value; the <kw>#FIXED</kw> keyword states that 2090the attribute must always have the default value. 2091If a default value 2092is declared, when an XML processor encounters an omitted attribute, it 2093is to behave as though the attribute were present with 2094the declared default value.</termdef></p> 2095<vcnote id="RequiredAttr"> 2096<head>Required Attribute</head> 2097<p>If the default declaration is the keyword <kw>#REQUIRED</kw>, then 2098the attribute must be specified for 2099all elements of the type in the attribute-list declaration. 2100</p></vcnote> 2101<vcnote id="defattrvalid"> 2102<head>Attribute Default Legal</head> 2103<p> 2104The declared 2105default value must meet the lexical constraints of the declared attribute type. 2106</p> 2107</vcnote> 2108<vcnote id="FixedAttr"> 2109<head>Fixed Attribute Default</head> 2110<p>If an attribute has a default value declared with the 2111<kw>#FIXED</kw> keyword, instances of that attribute must 2112match the default value. 2113</p></vcnote> 2114 2115<p>Examples of attribute-list declarations: 2116<eg><!ATTLIST termdef 2117 id ID #REQUIRED 2118 name CDATA #IMPLIED> 2119<!ATTLIST list 2120 type (bullets|ordered|glossary) "ordered"> 2121<!ATTLIST form 2122 method CDATA #FIXED "POST"></eg></p> 2123</div3> 2124<div3 id="AVNormalize"> 2125<head>Attribute-Value Normalization</head> 2126<p>Before the value of an attribute is passed to the application 2127or checked for validity, the 2128XML processor must normalize it as follows: 2129<ulist> 2130<item><p>a character reference is processed by appending the referenced 2131character to the attribute value</p></item> 2132<item><p>an entity reference is processed by recursively processing the 2133replacement text of the entity</p></item> 2134<item><p>a whitespace character (#x20, #xD, #xA, #x9) is processed by 2135appending #x20 to the normalized value, except that only a single #x20 2136is appended for a "#xD#xA" sequence that is part of an external 2137parsed entity or the literal entity value of an internal parsed 2138entity</p></item> 2139<item><p>other characters are processed by appending them to the normalized 2140value</p> 2141</item></ulist> 2142</p> 2143<p>If the declared value is not CDATA, then the XML processor must 2144further process the normalized attribute value by discarding any 2145leading and trailing space (#x20) characters, and by replacing 2146sequences of space (#x20) characters by a single space (#x20) 2147character.</p> 2148<p> 2149All attributes for which no declaration has been read should be treated 2150by a non-validating parser as if declared 2151<kw>CDATA</kw>. 2152</p> 2153</div3> 2154</div2> 2155<div2 id="sec-condition-sect"> 2156<head>Conditional Sections</head> 2157<p><termdef id="dt-cond-section" term="conditional section"> 2158<term>Conditional sections</term> are portions of the 2159<termref def="dt-doctype">document type declaration external subset</termref> 2160which are 2161included in, or excluded from, the logical structure of the DTD based on 2162the keyword which governs them.</termdef> 2163<scrap lang="ebnf"> 2164<head>Conditional Section</head> 2165<prodgroup pcw2="9" pcw4="14.5"> 2166<prod id="NT-conditionalSect"><lhs>conditionalSect</lhs> 2167<rhs><nt def="NT-includeSect">includeSect</nt> 2168| <nt def="NT-ignoreSect">ignoreSect</nt> 2169</rhs> 2170</prod> 2171<prod id="NT-includeSect"><lhs>includeSect</lhs> 2172<rhs>'<![' S? 'INCLUDE' S? '[' 2173 2174<nt def="NT-extSubsetDecl">extSubsetDecl</nt> 2175']]>' 2176</rhs> 2177</prod> 2178<prod id="NT-ignoreSect"><lhs>ignoreSect</lhs> 2179<rhs>'<![' S? 'IGNORE' S? '[' 2180<nt def="NT-ignoreSectContents">ignoreSectContents</nt>* 2181']]>'</rhs> 2182</prod> 2183 2184<prod id="NT-ignoreSectContents"><lhs>ignoreSectContents</lhs> 2185<rhs><nt def="NT-Ignore">Ignore</nt> 2186('<![' <nt def="NT-ignoreSectContents">ignoreSectContents</nt> ']]>' 2187<nt def="NT-Ignore">Ignore</nt>)*</rhs></prod> 2188<prod id="NT-Ignore"><lhs>Ignore</lhs> 2189<rhs><nt def="NT-Char">Char</nt>* - 2190(<nt def="NT-Char">Char</nt>* ('<![' | ']]>') 2191<nt def="NT-Char">Char</nt>*) 2192</rhs></prod> 2193 2194</prodgroup> 2195</scrap> 2196</p> 2197<p>Like the internal and external DTD subsets, a conditional section 2198may contain one or more complete declarations, 2199comments, processing instructions, 2200or nested conditional sections, intermingled with white space. 2201</p> 2202<p>If the keyword of the 2203conditional section is <kw>INCLUDE</kw>, then the contents of the conditional 2204section are part of the DTD. 2205If the keyword of the conditional 2206section is <kw>IGNORE</kw>, then the contents of the conditional section are 2207not logically part of the DTD. 2208Note that for reliable parsing, the contents of even ignored 2209conditional sections must be read in order to 2210detect nested conditional sections and ensure that the end of the 2211outermost (ignored) conditional section is properly detected. 2212If a conditional section with a 2213keyword of <kw>INCLUDE</kw> occurs within a larger conditional 2214section with a keyword of <kw>IGNORE</kw>, both the outer and the 2215inner conditional sections are ignored.</p> 2216<p>If the keyword of the conditional section is a 2217parameter-entity reference, the parameter entity must be replaced by its 2218content before the processor decides whether to 2219include or ignore the conditional section.</p> 2220<p>An example: 2221<eg><!ENTITY % draft 'INCLUDE' > 2222<!ENTITY % final 'IGNORE' > 2223 2224<![%draft;[ 2225<!ELEMENT book (comments*, title, body, supplements?)> 2226]]> 2227<![%final;[ 2228<!ELEMENT book (title, body, supplements?)> 2229]]> 2230</eg> 2231</p> 2232</div2> 2233 2234 2235<!-- 2236<div2 id='sec-pass-to-app'> 2237<head>XML Processor Treatment of Logical Structure</head> 2238<p>When an XML processor encounters a start-tag, it must make 2239at least the following information available to the application: 2240<ulist> 2241<item> 2242<p>the element type's generic identifier</p> 2243</item> 2244<item> 2245<p>the names of attributes known to apply to this element type 2246(validating processors must make available names of all attributes 2247declared for the element type; non-validating processors must 2248make available at least the names of the attributes for which 2249values are specified. 2250</p> 2251</item> 2252</ulist> 2253</p> 2254</div2> 2255--> 2256 2257</div1> 2258<!-- &Entities; --> 2259 2260<div1 id="sec-physical-struct"> 2261<head>Physical Structures</head> 2262 2263<p><termdef id="dt-entity" term="Entity">An XML document may consist 2264of one or many storage units. These are called 2265<term>entities</term>; they all have <term>content</term> and are all 2266(except for the document entity, see below, and 2267the <termref def="dt-doctype">external DTD subset</termref>) 2268identified by <term>name</term>. 2269</termdef> 2270Each XML document has one entity 2271called the <termref def="dt-docent">document entity</termref>, which serves 2272as the starting point for the <termref def="dt-xml-proc">XML 2273processor</termref> and may contain the whole document.</p> 2274<p>Entities may be either parsed or unparsed. 2275<termdef id="dt-parsedent" term="Text Entity">A <term>parsed entity's</term> 2276contents are referred to as its 2277<termref def="dt-repltext">replacement text</termref>; 2278this <termref def="dt-text">text</termref> is considered an 2279integral part of the document.</termdef></p> 2280 2281<p><termdef id="dt-unparsed" term="Unparsed Entity">An 2282<term>unparsed entity</term> 2283is a resource whose contents may or may not be 2284<termref def="dt-text">text</termref>, and if text, may not be XML. 2285Each unparsed entity 2286has an associated <termref def="dt-notation">notation</termref>, identified by name. 2287Beyond a requirement 2288that an XML processor make the identifiers for the entity and 2289notation available to the application, 2290XML places no constraints on the contents of unparsed entities.</termdef> 2291</p> 2292<p> 2293Parsed entities are invoked by name using entity references; 2294unparsed entities by name, given in the value of <kw>ENTITY</kw> 2295or <kw>ENTITIES</kw> 2296attributes.</p> 2297<p><termdef id="gen-entity" term="general entity"><term>General entities</term> 2298are entities for use within the document content. 2299In this specification, general entities are sometimes referred 2300to with the unqualified term <emph>entity</emph> when this leads 2301to no ambiguity.</termdef> 2302<termdef id="dt-PE" term="Parameter entity">Parameter entities 2303are parsed entities for use within the DTD.</termdef> 2304These two types of entities use different forms of reference and 2305are recognized in different contexts. 2306Furthermore, they occupy different namespaces; a parameter entity and 2307a general entity with the same name are two distinct entities. 2308</p> 2309 2310<div2 id="sec-references"> 2311<head>Character and Entity References</head> 2312<p><termdef id="dt-charref" term="Character Reference"> 2313A <term>character reference</term> refers to a specific character in the 2314ISO/IEC 10646 character set, for example one not directly accessible from 2315available input devices. 2316<scrap lang="ebnf"> 2317<head>Character Reference</head> 2318<prod id="NT-CharRef"><lhs>CharRef</lhs> 2319<rhs>'&#' [0-9]+ ';' </rhs> 2320<rhs>| '&hcro;' [0-9a-fA-F]+ ';'</rhs> 2321<wfc def="wf-Legalchar"/> 2322</prod> 2323</scrap> 2324<wfcnote id="wf-Legalchar"> 2325<head>Legal Character</head> 2326<p>Characters referred to using character references must 2327match the production for 2328<termref def="NT-Char">Char</termref>.</p> 2329</wfcnote> 2330If the character reference begins with "<code>&#x</code>", the digits and 2331letters up to the terminating <code>;</code> provide a hexadecimal 2332representation of the character's code point in ISO/IEC 10646. 2333If it begins just with "<code>&#</code>", the digits up to the terminating 2334<code>;</code> provide a decimal representation of the character's 2335code point. 2336</termdef> 2337</p> 2338<p><termdef id="dt-entref" term="Entity Reference">An <term>entity 2339reference</term> refers to the content of a named entity.</termdef> 2340<termdef id="dt-GERef" term="General Entity Reference">References to 2341parsed general entities 2342use ampersand (<code>&</code>) and semicolon (<code>;</code>) as 2343delimiters.</termdef> 2344<termdef id="dt-PERef" term="Parameter-entity reference"> 2345<term>Parameter-entity references</term> use percent-sign (<code>%</code>) and 2346semicolon 2347(<code>;</code>) as delimiters.</termdef> 2348</p> 2349<scrap lang="ebnf"> 2350<head>Entity Reference</head> 2351<prod id="NT-Reference"><lhs>Reference</lhs> 2352<rhs><nt def="NT-EntityRef">EntityRef</nt> 2353| <nt def="NT-CharRef">CharRef</nt></rhs></prod> 2354<prod id="NT-EntityRef"><lhs>EntityRef</lhs> 2355<rhs>'&' <nt def="NT-Name">Name</nt> ';'</rhs> 2356<wfc def="wf-entdeclared"/> 2357<vc def="vc-entdeclared"/> 2358<wfc def="textent"/> 2359<wfc def="norecursion"/> 2360</prod> 2361<prod id="NT-PEReference"><lhs>PEReference</lhs> 2362<rhs>'%' <nt def="NT-Name">Name</nt> ';'</rhs> 2363<vc def="vc-entdeclared"/> 2364<wfc def="norecursion"/> 2365<wfc def="indtd"/> 2366</prod> 2367</scrap> 2368 2369<wfcnote id="wf-entdeclared"> 2370<head>Entity Declared</head> 2371<p>In a document without any DTD, a document with only an internal 2372DTD subset which contains no parameter entity references, or a document with 2373"<code>standalone='yes'</code>", 2374the <nt def="NT-Name">Name</nt> given in the entity reference must 2375<termref def="dt-match">match</termref> that in an 2376<titleref href="sec-entity-decl">entity declaration</titleref>, except that 2377well-formed documents need not declare 2378any of the following entities: &magicents;. 2379The declaration of a parameter entity must precede any reference to it. 2380Similarly, the declaration of a general entity must precede any 2381reference to it which appears in a default value in an attribute-list 2382declaration.</p> 2383<p>Note that if entities are declared in the external subset or in 2384external parameter entities, a non-validating processor is 2385<titleref href="include-if-valid">not obligated to</titleref> read 2386and process their declarations; for such documents, the rule that 2387an entity must be declared is a well-formedness constraint only 2388if <titleref href="sec-rmd">standalone='yes'</titleref>.</p> 2389</wfcnote> 2390<vcnote id="vc-entdeclared"> 2391<head>Entity Declared</head> 2392<p>In a document with an external subset or external parameter 2393entities with "<code>standalone='no'</code>", 2394the <nt def="NT-Name">Name</nt> given in the entity reference must <termref def="dt-match">match</termref> that in an 2395<titleref href="sec-entity-decl">entity declaration</titleref>. 2396For interoperability, valid documents should declare the entities 2397&magicents;, in the form 2398specified in <specref ref="sec-predefined-ent"/>. 2399The declaration of a parameter entity must precede any reference to it. 2400Similarly, the declaration of a general entity must precede any 2401reference to it which appears in a default value in an attribute-list 2402declaration.</p> 2403</vcnote> 2404<!-- FINAL EDIT: is this duplication too clumsy? --> 2405<wfcnote id="textent"> 2406<head>Parsed Entity</head> 2407<p> 2408An entity reference must not contain the name of an <termref def="dt-unparsed">unparsed entity</termref>. Unparsed entities may be referred 2409to only in <termref def="dt-attrval">attribute values</termref> declared to 2410be of type <kw>ENTITY</kw> or <kw>ENTITIES</kw>. 2411</p> 2412</wfcnote> 2413<wfcnote id="norecursion"> 2414<head>No Recursion</head> 2415<p> 2416A parsed entity must not contain a recursive reference to itself, 2417either directly or indirectly. 2418</p> 2419</wfcnote> 2420<wfcnote id="indtd"> 2421<head>In DTD</head> 2422<p> 2423Parameter-entity references may only appear in the 2424<termref def="dt-doctype">DTD</termref>. 2425</p> 2426</wfcnote> 2427<p>Examples of character and entity references: 2428<eg>Type <key>less-than</key> (&hcro;3C;) to save options. 2429This document was prepared on &docdate; and 2430is classified &security-level;.</eg></p> 2431<p>Example of a parameter-entity reference: 2432<eg><![CDATA[<!-- declare the parameter entity "ISOLat2"... --> 2433<!ENTITY % ISOLat2 2434 SYSTEM "http://www.xml.com/iso/isolat2-xml.entities" > 2435<!-- ... now reference it. --> 2436%ISOLat2;]]></eg></p> 2437</div2> 2438 2439<div2 id="sec-entity-decl"> 2440<head>Entity Declarations</head> 2441 2442<p><termdef id="dt-entdecl" term="entity declaration"> 2443Entities are declared thus: 2444<scrap lang="ebnf"> 2445<head>Entity Declaration</head> 2446<prodgroup pcw2="5" pcw4="18.5"> 2447<prod id="NT-EntityDecl"><lhs>EntityDecl</lhs> 2448<rhs><nt def="NT-GEDecl">GEDecl</nt><!--</rhs><com>General entities</com> 2449<rhs>--> | <nt def="NT-PEDecl">PEDecl</nt></rhs> 2450<!--<com>Parameter entities</com>--> 2451</prod> 2452<prod id="NT-GEDecl"><lhs>GEDecl</lhs> 2453<rhs>'<!ENTITY' <nt def="NT-S">S</nt> <nt def="NT-Name">Name</nt> 2454<nt def="NT-S">S</nt> <nt def="NT-EntityDef">EntityDef</nt> 2455<nt def="NT-S">S</nt>? '>'</rhs> 2456</prod> 2457<prod id="NT-PEDecl"><lhs>PEDecl</lhs> 2458<rhs>'<!ENTITY' <nt def="NT-S">S</nt> '%' <nt def="NT-S">S</nt> 2459<nt def="NT-Name">Name</nt> <nt def="NT-S">S</nt> 2460<nt def="NT-PEDef">PEDef</nt> <nt def="NT-S">S</nt>? '>'</rhs> 2461<!--<com>Parameter entities</com>--> 2462</prod> 2463<prod id="NT-EntityDef"><lhs>EntityDef</lhs> 2464<rhs><nt def="NT-EntityValue">EntityValue</nt> 2465<!--</rhs> 2466<rhs>-->| (<nt def="NT-ExternalID">ExternalID</nt> 2467<nt def="NT-NDataDecl">NDataDecl</nt>?)</rhs> 2468<!-- <nt def='NT-ExternalDef'>ExternalDef</nt></rhs> --> 2469</prod> 2470<!-- FINAL EDIT: what happened to WFs here? --> 2471<prod id="NT-PEDef"><lhs>PEDef</lhs> 2472<rhs><nt def="NT-EntityValue">EntityValue</nt> 2473| <nt def="NT-ExternalID">ExternalID</nt></rhs></prod> 2474</prodgroup> 2475</scrap> 2476The <nt def="NT-Name">Name</nt> identifies the entity in an 2477<termref def="dt-entref">entity reference</termref> or, in the case of an 2478unparsed entity, in the value of an <kw>ENTITY</kw> or <kw>ENTITIES</kw> 2479attribute. 2480If the same entity is declared more than once, the first declaration 2481encountered is binding; at user option, an XML processor may issue a 2482warning if entities are declared multiple times.</termdef> 2483</p> 2484 2485<div3 id="sec-internal-ent"> 2486<head>Internal Entities</head> 2487 2488<p><termdef id="dt-internent" term="Internal Entity Replacement Text">If 2489the entity definition is an 2490<nt def="NT-EntityValue">EntityValue</nt>, 2491the defined entity is called an <term>internal entity</term>. 2492There is no separate physical 2493storage object, and the content of the entity is given in the 2494declaration. </termdef> 2495Note that some processing of entity and character references in the 2496<termref def="dt-litentval">literal entity value</termref> may be required to 2497produce the correct <termref def="dt-repltext">replacement 2498text</termref>: see <specref ref="intern-replacement"/>. 2499</p> 2500<p>An internal entity is a <termref def="dt-parsedent">parsed 2501entity</termref>.</p> 2502<p>Example of an internal entity declaration: 2503<eg><!ENTITY Pub-Status "This is a pre-release of the 2504 specification."></eg></p> 2505</div3> 2506 2507<div3 id="sec-external-ent"> 2508<head>External Entities</head> 2509 2510<p><termdef id="dt-extent" term="External Entity">If the entity is not 2511internal, it is an <term>external 2512entity</term>, declared as follows: 2513<scrap lang="ebnf"> 2514<head>External Entity Declaration</head> 2515<!-- 2516<prod id='NT-ExternalDef'><lhs>ExternalDef</lhs> 2517<rhs></prod> --> 2518<prod id="NT-ExternalID"><lhs>ExternalID</lhs> 2519<rhs>'SYSTEM' <nt def="NT-S">S</nt> 2520<nt def="NT-SystemLiteral">SystemLiteral</nt></rhs> 2521<rhs>| 'PUBLIC' <nt def="NT-S">S</nt> 2522<nt def="NT-PubidLiteral">PubidLiteral</nt> 2523<nt def="NT-S">S</nt> 2524<nt def="NT-SystemLiteral">SystemLiteral</nt> 2525</rhs> 2526</prod> 2527<prod id="NT-NDataDecl"><lhs>NDataDecl</lhs> 2528<rhs><nt def="NT-S">S</nt> 'NDATA' <nt def="NT-S">S</nt> 2529<nt def="NT-Name">Name</nt></rhs> 2530<vc def="not-declared"/></prod> 2531</scrap> 2532If the <nt def="NT-NDataDecl">NDataDecl</nt> is present, this is a 2533general <termref def="dt-unparsed">unparsed 2534entity</termref>; otherwise it is a parsed entity.</termdef></p> 2535<vcnote id="not-declared"> 2536<head>Notation Declared</head> 2537<p> 2538The <nt def="NT-Name">Name</nt> must match the declared name of a 2539<termref def="dt-notation">notation</termref>. 2540</p> 2541</vcnote> 2542<p><termdef id="dt-sysid" term="System Identifier">The 2543<nt def="NT-SystemLiteral">SystemLiteral</nt> 2544is called the entity's <term>system identifier</term>. It is a URI, 2545which may be used to retrieve the entity.</termdef> 2546Note that the hash mark (<code>#</code>) and fragment identifier 2547frequently used with URIs are not, formally, part of the URI itself; 2548an XML processor may signal an error if a fragment identifier is 2549given as part of a system identifier. 2550Unless otherwise provided by information outside the scope of this 2551specification (e.g. a special XML element type defined by a particular 2552DTD, or a processing instruction defined by a particular application 2553specification), relative URIs are relative to the location of the 2554resource within which the entity declaration occurs. 2555A URI might thus be relative to the 2556<termref def="dt-docent">document entity</termref>, to the entity 2557containing the <termref def="dt-doctype">external DTD subset</termref>, 2558or to some other <termref def="dt-extent">external parameter entity</termref>. 2559</p> 2560<p>An XML processor should handle a non-ASCII character in a URI by 2561representing the character in UTF-8 as one or more bytes, and then 2562escaping these bytes with the URI escaping mechanism (i.e., by 2563converting each byte to %HH, where HH is the hexadecimal notation of the 2564byte value).</p> 2565<p><termdef id="dt-pubid" term="Public identifier"> 2566In addition to a system identifier, an external identifier may 2567include a <term>public identifier</term>.</termdef> 2568An XML processor attempting to retrieve the entity's content may use the public 2569identifier to try to generate an alternative URI. If the processor 2570is unable to do so, it must use the URI specified in the system 2571literal. Before a match is attempted, all strings 2572of white space in the public identifier must be normalized to single space characters (#x20), 2573and leading and trailing white space must be removed.</p> 2574<p>Examples of external entity declarations: 2575<eg><!ENTITY open-hatch 2576 SYSTEM "http://www.textuality.com/boilerplate/OpenHatch.xml"> 2577<!ENTITY open-hatch 2578 PUBLIC "-//Textuality//TEXT Standard open-hatch boilerplate//EN" 2579 "http://www.textuality.com/boilerplate/OpenHatch.xml"> 2580<!ENTITY hatch-pic 2581 SYSTEM "../grafix/OpenHatch.gif" 2582 NDATA gif ></eg></p> 2583</div3> 2584 2585</div2> 2586 2587<div2 id="TextEntities"> 2588<head>Parsed Entities</head> 2589<div3 id="sec-TextDecl"> 2590<head>The Text Declaration</head> 2591<p>External parsed entities may each begin with a <term>text 2592declaration</term>. 2593<scrap lang="ebnf"> 2594<head>Text Declaration</head> 2595<prodgroup pcw4="12.5" pcw5="13"> 2596<prod id="NT-TextDecl"><lhs>TextDecl</lhs> 2597<rhs>&xmlpio; 2598<nt def="NT-VersionInfo">VersionInfo</nt>? 2599<nt def="NT-EncodingDecl">EncodingDecl</nt> 2600<nt def="NT-S">S</nt>? &pic;</rhs> 2601</prod> 2602</prodgroup> 2603</scrap> 2604</p> 2605<p>The text declaration must be provided literally, not 2606by reference to a parsed entity. 2607No text declaration may appear at any position other than the beginning of 2608an external parsed entity.</p> 2609</div3> 2610<div3 id="wf-entities"> 2611<head>Well-Formed Parsed Entities</head> 2612<p>The document entity is well-formed if it matches the production labeled 2613<nt def="NT-document">document</nt>. 2614An external general 2615parsed entity is well-formed if it matches the production labeled 2616<nt def="NT-extParsedEnt">extParsedEnt</nt>. 2617An external parameter 2618entity is well-formed if it matches the production labeled 2619<nt def="NT-extPE">extPE</nt>. 2620<scrap lang="ebnf"> 2621<head>Well-Formed External Parsed Entity</head> 2622<prod id="NT-extParsedEnt"><lhs>extParsedEnt</lhs> 2623<rhs><nt def="NT-TextDecl">TextDecl</nt>? 2624<nt def="NT-content">content</nt></rhs> 2625</prod> 2626<prod id="NT-extPE"><lhs>extPE</lhs> 2627<rhs><nt def="NT-TextDecl">TextDecl</nt>? 2628<nt def="NT-extSubsetDecl">extSubsetDecl</nt></rhs> 2629</prod> 2630</scrap> 2631An internal general parsed entity is well-formed if its replacement text 2632matches the production labeled 2633<nt def="NT-content">content</nt>. 2634All internal parameter entities are well-formed by definition. 2635</p> 2636<p>A consequence of well-formedness in entities is that the logical 2637and physical structures in an XML document are properly nested; no 2638<termref def="dt-stag">start-tag</termref>, 2639<termref def="dt-etag">end-tag</termref>, 2640<termref def="dt-empty">empty-element tag</termref>, 2641<termref def="dt-element">element</termref>, 2642<termref def="dt-comment">comment</termref>, 2643<termref def="dt-pi">processing instruction</termref>, 2644<termref def="dt-charref">character 2645reference</termref>, or 2646<termref def="dt-entref">entity reference</termref> 2647can begin in one entity and end in another.</p> 2648</div3> 2649<div3 id="charencoding"> 2650<head>Character Encoding in Entities</head> 2651 2652<p>Each external parsed entity in an XML document may use a different 2653encoding for its characters. All XML processors must be able to read 2654entities in either UTF-8 or UTF-16. 2655 2656</p> 2657<p>Entities encoded in UTF-16 must 2658begin with the Byte Order Mark described by ISO/IEC 10646 Annex E and 2659Unicode Appendix B (the ZERO WIDTH NO-BREAK SPACE character, #xFEFF). 2660This is an encoding signature, not part of either the markup or the 2661character data of the XML document. 2662XML processors must be able to use this character to 2663differentiate between UTF-8 and UTF-16 encoded documents.</p> 2664<p>Although an XML processor is required to read only entities in 2665the UTF-8 and UTF-16 encodings, it is recognized that other encodings are 2666used around the world, and it may be desired for XML processors 2667to read entities that use them. 2668Parsed entities which are stored in an encoding other than 2669UTF-8 or UTF-16 must begin with a <titleref href="TextDecl">text 2670declaration</titleref> containing an encoding declaration: 2671<scrap lang="ebnf"> 2672<head>Encoding Declaration</head> 2673<prod id="NT-EncodingDecl"><lhs>EncodingDecl</lhs> 2674<rhs><nt def="NT-S">S</nt> 2675'encoding' <nt def="NT-Eq">Eq</nt> 2676('"' <nt def="NT-EncName">EncName</nt> '"' | 2677"'" <nt def="NT-EncName">EncName</nt> "'" ) 2678</rhs> 2679</prod> 2680<prod id="NT-EncName"><lhs>EncName</lhs> 2681<rhs>[A-Za-z] ([A-Za-z0-9._] | '-')*</rhs> 2682<com>Encoding name contains only Latin characters</com> 2683</prod> 2684</scrap> 2685In the <termref def="dt-docent">document entity</termref>, the encoding 2686declaration is part of the <termref def="dt-xmldecl">XML declaration</termref>. 2687The <nt def="NT-EncName">EncName</nt> is the name of the encoding used. 2688</p> 2689<!-- FINAL EDIT: check name of IANA and charset names --> 2690<p>In an encoding declaration, the values 2691"<code>UTF-8</code>", 2692"<code>UTF-16</code>", 2693"<code>ISO-10646-UCS-2</code>", and 2694"<code>ISO-10646-UCS-4</code>" should be 2695used for the various encodings and transformations of Unicode / 2696ISO/IEC 10646, the values 2697"<code>ISO-8859-1</code>", 2698"<code>ISO-8859-2</code>", ... 2699"<code>ISO-8859-9</code>" should be used for the parts of ISO 8859, and 2700the values 2701"<code>ISO-2022-JP</code>", 2702"<code>Shift_JIS</code>", and 2703"<code>EUC-JP</code>" 2704should be used for the various encoded forms of JIS X-0208-1997. XML 2705processors may recognize other encodings; it is recommended that 2706character encodings registered (as <emph>charset</emph>s) 2707with the Internet Assigned Numbers 2708Authority <bibref ref="IANA"/>, other than those just listed, should be 2709referred to 2710using their registered names. 2711Note that these registered names are defined to be 2712case-insensitive, so processors wishing to match against them 2713should do so in a case-insensitive 2714way.</p> 2715<p>In the absence of information provided by an external 2716transport protocol (e.g. HTTP or MIME), 2717it is an <termref def="dt-error">error</termref> for an entity including 2718an encoding declaration to be presented to the XML processor 2719in an encoding other than that named in the declaration, 2720for an encoding declaration to occur other than at the beginning 2721of an external entity, or for 2722an entity which begins with neither a Byte Order Mark nor an encoding 2723declaration to use an encoding other than UTF-8. 2724Note that since ASCII 2725is a subset of UTF-8, ordinary ASCII entities do not strictly need 2726an encoding declaration.</p> 2727 2728<p>It is a <termref def="dt-fatal">fatal error</termref> when an XML processor 2729encounters an entity with an encoding that it is unable to process.</p> 2730<p>Examples of encoding declarations: 2731<eg><?xml encoding='UTF-8'?> 2732<?xml encoding='EUC-JP'?></eg></p> 2733</div3> 2734</div2> 2735<div2 id="entproc"> 2736<head>XML Processor Treatment of Entities and References</head> 2737<p>The table below summarizes the contexts in which character references, 2738entity references, and invocations of unparsed entities might appear and the 2739required behavior of an <termref def="dt-xml-proc">XML processor</termref> in 2740each case. 2741The labels in the leftmost column describe the recognition context: 2742<glist> 2743<gitem><label>Reference in Content</label> 2744<def><p>as a reference 2745anywhere after the <termref def="dt-stag">start-tag</termref> and 2746before the <termref def="dt-etag">end-tag</termref> of an element; corresponds 2747to the nonterminal <nt def="NT-content">content</nt>.</p></def> 2748</gitem> 2749<gitem> 2750<label>Reference in Attribute Value</label> 2751<def><p>as a reference within either the value of an attribute in a 2752<termref def="dt-stag">start-tag</termref>, or a default 2753value in an <termref def="dt-attdecl">attribute declaration</termref>; 2754corresponds to the nonterminal 2755<nt def="NT-AttValue">AttValue</nt>.</p></def></gitem> 2756<gitem> 2757<label>Occurs as Attribute Value</label> 2758<def><p>as a <nt def="NT-Name">Name</nt>, not a reference, appearing either as 2759the value of an 2760attribute which has been declared as type <kw>ENTITY</kw>, or as one of 2761the space-separated tokens in the value of an attribute which has been 2762declared as type <kw>ENTITIES</kw>.</p> 2763</def></gitem> 2764<gitem><label>Reference in Entity Value</label> 2765<def><p>as a reference 2766within a parameter or internal entity's 2767<termref def="dt-litentval">literal entity value</termref> in 2768the entity's declaration; corresponds to the nonterminal 2769<nt def="NT-EntityValue">EntityValue</nt>.</p></def></gitem> 2770<gitem><label>Reference in DTD</label> 2771<def><p>as a reference within either the internal or external subsets of the 2772<termref def="dt-doctype">DTD</termref>, but outside 2773of an <nt def="NT-EntityValue">EntityValue</nt> or 2774<nt def="NT-AttValue">AttValue</nt>.</p></def> 2775</gitem> 2776</glist></p> 2777<htable border="1" cellpadding="7" align="center"> 2778<htbody> 2779<tr><td bgcolor="&cellback;" rowspan="2" colspan="1"/> 2780<td bgcolor="&cellback;" align="center" valign="bottom" colspan="4">Entity Type</td> 2781<td bgcolor="&cellback;" rowspan="2" align="center">Character</td> 2782</tr> 2783<tr align="center" valign="bottom"> 2784<td bgcolor="&cellback;">Parameter</td> 2785<td bgcolor="&cellback;">Internal 2786General</td> 2787<td bgcolor="&cellback;">External Parsed 2788General</td> 2789<td bgcolor="&cellback;">Unparsed</td> 2790</tr> 2791<tr align="center" valign="middle"> 2792 2793<td bgcolor="&cellback;" align="right">Reference 2794in Content</td> 2795<td bgcolor="&cellback;"><titleref href="not-recognized">Not recognized</titleref></td> 2796<td bgcolor="&cellback;"><titleref href="included">Included</titleref></td> 2797<td bgcolor="&cellback;"><titleref href="include-if-valid">Included if validating</titleref></td> 2798<td bgcolor="&cellback;"><titleref href="forbidden">Forbidden</titleref></td> 2799<td bgcolor="&cellback;"><titleref href="included">Included</titleref></td> 2800</tr> 2801<tr align="center" valign="middle"> 2802<td bgcolor="&cellback;" align="right">Reference 2803in Attribute Value</td> 2804<td bgcolor="&cellback;"><titleref href="not-recognized">Not recognized</titleref></td> 2805<td bgcolor="&cellback;"><titleref href="inliteral">Included in literal</titleref></td> 2806<td bgcolor="&cellback;"><titleref href="forbidden">Forbidden</titleref></td> 2807<td bgcolor="&cellback;"><titleref href="forbidden">Forbidden</titleref></td> 2808<td bgcolor="&cellback;"><titleref href="included">Included</titleref></td> 2809</tr> 2810<tr align="center" valign="middle"> 2811<td bgcolor="&cellback;" align="right">Occurs as 2812Attribute Value</td> 2813<td bgcolor="&cellback;"><titleref href="not-recognized">Not recognized</titleref></td> 2814<td bgcolor="&cellback;"><titleref href="not-recognized">Forbidden</titleref></td> 2815<td bgcolor="&cellback;"><titleref href="not-recognized">Forbidden</titleref></td> 2816<td bgcolor="&cellback;"><titleref href="notify">Notify</titleref></td> 2817<td bgcolor="&cellback;"><titleref href="not recognized">Not recognized</titleref></td> 2818</tr> 2819<tr align="center" valign="middle"> 2820<td bgcolor="&cellback;" align="right">Reference 2821in EntityValue</td> 2822<td bgcolor="&cellback;"><titleref href="inliteral">Included in literal</titleref></td> 2823<td bgcolor="&cellback;"><titleref href="bypass">Bypassed</titleref></td> 2824<td bgcolor="&cellback;"><titleref href="bypass">Bypassed</titleref></td> 2825<td bgcolor="&cellback;"><titleref href="forbidden">Forbidden</titleref></td> 2826<td bgcolor="&cellback;"><titleref href="included">Included</titleref></td> 2827</tr> 2828<tr align="center" valign="middle"> 2829<td bgcolor="&cellback;" align="right">Reference 2830in DTD</td> 2831<td bgcolor="&cellback;"><titleref href="as-PE">Included as PE</titleref></td> 2832<td bgcolor="&cellback;"><titleref href="forbidden">Forbidden</titleref></td> 2833<td bgcolor="&cellback;"><titleref href="forbidden">Forbidden</titleref></td> 2834<td bgcolor="&cellback;"><titleref href="forbidden">Forbidden</titleref></td> 2835<td bgcolor="&cellback;"><titleref href="forbidden">Forbidden</titleref></td> 2836</tr> 2837</htbody> 2838</htable> 2839<div3 id="not-recognized"> 2840<head>Not Recognized</head> 2841<p>Outside the DTD, the <code>%</code> character has no 2842special significance; thus, what would be parameter entity references in the 2843DTD are not recognized as markup in <nt def="NT-content">content</nt>. 2844Similarly, the names of unparsed entities are not recognized except 2845when they appear in the value of an appropriately declared attribute. 2846</p> 2847</div3> 2848<div3 id="included"> 2849<head>Included</head> 2850<p><termdef id="dt-include" term="Include">An entity is 2851<term>included</term> when its 2852<termref def="dt-repltext">replacement text</termref> is retrieved 2853and processed, in place of the reference itself, 2854as though it were part of the document at the location the 2855reference was recognized. 2856The replacement text may contain both 2857<termref def="dt-chardata">character data</termref> 2858and (except for parameter entities) <termref def="dt-markup">markup</termref>, 2859which must be recognized in 2860the usual way, except that the replacement text of entities used to escape 2861markup delimiters (the entities &magicents;) is always treated as 2862data. (The string "<code>AT&amp;T;</code>" expands to 2863"<code>AT&T;</code>" and the remaining ampersand is not recognized 2864as an entity-reference delimiter.) 2865A character reference is <term>included</term> when the indicated 2866character is processed in place of the reference itself. 2867</termdef></p> 2868</div3> 2869<div3 id="include-if-valid"> 2870<head>Included If Validating</head> 2871<p>When an XML processor recognizes a reference to a parsed entity, in order 2872to <termref def="dt-valid">validate</termref> 2873the document, the processor must 2874<termref def="dt-include">include</termref> its 2875replacement text. 2876If the entity is external, and the processor is not 2877attempting to validate the XML document, the 2878processor <termref def="dt-may">may</termref>, but need not, 2879include the entity's replacement text. 2880If a non-validating parser does not include the replacement text, 2881it must inform the application that it recognized, but did not 2882read, the entity.</p> 2883<p>This rule is based on the recognition that the automatic inclusion 2884provided by the SGML and XML entity mechanism, primarily designed 2885to support modularity in authoring, is not necessarily 2886appropriate for other applications, in particular document browsing. 2887Browsers, for example, when encountering an external parsed entity reference, 2888might choose to provide a visual indication of the entity's 2889presence and retrieve it for display only on demand. 2890</p> 2891</div3> 2892<div3 id="forbidden"> 2893<head>Forbidden</head> 2894<p>The following are forbidden, and constitute 2895<termref def="dt-fatal">fatal</termref> errors: 2896<ulist> 2897<item><p>the appearance of a reference to an 2898<termref def="dt-unparsed">unparsed entity</termref>. 2899</p></item> 2900<item><p>the appearance of any character or general-entity reference in the 2901DTD except within an <nt def="NT-EntityValue">EntityValue</nt> or 2902<nt def="NT-AttValue">AttValue</nt>.</p></item> 2903<item><p>a reference to an external entity in an attribute value.</p> 2904</item> 2905</ulist> 2906</p> 2907</div3> 2908<div3 id="inliteral"> 2909<head>Included in Literal</head> 2910<p>When an <termref def="dt-entref">entity reference</termref> appears in an 2911attribute value, or a parameter entity reference appears in a literal entity 2912value, its <termref def="dt-repltext">replacement text</termref> is 2913processed in place of the reference itself as though it 2914were part of the document at the location the reference was recognized, 2915except that a single or double quote character in the replacement text 2916is always treated as a normal data character and will not terminate the 2917literal. 2918For example, this is well-formed: 2919<eg><![CDATA[<!ENTITY % YN '"Yes"' > 2920<!ENTITY WhatHeSaid "He said &YN;" >]]></eg> 2921while this is not: 2922<eg><!ENTITY EndAttr "27'" > 2923<element attribute='a-&EndAttr;></eg> 2924</p></div3> 2925<div3 id="notify"> 2926<head>Notify</head> 2927<p>When the name of an <termref def="dt-unparsed">unparsed 2928entity</termref> appears as a token in the 2929value of an attribute of declared type <kw>ENTITY</kw> or <kw>ENTITIES</kw>, 2930a validating processor must inform the 2931application of the <termref def="dt-sysid">system</termref> 2932and <termref def="dt-pubid">public</termref> (if any) 2933identifiers for both the entity and its associated 2934<termref def="dt-notation">notation</termref>.</p> 2935</div3> 2936<div3 id="bypass"> 2937<head>Bypassed</head> 2938<p>When a general entity reference appears in the 2939<nt def="NT-EntityValue">EntityValue</nt> in an entity declaration, 2940it is bypassed and left as is.</p> 2941</div3> 2942<div3 id="as-PE"> 2943<head>Included as PE</head> 2944<p>Just as with external parsed entities, parameter entities 2945need only be <titleref href="include-if-valid">included if 2946validating</titleref>. 2947When a parameter-entity reference is recognized in the DTD 2948and included, its 2949<termref def="dt-repltext">replacement 2950text</termref> is enlarged by the attachment of one leading and one following 2951space (#x20) character; the intent is to constrain the replacement 2952text of parameter 2953entities to contain an integral number of grammatical tokens in the DTD. 2954</p> 2955</div3> 2956 2957</div2> 2958<div2 id="intern-replacement"> 2959<head>Construction of Internal Entity Replacement Text</head> 2960<p>In discussing the treatment 2961of internal entities, it is 2962useful to distinguish two forms of the entity's value. 2963<termdef id="dt-litentval" term="Literal Entity Value">The <term>literal 2964entity value</term> is the quoted string actually 2965present in the entity declaration, corresponding to the 2966non-terminal <nt def="NT-EntityValue">EntityValue</nt>.</termdef> 2967<termdef id="dt-repltext" term="Replacement Text">The <term>replacement 2968text</term> is the content of the entity, after 2969replacement of character references and parameter-entity 2970references. 2971</termdef></p> 2972 2973<p>The literal entity value 2974as given in an internal entity declaration 2975(<nt def="NT-EntityValue">EntityValue</nt>) may contain character, 2976parameter-entity, and general-entity references. 2977Such references must be contained entirely within the 2978literal entity value. 2979The actual replacement text that is 2980<termref def="dt-include">included</termref> as described above 2981must contain the <emph>replacement text</emph> of any 2982parameter entities referred to, and must contain the character 2983referred to, in place of any character references in the 2984literal entity value; however, 2985general-entity references must be left as-is, unexpanded. 2986For example, given the following declarations: 2987 2988<eg><![CDATA[<!ENTITY % pub "Éditions Gallimard" > 2989<!ENTITY rights "All rights reserved" > 2990<!ENTITY book "La Peste: Albert Camus, 2991© 1947 %pub;. &rights;" >]]></eg> 2992then the replacement text for the entity "<code>book</code>" is: 2993<eg>La Peste: Albert Camus, 2994� 1947 �ditions Gallimard. &rights;</eg> 2995The general-entity reference "<code>&rights;</code>" would be expanded 2996should the reference "<code>&book;</code>" appear in the document's 2997content or an attribute value.</p> 2998<p>These simple rules may have complex interactions; for a detailed 2999discussion of a difficult example, see 3000<specref ref="sec-entexpand"/>. 3001</p> 3002 3003</div2> 3004<div2 id="sec-predefined-ent"> 3005<head>Predefined Entities</head> 3006<p><termdef id="dt-escape" term="escape">Entity and character 3007references can both be used to <term>escape</term> the left angle bracket, 3008ampersand, and other delimiters. A set of general entities 3009(&magicents;) is specified for this purpose. 3010Numeric character references may also be used; they are 3011expanded immediately when recognized and must be treated as 3012character data, so the numeric character references 3013"<code>&#60;</code>" and "<code>&#38;</code>" may be used to 3014escape <code><</code> and <code>&</code> when they occur 3015in character data.</termdef></p> 3016<p>All XML processors must recognize these entities whether they 3017are declared or not. 3018<termref def="dt-interop">For interoperability</termref>, 3019valid XML documents should declare these 3020entities, like any others, before using them. 3021If the entities in question are declared, they must be declared 3022as internal entities whose replacement text is the single 3023character being escaped or a character reference to 3024that character, as shown below. 3025<eg><![CDATA[<!ENTITY lt "&#60;"> 3026<!ENTITY gt ">"> 3027<!ENTITY amp "&#38;"> 3028<!ENTITY apos "'"> 3029<!ENTITY quot """> 3030]]></eg> 3031Note that the <code><</code> and <code>&</code> characters 3032in the declarations of "<code>lt</code>" and "<code>amp</code>" 3033are doubly escaped to meet the requirement that entity replacement 3034be well-formed. 3035</p> 3036</div2> 3037 3038<div2 id="Notations"> 3039<head>Notation Declarations</head> 3040 3041<p><termdef id="dt-notation" term="Notation"><term>Notations</term> identify by 3042name the format of <termref def="dt-extent">unparsed 3043entities</termref>, the 3044format of elements which bear a notation attribute, 3045or the application to which 3046a <termref def="dt-pi">processing instruction</termref> is 3047addressed.</termdef></p> 3048<p><termdef id="dt-notdecl" term="Notation Declaration"> 3049<term>Notation declarations</term> 3050provide a name for the notation, for use in 3051entity and attribute-list declarations and in attribute specifications, 3052and an external identifier for the notation which may allow an XML 3053processor or its client application to locate a helper application 3054capable of processing data in the given notation. 3055<scrap lang="ebnf"> 3056<head>Notation Declarations</head> 3057<prod id="NT-NotationDecl"><lhs>NotationDecl</lhs> 3058<rhs>'<!NOTATION' <nt def="NT-S">S</nt> <nt def="NT-Name">Name</nt> 3059<nt def="NT-S">S</nt> 3060(<nt def="NT-ExternalID">ExternalID</nt> | 3061<nt def="NT-PublicID">PublicID</nt>) 3062<nt def="NT-S">S</nt>? '>'</rhs></prod> 3063<prod id="NT-PublicID"><lhs>PublicID</lhs> 3064<rhs>'PUBLIC' <nt def="NT-S">S</nt> 3065<nt def="NT-PubidLiteral">PubidLiteral</nt> 3066</rhs></prod> 3067</scrap> 3068</termdef></p> 3069<p>XML processors must provide applications with the name and external 3070identifier(s) of any notation declared and referred to in an attribute 3071value, attribute definition, or entity declaration. They may 3072additionally resolve the external identifier into the 3073<termref def="dt-sysid">system identifier</termref>, 3074file name, or other information needed to allow the 3075application to call a processor for data in the notation described. (It 3076is not an error, however, for XML documents to declare and refer to 3077notations for which notation-specific applications are not available on 3078the system where the XML processor or application is running.)</p> 3079</div2> 3080 3081 3082<div2 id="sec-doc-entity"> 3083<head>Document Entity</head> 3084 3085<p><termdef id="dt-docent" term="Document Entity">The <term>document 3086entity</term> serves as the root of the entity 3087tree and a starting-point for an <termref def="dt-xml-proc">XML 3088processor</termref>.</termdef> 3089This specification does 3090not specify how the document entity is to be located by an XML 3091processor; unlike other entities, the document entity has no name and might 3092well appear on a processor input stream 3093without any identification at all.</p> 3094</div2> 3095 3096 3097</div1> 3098<!-- &Conformance; --> 3099 3100<div1 id="sec-conformance"> 3101<head>Conformance</head> 3102 3103<div2 id="proc-types"> 3104<head>Validating and Non-Validating Processors</head> 3105<p>Conforming <termref def="dt-xml-proc">XML processors</termref> fall into two 3106classes: validating and non-validating.</p> 3107<p>Validating and non-validating processors alike must report 3108violations of this specification's well-formedness constraints 3109in the content of the 3110<termref def="dt-docent">document entity</termref> and any 3111other <termref def="dt-parsedent">parsed entities</termref> that 3112they read.</p> 3113<p><termdef id="dt-validating" term="Validating Processor"> 3114<term>Validating processors</term> must report 3115violations of the constraints expressed by the declarations in the 3116<termref def="dt-doctype">DTD</termref>, and 3117failures to fulfill the validity constraints given 3118in this specification. 3119</termdef> 3120To accomplish this, validating XML processors must read and process the entire 3121DTD and all external parsed entities referenced in the document. 3122</p> 3123<p>Non-validating processors are required to check only the 3124<termref def="dt-docent">document entity</termref>, including 3125the entire internal DTD subset, for well-formedness. 3126<termdef id="dt-use-mdecl" term="Process Declarations"> 3127While they are not required to check the document for validity, 3128they are required to 3129<term>process</term> all the declarations they read in the 3130internal DTD subset and in any parameter entity that they 3131read, up to the first reference 3132to a parameter entity that they do <emph>not</emph> read; that is to 3133say, they must 3134use the information in those declarations to 3135<titleref href="AVNormalize">normalize</titleref> attribute values, 3136<titleref href="included">include</titleref> the replacement text of 3137internal entities, and supply 3138<titleref href="sec-attr-defaults">default attribute values</titleref>. 3139</termdef> 3140They must not <termref def="dt-use-mdecl">process</termref> 3141<termref def="dt-entdecl">entity declarations</termref> or 3142<termref def="dt-attdecl">attribute-list declarations</termref> 3143encountered after a reference to a parameter entity that is not 3144read, since the entity may have contained overriding declarations. 3145</p> 3146</div2> 3147<div2 id="safe-behavior"> 3148<head>Using XML Processors</head> 3149<p>The behavior of a validating XML processor is highly predictable; it 3150must read every piece of a document and report all well-formedness and 3151validity violations. 3152Less is required of a non-validating processor; it need not read any 3153part of the document other than the document entity. 3154This has two effects that may be important to users of XML processors: 3155<ulist> 3156<item><p>Certain well-formedness errors, specifically those that require 3157reading external entities, may not be detected by a non-validating processor. 3158Examples include the constraints entitled 3159<titleref href="wf-entdeclared">Entity Declared</titleref>, 3160<titleref href="wf-textent">Parsed Entity</titleref>, and 3161<titleref href="wf-norecursion">No Recursion</titleref>, as well 3162as some of the cases described as 3163<titleref href="forbidden">forbidden</titleref> in 3164<specref ref="entproc"/>.</p></item> 3165<item><p>The information passed from the processor to the application may 3166vary, depending on whether the processor reads 3167parameter and external entities. 3168For example, a non-validating processor may not 3169<titleref href="AVNormalize">normalize</titleref> attribute values, 3170<titleref href="included">include</titleref> the replacement text of 3171internal entities, or supply 3172<titleref href="sec-attr-defaults">default attribute values</titleref>, 3173where doing so depends on having read declarations in 3174external or parameter entities.</p></item> 3175</ulist> 3176</p> 3177<p>For maximum reliability in interoperating between different XML 3178processors, applications which use non-validating processors should not 3179rely on any behaviors not required of such processors. 3180Applications which require facilities such as the use of default 3181attributes or internal entities which are declared in external 3182entities should use validating XML processors.</p> 3183</div2> 3184</div1> 3185 3186<div1 id="sec-notation"> 3187<head>Notation</head> 3188 3189<p>The formal grammar of XML is given in this specification using a simple 3190Extended Backus-Naur Form (EBNF) notation. Each rule in the grammar defines 3191one symbol, in the form 3192<eg>symbol ::= expression</eg></p> 3193<p>Symbols are written with an initial capital letter if they are 3194defined by a regular expression, or with an initial lower case letter 3195otherwise. 3196Literal strings are quoted. 3197 3198</p> 3199 3200<p>Within the expression on the right-hand side of a rule, the following 3201expressions are used to match strings of one or more characters: 3202<glist> 3203<gitem> 3204<label><code>#xN</code></label> 3205<def><p>where <code>N</code> is a hexadecimal integer, the 3206expression matches the character in ISO/IEC 10646 whose canonical 3207(UCS-4) 3208code value, when interpreted as an unsigned binary number, has 3209the value indicated. The number of leading zeros in the 3210<code>#xN</code> form is insignificant; the number of leading 3211zeros in the corresponding code value 3212is governed by the character 3213encoding in use and is not significant for XML.</p></def> 3214</gitem> 3215<gitem> 3216<label><code>[a-zA-Z]</code>, <code>[#xN-#xN]</code></label> 3217<def><p>matches any <termref def="dt-character">character</termref> 3218with a value in the range(s) indicated (inclusive).</p></def> 3219</gitem> 3220<gitem> 3221<label><code>[^a-z]</code>, <code>[^#xN-#xN]</code></label> 3222<def><p>matches any <termref def="dt-character">character</termref> 3223with a value <emph>outside</emph> the 3224range indicated.</p></def> 3225</gitem> 3226<gitem> 3227<label><code>[^abc]</code>, <code>[^#xN#xN#xN]</code></label> 3228<def><p>matches any <termref def="dt-character">character</termref> 3229with a value not among the characters given.</p></def> 3230</gitem> 3231<gitem> 3232<label><code>"string"</code></label> 3233<def><p>matches a literal string <termref def="dt-match">matching</termref> 3234that given inside the double quotes.</p></def> 3235</gitem> 3236<gitem> 3237<label><code>'string'</code></label> 3238<def><p>matches a literal string <termref def="dt-match">matching</termref> 3239that given inside the single quotes.</p></def> 3240</gitem> 3241</glist> 3242These symbols may be combined to match more complex patterns as follows, 3243where <code>A</code> and <code>B</code> represent simple expressions: 3244<glist> 3245<gitem> 3246<label>(<code>expression</code>)</label> 3247<def><p><code>expression</code> is treated as a unit 3248and may be combined as described in this list.</p></def> 3249</gitem> 3250<gitem> 3251<label><code>A?</code></label> 3252<def><p>matches <code>A</code> or nothing; optional <code>A</code>.</p></def> 3253</gitem> 3254<gitem> 3255<label><code>A B</code></label> 3256<def><p>matches <code>A</code> followed by <code>B</code>.</p></def> 3257</gitem> 3258<gitem> 3259<label><code>A | B</code></label> 3260<def><p>matches <code>A</code> or <code>B</code> but not both.</p></def> 3261</gitem> 3262<gitem> 3263<label><code>A - B</code></label> 3264<def><p>matches any string that matches <code>A</code> but does not match 3265<code>B</code>. 3266</p></def> 3267</gitem> 3268<gitem> 3269<label><code>A+</code></label> 3270<def><p>matches one or more occurrences of <code>A</code>.</p></def> 3271</gitem> 3272<gitem> 3273<label><code>A*</code></label> 3274<def><p>matches zero or more occurrences of <code>A</code>.</p></def> 3275</gitem> 3276 3277</glist> 3278Other notations used in the productions are: 3279<glist> 3280<gitem> 3281<label><code>/* ... */</code></label> 3282<def><p>comment.</p></def> 3283</gitem> 3284<gitem> 3285<label><code>[ wfc: ... ]</code></label> 3286<def><p>well-formedness constraint; this identifies by name a 3287constraint on 3288<termref def="dt-wellformed">well-formed</termref> documents 3289associated with a production.</p></def> 3290</gitem> 3291<gitem> 3292<label><code>[ vc: ... ]</code></label> 3293<def><p>validity constraint; this identifies by name a constraint on 3294<termref def="dt-valid">valid</termref> documents associated with 3295a production.</p></def> 3296</gitem> 3297</glist> 3298</p></div1> 3299 3300</body> 3301<back> 3302<!-- &SGML; --> 3303 3304 3305<!-- &Biblio; --> 3306<div1 id="sec-bibliography"> 3307 3308<head>References</head> 3309<div2 id="sec-existing-stds"> 3310<head>Normative References</head> 3311 3312<blist> 3313<bibl id="IANA" key="IANA"> 3314(Internet Assigned Numbers Authority) <emph>Official Names for 3315Character Sets</emph>, 3316ed. Keld Simonsen et al. 3317See <loc href="ftp://ftp.isi.edu/in-notes/iana/assignments/character-sets">ftp://ftp.isi.edu/in-notes/iana/assignments/character-sets</loc>. 3318</bibl> 3319 3320<bibl id="RFC1766" key="IETF RFC 1766"> 3321IETF (Internet Engineering Task Force). 3322<emph>RFC 1766: Tags for the Identification of Languages</emph>, 3323ed. H. Alvestrand. 33241995. 3325</bibl> 3326 3327<bibl id="ISO639" key="ISO 639"> 3328(International Organization for Standardization). 3329<emph>ISO 639:1988 (E). 3330Code for the representation of names of languages.</emph> 3331[Geneva]: International Organization for 3332Standardization, 1988.</bibl> 3333 3334<bibl id="ISO3166" key="ISO 3166"> 3335(International Organization for Standardization). 3336<emph>ISO 3166-1:1997 (E). 3337Codes for the representation of names of countries and their subdivisions 3338— Part 1: Country codes</emph> 3339[Geneva]: International Organization for 3340Standardization, 1997.</bibl> 3341 3342<bibl id="ISO10646" key="ISO/IEC 10646">ISO 3343(International Organization for Standardization). 3344<emph>ISO/IEC 10646-1993 (E). Information technology — Universal 3345Multiple-Octet Coded Character Set (UCS) — Part 1: 3346Architecture and Basic Multilingual Plane.</emph> 3347[Geneva]: International Organization for 3348Standardization, 1993 (plus amendments AM 1 through AM 7). 3349</bibl> 3350 3351<bibl id="Unicode" key="Unicode">The Unicode Consortium. 3352<emph>The Unicode Standard, Version 2.0.</emph> 3353Reading, Mass.: Addison-Wesley Developers Press, 1996.</bibl> 3354 3355</blist> 3356 3357</div2> 3358 3359<div2><head>Other References</head> 3360 3361<blist> 3362 3363<bibl id="Aho" key="Aho/Ullman">Aho, Alfred V., 3364Ravi Sethi, and Jeffrey D. Ullman. 3365<emph>Compilers: Principles, Techniques, and Tools</emph>. 3366Reading: Addison-Wesley, 1986, rpt. corr. 1988.</bibl> 3367 3368<bibl id="Berners-Lee" xml-link="simple" key="Berners-Lee et al."> 3369Berners-Lee, T., R. Fielding, and L. Masinter. 3370<emph>Uniform Resource Identifiers (URI): Generic Syntax and 3371Semantics</emph>. 33721997. 3373(Work in progress; see updates to RFC1738.)</bibl> 3374 3375<bibl id="ABK" key="Br�ggemann-Klein">Br�ggemann-Klein, Anne. 3376<emph>Regular Expressions into Finite Automata</emph>. 3377Extended abstract in I. Simon, Hrsg., LATIN 1992, 3378S. 97-98. Springer-Verlag, Berlin 1992. 3379Full Version in Theoretical Computer Science 120: 197-213, 1993. 3380 3381</bibl> 3382 3383<bibl id="ABKDW" key="Br�ggemann-Klein and Wood">Br�ggemann-Klein, Anne, 3384and Derick Wood. 3385<emph>Deterministic Regular Languages</emph>. 3386Universit�t Freiburg, Institut f�r Informatik, 3387Bericht 38, Oktober 1991. 3388</bibl> 3389 3390<bibl id="Clark" key="Clark">James Clark. 3391Comparison of SGML and XML. See 3392<loc href="http://www.w3.org/TR/NOTE-sgml-xml-971215">http://www.w3.org/TR/NOTE-sgml-xml-971215</loc>. 3393</bibl> 3394<bibl id="RFC1738" xml-link="simple" key="IETF RFC1738"> 3395IETF (Internet Engineering Task Force). 3396<emph>RFC 1738: Uniform Resource Locators (URL)</emph>, 3397ed. T. Berners-Lee, L. Masinter, M. McCahill. 33981994. 3399</bibl> 3400 3401<bibl id="RFC1808" xml-link="simple" key="IETF RFC1808"> 3402IETF (Internet Engineering Task Force). 3403<emph>RFC 1808: Relative Uniform Resource Locators</emph>, 3404ed. R. Fielding. 34051995. 3406</bibl> 3407 3408<bibl id="RFC2141" xml-link="simple" key="IETF RFC2141"> 3409IETF (Internet Engineering Task Force). 3410<emph>RFC 2141: URN Syntax</emph>, 3411ed. R. Moats. 34121997. 3413</bibl> 3414 3415<bibl id="ISO8879" key="ISO 8879">ISO 3416(International Organization for Standardization). 3417<emph>ISO 8879:1986(E). Information processing — Text and Office 3418Systems — Standard Generalized Markup Language (SGML).</emph> First 3419edition — 1986-10-15. [Geneva]: International Organization for 3420Standardization, 1986. 3421</bibl> 3422 3423 3424<bibl id="ISO10744" key="ISO/IEC 10744">ISO 3425(International Organization for Standardization). 3426<emph>ISO/IEC 10744-1992 (E). Information technology — 3427Hypermedia/Time-based Structuring Language (HyTime). 3428</emph> 3429[Geneva]: International Organization for 3430Standardization, 1992. 3431<emph>Extended Facilities Annexe.</emph> 3432[Geneva]: International Organization for 3433Standardization, 1996. 3434</bibl> 3435 3436 3437 3438</blist> 3439</div2> 3440</div1> 3441<div1 id="CharClasses"> 3442<head>Character Classes</head> 3443<p>Following the characteristics defined in the Unicode standard, 3444characters are classed as base characters (among others, these 3445contain the alphabetic characters of the Latin alphabet, without 3446diacritics), ideographic characters, and combining characters (among 3447others, this class contains most diacritics); these classes combine 3448to form the class of letters. Digits and extenders are 3449also distinguished. 3450<scrap lang="ebnf" id="CHARACTERS"> 3451<head>Characters</head> 3452<prodgroup pcw3="3" pcw4="15"> 3453<prod id="NT-Letter"><lhs>Letter</lhs> 3454<rhs><nt def="NT-BaseChar">BaseChar</nt> 3455| <nt def="NT-Ideographic">Ideographic</nt></rhs> </prod> 3456<prod id="NT-BaseChar"><lhs>BaseChar</lhs> 3457<rhs>[#x0041-#x005A] 3458| [#x0061-#x007A] 3459| [#x00C0-#x00D6] 3460| [#x00D8-#x00F6] 3461| [#x00F8-#x00FF] 3462| [#x0100-#x0131] 3463| [#x0134-#x013E] 3464| [#x0141-#x0148] 3465| [#x014A-#x017E] 3466| [#x0180-#x01C3] 3467| [#x01CD-#x01F0] 3468| [#x01F4-#x01F5] 3469| [#x01FA-#x0217] 3470| [#x0250-#x02A8] 3471| [#x02BB-#x02C1] 3472| #x0386 3473| [#x0388-#x038A] 3474| #x038C 3475| [#x038E-#x03A1] 3476| [#x03A3-#x03CE] 3477| [#x03D0-#x03D6] 3478| #x03DA 3479| #x03DC 3480| #x03DE 3481| #x03E0 3482| [#x03E2-#x03F3] 3483| [#x0401-#x040C] 3484| [#x040E-#x044F] 3485| [#x0451-#x045C] 3486| [#x045E-#x0481] 3487| [#x0490-#x04C4] 3488| [#x04C7-#x04C8] 3489| [#x04CB-#x04CC] 3490| [#x04D0-#x04EB] 3491| [#x04EE-#x04F5] 3492| [#x04F8-#x04F9] 3493| [#x0531-#x0556] 3494| #x0559 3495| [#x0561-#x0586] 3496| [#x05D0-#x05EA] 3497| [#x05F0-#x05F2] 3498| [#x0621-#x063A] 3499| [#x0641-#x064A] 3500| [#x0671-#x06B7] 3501| [#x06BA-#x06BE] 3502| [#x06C0-#x06CE] 3503| [#x06D0-#x06D3] 3504| #x06D5 3505| [#x06E5-#x06E6] 3506| [#x0905-#x0939] 3507| #x093D 3508| [#x0958-#x0961] 3509| [#x0985-#x098C] 3510| [#x098F-#x0990] 3511| [#x0993-#x09A8] 3512| [#x09AA-#x09B0] 3513| #x09B2 3514| [#x09B6-#x09B9] 3515| [#x09DC-#x09DD] 3516| [#x09DF-#x09E1] 3517| [#x09F0-#x09F1] 3518| [#x0A05-#x0A0A] 3519| [#x0A0F-#x0A10] 3520| [#x0A13-#x0A28] 3521| [#x0A2A-#x0A30] 3522| [#x0A32-#x0A33] 3523| [#x0A35-#x0A36] 3524| [#x0A38-#x0A39] 3525| [#x0A59-#x0A5C] 3526| #x0A5E 3527| [#x0A72-#x0A74] 3528| [#x0A85-#x0A8B] 3529| #x0A8D 3530| [#x0A8F-#x0A91] 3531| [#x0A93-#x0AA8] 3532| [#x0AAA-#x0AB0] 3533| [#x0AB2-#x0AB3] 3534| [#x0AB5-#x0AB9] 3535| #x0ABD 3536| #x0AE0 3537| [#x0B05-#x0B0C] 3538| [#x0B0F-#x0B10] 3539| [#x0B13-#x0B28] 3540| [#x0B2A-#x0B30] 3541| [#x0B32-#x0B33] 3542| [#x0B36-#x0B39] 3543| #x0B3D 3544| [#x0B5C-#x0B5D] 3545| [#x0B5F-#x0B61] 3546| [#x0B85-#x0B8A] 3547| [#x0B8E-#x0B90] 3548| [#x0B92-#x0B95] 3549| [#x0B99-#x0B9A] 3550| #x0B9C 3551| [#x0B9E-#x0B9F] 3552| [#x0BA3-#x0BA4] 3553| [#x0BA8-#x0BAA] 3554| [#x0BAE-#x0BB5] 3555| [#x0BB7-#x0BB9] 3556| [#x0C05-#x0C0C] 3557| [#x0C0E-#x0C10] 3558| [#x0C12-#x0C28] 3559| [#x0C2A-#x0C33] 3560| [#x0C35-#x0C39] 3561| [#x0C60-#x0C61] 3562| [#x0C85-#x0C8C] 3563| [#x0C8E-#x0C90] 3564| [#x0C92-#x0CA8] 3565| [#x0CAA-#x0CB3] 3566| [#x0CB5-#x0CB9] 3567| #x0CDE 3568| [#x0CE0-#x0CE1] 3569| [#x0D05-#x0D0C] 3570| [#x0D0E-#x0D10] 3571| [#x0D12-#x0D28] 3572| [#x0D2A-#x0D39] 3573| [#x0D60-#x0D61] 3574| [#x0E01-#x0E2E] 3575| #x0E30 3576| [#x0E32-#x0E33] 3577| [#x0E40-#x0E45] 3578| [#x0E81-#x0E82] 3579| #x0E84 3580| [#x0E87-#x0E88] 3581| #x0E8A 3582| #x0E8D 3583| [#x0E94-#x0E97] 3584| [#x0E99-#x0E9F] 3585| [#x0EA1-#x0EA3] 3586| #x0EA5 3587| #x0EA7 3588| [#x0EAA-#x0EAB] 3589| [#x0EAD-#x0EAE] 3590| #x0EB0 3591| [#x0EB2-#x0EB3] 3592| #x0EBD 3593| [#x0EC0-#x0EC4] 3594| [#x0F40-#x0F47] 3595| [#x0F49-#x0F69] 3596| [#x10A0-#x10C5] 3597| [#x10D0-#x10F6] 3598| #x1100 3599| [#x1102-#x1103] 3600| [#x1105-#x1107] 3601| #x1109 3602| [#x110B-#x110C] 3603| [#x110E-#x1112] 3604| #x113C 3605| #x113E 3606| #x1140 3607| #x114C 3608| #x114E 3609| #x1150 3610| [#x1154-#x1155] 3611| #x1159 3612| [#x115F-#x1161] 3613| #x1163 3614| #x1165 3615| #x1167 3616| #x1169 3617| [#x116D-#x116E] 3618| [#x1172-#x1173] 3619| #x1175 3620| #x119E 3621| #x11A8 3622| #x11AB 3623| [#x11AE-#x11AF] 3624| [#x11B7-#x11B8] 3625| #x11BA 3626| [#x11BC-#x11C2] 3627| #x11EB 3628| #x11F0 3629| #x11F9 3630| [#x1E00-#x1E9B] 3631| [#x1EA0-#x1EF9] 3632| [#x1F00-#x1F15] 3633| [#x1F18-#x1F1D] 3634| [#x1F20-#x1F45] 3635| [#x1F48-#x1F4D] 3636| [#x1F50-#x1F57] 3637| #x1F59 3638| #x1F5B 3639| #x1F5D 3640| [#x1F5F-#x1F7D] 3641| [#x1F80-#x1FB4] 3642| [#x1FB6-#x1FBC] 3643| #x1FBE 3644| [#x1FC2-#x1FC4] 3645| [#x1FC6-#x1FCC] 3646| [#x1FD0-#x1FD3] 3647| [#x1FD6-#x1FDB] 3648| [#x1FE0-#x1FEC] 3649| [#x1FF2-#x1FF4] 3650| [#x1FF6-#x1FFC] 3651| #x2126 3652| [#x212A-#x212B] 3653| #x212E 3654| [#x2180-#x2182] 3655| [#x3041-#x3094] 3656| [#x30A1-#x30FA] 3657| [#x3105-#x312C] 3658| [#xAC00-#xD7A3] 3659</rhs></prod> 3660<prod id="NT-Ideographic"><lhs>Ideographic</lhs> 3661<rhs>[#x4E00-#x9FA5] 3662| #x3007 3663| [#x3021-#x3029] 3664</rhs></prod> 3665<prod id="NT-CombiningChar"><lhs>CombiningChar</lhs> 3666<rhs>[#x0300-#x0345] 3667| [#x0360-#x0361] 3668| [#x0483-#x0486] 3669| [#x0591-#x05A1] 3670| [#x05A3-#x05B9] 3671| [#x05BB-#x05BD] 3672| #x05BF 3673| [#x05C1-#x05C2] 3674| #x05C4 3675| [#x064B-#x0652] 3676| #x0670 3677| [#x06D6-#x06DC] 3678| [#x06DD-#x06DF] 3679| [#x06E0-#x06E4] 3680| [#x06E7-#x06E8] 3681| [#x06EA-#x06ED] 3682| [#x0901-#x0903] 3683| #x093C 3684| [#x093E-#x094C] 3685| #x094D 3686| [#x0951-#x0954] 3687| [#x0962-#x0963] 3688| [#x0981-#x0983] 3689| #x09BC 3690| #x09BE 3691| #x09BF 3692| [#x09C0-#x09C4] 3693| [#x09C7-#x09C8] 3694| [#x09CB-#x09CD] 3695| #x09D7 3696| [#x09E2-#x09E3] 3697| #x0A02 3698| #x0A3C 3699| #x0A3E 3700| #x0A3F 3701| [#x0A40-#x0A42] 3702| [#x0A47-#x0A48] 3703| [#x0A4B-#x0A4D] 3704| [#x0A70-#x0A71] 3705| [#x0A81-#x0A83] 3706| #x0ABC 3707| [#x0ABE-#x0AC5] 3708| [#x0AC7-#x0AC9] 3709| [#x0ACB-#x0ACD] 3710| [#x0B01-#x0B03] 3711| #x0B3C 3712| [#x0B3E-#x0B43] 3713| [#x0B47-#x0B48] 3714| [#x0B4B-#x0B4D] 3715| [#x0B56-#x0B57] 3716| [#x0B82-#x0B83] 3717| [#x0BBE-#x0BC2] 3718| [#x0BC6-#x0BC8] 3719| [#x0BCA-#x0BCD] 3720| #x0BD7 3721| [#x0C01-#x0C03] 3722| [#x0C3E-#x0C44] 3723| [#x0C46-#x0C48] 3724| [#x0C4A-#x0C4D] 3725| [#x0C55-#x0C56] 3726| [#x0C82-#x0C83] 3727| [#x0CBE-#x0CC4] 3728| [#x0CC6-#x0CC8] 3729| [#x0CCA-#x0CCD] 3730| [#x0CD5-#x0CD6] 3731| [#x0D02-#x0D03] 3732| [#x0D3E-#x0D43] 3733| [#x0D46-#x0D48] 3734| [#x0D4A-#x0D4D] 3735| #x0D57 3736| #x0E31 3737| [#x0E34-#x0E3A] 3738| [#x0E47-#x0E4E] 3739| #x0EB1 3740| [#x0EB4-#x0EB9] 3741| [#x0EBB-#x0EBC] 3742| [#x0EC8-#x0ECD] 3743| [#x0F18-#x0F19] 3744| #x0F35 3745| #x0F37 3746| #x0F39 3747| #x0F3E 3748| #x0F3F 3749| [#x0F71-#x0F84] 3750| [#x0F86-#x0F8B] 3751| [#x0F90-#x0F95] 3752| #x0F97 3753| [#x0F99-#x0FAD] 3754| [#x0FB1-#x0FB7] 3755| #x0FB9 3756| [#x20D0-#x20DC] 3757| #x20E1 3758| [#x302A-#x302F] 3759| #x3099 3760| #x309A 3761</rhs></prod> 3762<prod id="NT-Digit"><lhs>Digit</lhs> 3763<rhs>[#x0030-#x0039] 3764| [#x0660-#x0669] 3765| [#x06F0-#x06F9] 3766| [#x0966-#x096F] 3767| [#x09E6-#x09EF] 3768| [#x0A66-#x0A6F] 3769| [#x0AE6-#x0AEF] 3770| [#x0B66-#x0B6F] 3771| [#x0BE7-#x0BEF] 3772| [#x0C66-#x0C6F] 3773| [#x0CE6-#x0CEF] 3774| [#x0D66-#x0D6F] 3775| [#x0E50-#x0E59] 3776| [#x0ED0-#x0ED9] 3777| [#x0F20-#x0F29] 3778</rhs></prod> 3779<prod id="NT-Extender"><lhs>Extender</lhs> 3780<rhs>#x00B7 3781| #x02D0 3782| #x02D1 3783| #x0387 3784| #x0640 3785| #x0E46 3786| #x0EC6 3787| #x3005 3788| [#x3031-#x3035] 3789| [#x309D-#x309E] 3790| [#x30FC-#x30FE] 3791</rhs></prod> 3792 3793</prodgroup> 3794</scrap> 3795</p> 3796<p>The character classes defined here can be derived from the 3797Unicode character database as follows: 3798<ulist> 3799<item> 3800<p>Name start characters must have one of the categories Ll, Lu, 3801Lo, Lt, Nl.</p> 3802</item> 3803<item> 3804<p>Name characters other than Name-start characters 3805must have one of the categories Mc, Me, Mn, Lm, or Nd.</p> 3806</item> 3807<item> 3808<p>Characters in the compatibility area (i.e. with character code 3809greater than #xF900 and less than #xFFFE) are not allowed in XML 3810names.</p> 3811</item> 3812<item> 3813<p>Characters which have a font or compatibility decomposition (i.e. those 3814with a "compatibility formatting tag" in field 5 of the database -- 3815marked by field 5 beginning with a "<") are not allowed.</p> 3816</item> 3817<item> 3818<p>The following characters are treated as name-start characters 3819rather than name characters, because the property file classifies 3820them as Alphabetic: [#x02BB-#x02C1], #x0559, #x06E5, #x06E6.</p> 3821</item> 3822<item> 3823<p>Characters #x20DD-#x20E0 are excluded (in accordance with 3824Unicode, section 5.14).</p> 3825</item> 3826<item> 3827<p>Character #x00B7 is classified as an extender, because the 3828property list so identifies it.</p> 3829</item> 3830<item> 3831<p>Character #x0387 is added as a name character, because #x00B7 3832is its canonical equivalent.</p> 3833</item> 3834<item> 3835<p>Characters ':' and '_' are allowed as name-start characters.</p> 3836</item> 3837<item> 3838<p>Characters '-' and '.' are allowed as name characters.</p> 3839</item> 3840</ulist> 3841</p> 3842</div1> 3843<inform-div1 id="sec-xml-and-sgml"> 3844<head>XML and SGML</head> 3845 3846<p>XML is designed to be a subset of SGML, in that every 3847<termref def="dt-valid">valid</termref> XML document should also be a 3848conformant SGML document. 3849For a detailed comparison of the additional restrictions that XML places on 3850documents beyond those of SGML, see <bibref ref="Clark"/>. 3851</p> 3852</inform-div1> 3853<inform-div1 id="sec-entexpand"> 3854<head>Expansion of Entity and Character References</head> 3855<p>This appendix contains some examples illustrating the 3856sequence of entity- and character-reference recognition and 3857expansion, as specified in <specref ref="entproc"/>.</p> 3858<p> 3859If the DTD contains the declaration 3860<eg><![CDATA[<!ENTITY example "<p>An ampersand (&#38;) may be escaped 3861numerically (&#38;#38;) or with a general entity 3862(&amp;).</p>" > 3863]]></eg> 3864then the XML processor will recognize the character references 3865when it parses the entity declaration, and resolve them before 3866storing the following string as the 3867value of the entity "<code>example</code>": 3868<eg><![CDATA[<p>An ampersand (&) may be escaped 3869numerically (&#38;) or with a general entity 3870(&amp;).</p> 3871]]></eg> 3872A reference in the document to "<code>&example;</code>" 3873will cause the text to be reparsed, at which time the 3874start- and end-tags of the "<code>p</code>" element will be recognized 3875and the three references will be recognized and expanded, 3876resulting in a "<code>p</code>" element with the following content 3877(all data, no delimiters or markup): 3878<eg><![CDATA[An ampersand (&) may be escaped 3879numerically (&) or with a general entity 3880(&). 3881]]></eg> 3882</p> 3883<p>A more complex example will illustrate the rules and their 3884effects fully. In the following example, the line numbers are 3885solely for reference. 3886<eg><![CDATA[1 <?xml version='1.0'?> 38872 <!DOCTYPE test [ 38883 <!ELEMENT test (#PCDATA) > 38894 <!ENTITY % xx '%zz;'> 38905 <!ENTITY % zz '<!ENTITY tricky "error-prone" >' > 38916 %xx; 38927 ]> 38938 <test>This sample shows a &tricky; method.</test> 3894]]></eg> 3895This produces the following: 3896<ulist spacing="compact"> 3897<item><p>in line 4, the reference to character 37 is expanded immediately, 3898and the parameter entity "<code>xx</code>" is stored in the symbol 3899table with the value "<code>%zz;</code>". Since the replacement text 3900is not rescanned, the reference to parameter entity "<code>zz</code>" 3901is not recognized. (And it would be an error if it were, since 3902"<code>zz</code>" is not yet declared.)</p></item> 3903<item><p>in line 5, the character reference "<code>&#60;</code>" is 3904expanded immediately and the parameter entity "<code>zz</code>" is 3905stored with the replacement text 3906"<code><!ENTITY tricky "error-prone" ></code>", 3907which is a well-formed entity declaration.</p></item> 3908<item><p>in line 6, the reference to "<code>xx</code>" is recognized, 3909and the replacement text of "<code>xx</code>" (namely 3910"<code>%zz;</code>") is parsed. The reference to "<code>zz</code>" 3911is recognized in its turn, and its replacement text 3912("<code><!ENTITY tricky "error-prone" ></code>") is parsed. 3913The general entity "<code>tricky</code>" has now been 3914declared, with the replacement text "<code>error-prone</code>".</p></item> 3915<item><p> 3916in line 8, the reference to the general entity "<code>tricky</code>" is 3917recognized, and it is expanded, so the full content of the 3918"<code>test</code>" element is the self-describing (and ungrammatical) string 3919<emph>This sample shows a error-prone method.</emph> 3920</p></item> 3921</ulist> 3922</p> 3923</inform-div1> 3924<inform-div1 id="determinism"> 3925<head>Deterministic Content Models</head> 3926<p><termref def="dt-compat">For compatibility</termref>, it is 3927required 3928that content models in element type declarations be deterministic. 3929</p> 3930<!-- FINAL EDIT: WebSGML allows ambiguity? --> 3931<p>SGML 3932requires deterministic content models (it calls them 3933"unambiguous"); XML processors built using SGML systems may 3934flag non-deterministic content models as errors.</p> 3935<p>For example, the content model <code>((b, c) | (b, d))</code> is 3936non-deterministic, because given an initial <code>b</code> the parser 3937cannot know which <code>b</code> in the model is being matched without 3938looking ahead to see which element follows the <code>b</code>. 3939In this case, the two references to 3940<code>b</code> can be collapsed 3941into a single reference, making the model read 3942<code>(b, (c | d))</code>. An initial <code>b</code> now clearly 3943matches only a single name in the content model. The parser doesn't 3944need to look ahead to see what follows; either <code>c</code> or 3945<code>d</code> would be accepted.</p> 3946<p>More formally: a finite state automaton may be constructed from the 3947content model using the standard algorithms, e.g. algorithm 3.5 3948in section 3.9 3949of Aho, Sethi, and Ullman <bibref ref="Aho"/>. 3950In many such algorithms, a follow set is constructed for each 3951position in the regular expression (i.e., each leaf 3952node in the 3953syntax tree for the regular expression); 3954if any position has a follow set in which 3955more than one following position is 3956labeled with the same element type name, 3957then the content model is in error 3958and may be reported as an error. 3959</p> 3960<p>Algorithms exist which allow many but not all non-deterministic 3961content models to be reduced automatically to equivalent deterministic 3962models; see Br�ggemann-Klein 1991 <bibref ref="ABK"/>.</p> 3963</inform-div1> 3964<inform-div1 id="sec-guessing"> 3965<head>Autodetection of Character Encodings</head> 3966<p>The XML encoding declaration functions as an internal label on each 3967entity, indicating which character encoding is in use. Before an XML 3968processor can read the internal label, however, it apparently has to 3969know what character encoding is in use—which is what the internal label 3970is trying to indicate. In the general case, this is a hopeless 3971situation. It is not entirely hopeless in XML, however, because XML 3972limits the general case in two ways: each implementation is assumed 3973to support only a finite set of character encodings, and the XML 3974encoding declaration is restricted in position and content in order to 3975make it feasible to autodetect the character encoding in use in each 3976entity in normal cases. Also, in many cases other sources of information 3977are available in addition to the XML data stream itself. 3978Two cases may be distinguished, 3979depending on whether the XML entity is presented to the 3980processor without, or with, any accompanying 3981(external) information. We consider the first case first. 3982</p> 3983<p> 3984Because each XML entity not in UTF-8 or UTF-16 format <emph>must</emph> 3985begin with an XML encoding declaration, in which the first characters 3986must be '<code><?xml</code>', any conforming processor can detect, 3987after two to four octets of input, which of the following cases apply. 3988In reading this list, it may help to know that in UCS-4, '<' is 3989"<code>#x0000003C</code>" and '?' is "<code>#x0000003F</code>", and the Byte 3990Order Mark required of UTF-16 data streams is "<code>#xFEFF</code>".</p> 3991<p> 3992<ulist> 3993<item> 3994<p><code>00 00 00 3C</code>: UCS-4, big-endian machine (1234 order)</p> 3995</item> 3996<item> 3997<p><code>3C 00 00 00</code>: UCS-4, little-endian machine (4321 order)</p> 3998</item> 3999<item> 4000<p><code>00 00 3C 00</code>: UCS-4, unusual octet order (2143)</p> 4001</item> 4002<item> 4003<p><code>00 3C 00 00</code>: UCS-4, unusual octet order (3412)</p> 4004</item> 4005<item> 4006<p><code>FE FF</code>: UTF-16, big-endian</p> 4007</item> 4008<item> 4009<p><code>FF FE</code>: UTF-16, little-endian</p> 4010</item> 4011<item> 4012<p><code>00 3C 00 3F</code>: UTF-16, big-endian, no Byte Order Mark 4013(and thus, strictly speaking, in error)</p> 4014</item> 4015<item> 4016<p><code>3C 00 3F 00</code>: UTF-16, little-endian, no Byte Order Mark 4017(and thus, strictly speaking, in error)</p> 4018</item> 4019<item> 4020<p><code>3C 3F 78 6D</code>: UTF-8, ISO 646, ASCII, some part of ISO 8859, 4021Shift-JIS, EUC, or any other 7-bit, 8-bit, or mixed-width encoding 4022which ensures that the characters of ASCII have their normal positions, 4023width, 4024and values; the actual encoding declaration must be read to 4025detect which of these applies, but since all of these encodings 4026use the same bit patterns for the ASCII characters, the encoding 4027declaration itself may be read reliably 4028</p> 4029</item> 4030<item> 4031<p><code>4C 6F A7 94</code>: EBCDIC (in some flavor; the full 4032encoding declaration must be read to tell which code page is in 4033use)</p> 4034</item> 4035<item> 4036<p>other: UTF-8 without an encoding declaration, or else 4037the data stream is corrupt, fragmentary, or enclosed in 4038a wrapper of some kind</p> 4039</item> 4040</ulist> 4041</p> 4042<p> 4043This level of autodetection is enough to read the XML encoding 4044declaration and parse the character-encoding identifier, which is 4045still necessary to distinguish the individual members of each family 4046of encodings (e.g. to tell UTF-8 from 8859, and the parts of 8859 4047from each other, or to distinguish the specific EBCDIC code page in 4048use, and so on). 4049</p> 4050<p> 4051Because the contents of the encoding declaration are restricted to 4052ASCII characters, a processor can reliably read the entire encoding 4053declaration as soon as it has detected which family of encodings is in 4054use. Since in practice, all widely used character encodings fall into 4055one of the categories above, the XML encoding declaration allows 4056reasonably reliable in-band labeling of character encodings, even when 4057external sources of information at the operating-system or 4058transport-protocol level are unreliable. 4059</p> 4060<p> 4061Once the processor has detected the character encoding in use, it can 4062act appropriately, whether by invoking a separate input routine for 4063each case, or by calling the proper conversion function on each 4064character of input. 4065</p> 4066<p> 4067Like any self-labeling system, the XML encoding declaration will not 4068work if any software changes the entity's character set or encoding 4069without updating the encoding declaration. Implementors of 4070character-encoding routines should be careful to ensure the accuracy 4071of the internal and external information used to label the entity. 4072</p> 4073<p>The second possible case occurs when the XML entity is accompanied 4074by encoding information, as in some file systems and some network 4075protocols. 4076When multiple sources of information are available, 4077 4078their relative 4079priority and the preferred method of handling conflict should be 4080specified as part of the higher-level protocol used to deliver XML. 4081Rules for the relative priority of the internal label and the 4082MIME-type label in an external header, for example, should be part of the 4083RFC document defining the text/xml and application/xml MIME types. In 4084the interests of interoperability, however, the following rules 4085are recommended. 4086<ulist> 4087<item><p>If an XML entity is in a file, the Byte-Order Mark 4088and encoding-declaration PI are used (if present) to determine the 4089character encoding. All other heuristics and sources of information 4090are solely for error recovery. 4091</p></item> 4092<item><p>If an XML entity is delivered with a 4093MIME type of text/xml, then the <code>charset</code> parameter 4094on the MIME type determines the 4095character encoding method; all other heuristics and sources of 4096information are solely for error recovery. 4097</p></item> 4098<item><p>If an XML entity is delivered 4099with a 4100MIME type of application/xml, then the Byte-Order Mark and 4101encoding-declaration PI are used (if present) to determine the 4102character encoding. All other heuristics and sources of 4103information are solely for error recovery. 4104</p></item> 4105</ulist> 4106These rules apply only in the absence of protocol-level documentation; 4107in particular, when the MIME types text/xml and application/xml are 4108defined, the recommendations of the relevant RFC will supersede 4109these rules. 4110</p> 4111 4112</inform-div1> 4113 4114<inform-div1 id="sec-xml-wg"> 4115<head>W3C XML Working Group</head> 4116 4117<p>This specification was prepared and approved for publication by the 4118W3C XML Working Group (WG). WG approval of this specification does 4119not necessarily imply that all WG members voted for its approval. 4120The current and former members of the XML WG are:</p> 4121 4122<orglist> 4123<member><name>Jon Bosak, Sun</name><role>Chair</role></member> 4124<member><name>James Clark</name><role>Technical Lead</role></member> 4125<member><name>Tim Bray, Textuality and Netscape</name><role>XML Co-editor</role></member> 4126<member><name>Jean Paoli, Microsoft</name><role>XML Co-editor</role></member> 4127<member><name>C. M. Sperberg-McQueen, U. of Ill.</name><role>XML 4128Co-editor</role></member> 4129<member><name>Dan Connolly, W3C</name><role>W3C Liaison</role></member> 4130<member><name>Paula Angerstein, Texcel</name></member> 4131<member><name>Steve DeRose, INSO</name></member> 4132<member><name>Dave Hollander, HP</name></member> 4133<member><name>Eliot Kimber, ISOGEN</name></member> 4134<member><name>Eve Maler, ArborText</name></member> 4135<member><name>Tom Magliery, NCSA</name></member> 4136<member><name>Murray Maloney, Muzmo and Grif</name></member> 4137<member><name>Makoto Murata, Fuji Xerox Information Systems</name></member> 4138<member><name>Joel Nava, Adobe</name></member> 4139<member><name>Conleth O'Connell, Vignette</name></member> 4140<member><name>Peter Sharpe, SoftQuad</name></member> 4141<member><name>John Tigue, DataChannel</name></member> 4142</orglist> 4143 4144</inform-div1> 4145</back> 4146</spec> 4147<!-- Keep this comment at the end of the file 4148Local variables: 4149mode: sgml 4150sgml-default-dtd-file:"~/sgml/spec.ced" 4151sgml-omittag:t 4152sgml-shorttag:t 4153End: 4154--> 4155