Annotation of html5/spec/syntax.html, revision 1.108

1.2       mike        1: <!DOCTYPE HTML>
1.12      mike        2: <html lang="en-US-x-Hixie"><head><title>9 The HTML syntax &#8212; HTML 5</title><style type="text/css">
1.1       mike        3:    pre { margin-left: 2em; white-space: pre-wrap; }
                      4:    h2 { margin: 3em 0 1em 0; }
                      5:    h3 { margin: 2.5em 0 1em 0; }
                      6:    h4 { margin: 2.5em 0 0.75em 0; }
                      7:    h5, h6 { margin: 2.5em 0 1em; }
                      8:    h1 + h2, h1 + h2 + h2 { margin: 0.75em 0 0.75em; }
                      9:    h2 + h3, h3 + h4, h4 + h5, h5 + h6 { margin-top: 0.5em; }
                     10:    p { margin: 1em 0; }
                     11:    hr:not(.top) { display: block; background: none; border: none; padding: 0; margin: 2em 0; height: auto; }
                     12:    dl, dd { margin-top: 0; margin-bottom: 0; }
                     13:    dt { margin-top: 0.75em; margin-bottom: 0.25em; clear: left; }
                     14:    dt + dt { margin-top: 0; }
                     15:    dd dt { margin-top: 0.25em; margin-bottom: 0; }
                     16:    dd p { margin-top: 0; }
                     17:    dd dl + p { margin-top: 1em; }
                     18:    dd table + p { margin-top: 1em; }
                     19:    p + * > li, dd li { margin: 1em 0; }
                     20:    dt, dfn { font-weight: bold; font-style: normal; }
                     21:    dt dfn { font-style: italic; }
                     22:    pre, code { font-size: inherit; font-family: monospace; font-variant: normal; }
                     23:    pre strong { color: black; font: inherit; font-weight: bold; background: yellow; }
                     24:    pre em { font-weight: bolder; font-style: normal; }
                     25:    @media screen { code { color: orangered; } code :link, code :visited { color: inherit; } }
                     26:    var sub { vertical-align: bottom; font-size: smaller; position: relative; top: 0.1em; }
                     27:    table { border-collapse: collapse; border-style: hidden hidden none hidden; }
                     28:    table thead { border-bottom: solid; }
                     29:    table tbody th:first-child { border-left: solid; }
                     30:    table td, table th { border-left: solid; border-right: solid; border-bottom: solid thin; vertical-align: top; padding: 0.2em; }
                     31:    blockquote { margin: 0 0 0 2em; border: 0; padding: 0; font-style: italic; }
                     32: 
                     33:    .bad, .bad *:not(.XXX) { color: gray; border-color: gray; background: transparent; }
                     34:    .matrix, .matrix td { border: none; text-align: right; }
                     35:    .matrix { margin-left: 2em; }
                     36:    .dice-example { border-collapse: collapse; border-style: hidden solid solid hidden; border-width: thin; margin-left: 3em; }
                     37:    .dice-example caption { width: 30em; font-size: smaller; font-style: italic; padding: 0.75em 0; text-align: left; }
                     38:    .dice-example td, .dice-example th { border: solid thin; width: 1.35em; height: 1.05em; text-align: center; padding: 0; }
1.2       mike       39:    .applies th > * { display: block; }
1.1       mike       40:    .applies thead code { display: block; }
                     41:    .applies td { text-align: center; }
                     42:    .applies .yes { background: yellow; }
                     43: 
                     44:    .toc dfn, h1 dfn, h2 dfn, h3 dfn, h4 dfn, h5 dfn, h6 dfn { font: inherit; }
                     45:    img.extra { float: right; }
                     46:    pre.idl { border: solid thin; background: #EEEEEE; color: black; padding: 0.5em 1em; }
                     47:    pre.idl :link, pre.idl :visited { color: inherit; background: transparent; }
                     48:    pre.css { border: solid thin; background: #FFFFEE; color: black; padding: 0.5em 1em; }
                     49:    pre.css:first-line { color: #AAAA50; }
                     50:    dl.domintro { color: green; margin: 2em 0 2em 2em; padding: 0.5em 1em; border: none; background: #EEFFEE; }
                     51:    hr + dl.domintro, div.impl + dl.domintro { margin-top: 2.5em; margin-bottom: 1.5em; }
                     52:    dl.domintro dt, dl.domintro dt * { color: black; text-decoration: none; }
                     53:    dl.domintro dd { margin: 0.5em 0 1em 2em; padding: 0; }
                     54:    dl.domintro dd p { margin: 0.5em 0; }
                     55:    dl.switch { padding-left: 2em; }
                     56:    dl.switch > dt { text-indent: -1.5em; }
                     57:    dl.switch > dt:before { content: '\21AA'; padding: 0 0.5em 0 0; display: inline-block; width: 1em; text-align: right; line-height: 0.5em; }
                     58:    dl.triple { padding: 0 0 0 1em; }
                     59:    dl.triple dt, dl.triple dd { margin: 0; display: inline }
                     60:    dl.triple dt:after { content: ':'; }
                     61:    dl.triple dd:after { content: '\A'; white-space: pre; }
                     62:    .diff-old { text-decoration: line-through; color: silver; background: transparent; }
                     63:    .diff-chg, .diff-new { text-decoration: underline; color: green; background: transparent; }
                     64:    a .diff-new { border-bottom: 1px blue solid; }
                     65: 
                     66:    h2 { page-break-before: always; }
                     67:    h1, h2, h3, h4, h5, h6 { page-break-after: avoid; }
                     68:    h1 + h2, hr + h2.no-toc { page-break-before: auto; }
                     69: 
                     70:    p > span:not([title=""]):not([class="XXX"]):not([class="impl"]), li > span:not([title=""]):not([class="XXX"]):not([class="impl"]) { border-bottom: solid #9999CC; }
                     71: 
                     72:    div.head { margin: 0 0 1em; padding: 1em 0 0 0; }
                     73:    div.head p { margin: 0; }
                     74:    div.head h1 { margin: 0; }
                     75:    div.head .logo { float: right; margin: 0 1em; }
                     76:    div.head .logo img { border: none } /* remove border from top image */
                     77:    div.head dl { margin: 1em 0; }
                     78:    p.copyright { font-size: x-small; font-style: oblique; margin: 0; }
                     79: 
                     80:    body > .toc > li { margin-top: 1em; margin-bottom: 1em; }
                     81:    body > .toc.brief > li { margin-top: 0.35em; margin-bottom: 0.35em; }
                     82:    body > .toc > li > * { margin-bottom: 0.5em; }
                     83:    body > .toc > li > * > li > * { margin-bottom: 0.25em; }
                     84:    .toc, .toc li { list-style: none; }
                     85: 
                     86:    .brief { margin-top: 1em; margin-bottom: 1em; line-height: 1.1; }
                     87:    .brief li { margin: 0; padding: 0; }
                     88:    .brief li p { margin: 0; padding: 0; }
                     89: 
                     90:    .category-list { margin-top: -0.75em; margin-bottom: 1em; line-height: 1.5; }
                     91:    .category-list::before { content: '\21D2\A0'; font-size: 1.2em; font-weight: 900; }
                     92:    .category-list li { display: inline; }
                     93:    .category-list li:not(:last-child)::after { content: ', '; }
                     94:    .category-list li > span, .category-list li > a { text-transform: lowercase; }
                     95:    .category-list li * { text-transform: none; } /* don't affect <code> nested in <a> */
                     96: 
                     97:    .XXX { color: #E50000; background: white; border: solid red; padding: 0.5em; margin: 1em 0; }
                     98:    .XXX > :first-child { margin-top: 0; }
                     99:    p .XXX { line-height: 3em; }
                    100:    .note { color: green; background: transparent; font-family: sans-serif; }
                    101:    .warning { color: red; background: transparent; }
                    102:    .note, .warning { font-weight: bolder; font-style: italic; }
                    103:    p.note, div.note { padding: 0.5em 2em; }
                    104:    span.note { padding: 0 2em; }
                    105:    .note p:first-child, .warning p:first-child { margin-top: 0; }
                    106:    .note p:last-child, .warning p:last-child { margin-bottom: 0; }
                    107:    .warning:before { font-style: normal; }
                    108:    p.note:before { content: 'Note: '; }
                    109:    p.warning:before { content: '\26A0 Warning! '; }
                    110: 
                    111:    .bookkeeping:before { display: block; content: 'Bookkeeping details'; font-weight: bolder; font-style: italic; }
                    112:    .bookkeeping { font-size: 0.8em; margin: 2em 0; }
                    113:    .bookkeeping p { margin: 0.5em 2em; display: list-item; list-style: square; }
                    114: 
                    115:    h4 { position: relative; z-index: 3; }
                    116:    h4 + .element, h4 + div + .element { margin-top: -2.5em; padding-top: 2em; }
                    117:    .element {
                    118:      background: #EEEEFF;
                    119:      color: black;
                    120:      margin: 0 0 1em 0.15em;
                    121:      padding: 0 1em 0.25em 0.75em;
                    122:      border-left: solid #9999FF 0.25em;
                    123:      position: relative;
                    124:      z-index: 1;
                    125:    }
                    126:    .element:before {
                    127:      position: absolute;
                    128:      z-index: 2;
                    129:      top: 0;
                    130:      left: -1.15em;
                    131:      height: 2em;
                    132:      width: 0.9em;
                    133:      background: #EEEEFF;
                    134:      content: ' ';
                    135:      border-style: none none solid solid;
                    136:      border-color: #9999FF;
                    137:      border-width: 0.25em;
                    138:    }
                    139: 
                    140:    .example {
                    141:      display: block;
                    142:      color: #222222;
                    143:      background: #FCFCFC;
                    144:      border-left: double;
                    145:      margin-left: 2em;
                    146:      padding-left: 1em;
                    147:    }
                    148: 
                    149:    .tall-and-narrow {
                    150:      font-size: 0.6em;
                    151:      column-width: 25em;
                    152:      column-gap: 1em;
                    153:      -moz-column-width: 25em;
                    154:      -moz-column-gap: 1em;
                    155:      -webkit-column-width: 25em;
                    156:      -webkit-column-gap: 1em;
                    157:    }
                    158: 
                    159:    ul.domTree, ul.domTree ul { padding: 0 0 0 1em; margin: 0; }
                    160:    ul.domTree li { padding: 0; margin: 0; list-style: none; position: relative; }
                    161:    ul.domTree li li { list-style: none; }
                    162:    ul.domTree li:first-child::before { position: absolute; top: 0; height: 0.6em; left: -0.75em; width: 0.5em; border-style: none none solid solid; content: ''; border-width: 0.1em; }
                    163:    ul.domTree li:not(:last-child)::after { position: absolute; top: 0; bottom: -0.6em; left: -0.75em; width: 0.5em; border-style: none none solid solid; content: ''; border-width: 0.1em; }
                    164:    ul.domTree span { font-style: italic; font-family: serif; }
                    165:    ul.domTree .t1 code { color: purple; font-weight: bold; }
                    166:    ul.domTree .t2 { font-style: normal; font-family: monospace; }
                    167:    ul.domTree .t2 .name { color: black; font-weight: bold; }
                    168:    ul.domTree .t2 .value { color: blue; font-weight: normal; }
                    169:    ul.domTree .t3 code, .domTree .t4 code, .domTree .t5 code { color: gray; }
                    170:    ul.domTree .t7 code, .domTree .t8 code { color: green; }
                    171:    ul.domTree .t10 code { color: teal; }
                    172: 
1.2       mike      173:   </style><link href="data:text/css," rel="stylesheet" title="Complete specification"><link href="data:text/css,.impl%20%7B%20display:%20none;%20%7D" rel="alternate stylesheet" title="Author documentation only"><link href="data:text/css,.impl%20%7B%20background:%20%23FFEEEE;%20%7D" rel="alternate stylesheet" title="Highlight implementation requirements"><link href="http://www.w3.org/StyleSheets/TR/W3C-ED" rel="stylesheet" type="text/css"><!-- ZZZ ED vs WD -->
                    174:   <script src="link-fixup.js"></script>
                    175:   <link href="comms.html" title="8 Communication" rel="prev">
                    176:   <link href="spec.html#contents" title="Table of contents" rel="index">
1.1       mike      177:   <link href="named-character-references.html" title="9.6 Named character references" rel="next">
1.16      mike      178:   </head><body onload="fixBrokenLink(); fixBrokenLink()"><div class="head">
1.1       mike      179:    <p><a href="http://www.w3.org/"><img alt="W3C" height="48" src="http://www.w3.org/Icons/w3c_home" width="72"></a></p>
1.4       mike      180:    <h1>HTML 5</h1>
1.1       mike      181:    <h2 class="no-num no-toc" id="a-vocabulary-and-associated-apis-for-html-and-xhtml">A vocabulary and associated APIs for HTML and XHTML</h2>
1.97      mike      182:    </div>
                    183: 
                    184:   <nav>
1.1       mike      185:    <a href="comms.html">&#8592; 8 Communication</a> &#8211;
1.2       mike      186:    <a href="spec.html#contents">Table of contents</a> &#8211;
1.1       mike      187:    <a href="named-character-references.html">9.6 Named character references &#8594;</a>
1.108   ! mike      188:   </nav><p>This is revision 1.2778.</p>
1.97      mike      189: 
1.11      mike      190: 
1.97      mike      191:   <h2 id="syntax"><span class="secno">9 </span><dfn>The HTML syntax</dfn></h2>
1.1       mike      192: 
1.97      mike      193:   <p class="note">This section only describes the rules for
1.83      mike      194:   <code><a href="iana-considerations.html#text-html">text/html</a></code> resources. Rules for XML resources are
1.1       mike      195:   discussed in the section below entitled "<a href="the-xhtml-syntax.html#the-xhtml-syntax">The XHTML
1.97      mike      196:   syntax</a>".</p>
                    197: 
                    198: 
                    199:   <h3 id="writing"><span class="secno">9.1 </span>Writing HTML documents</h3>
                    200: 
                    201:   <div class="impl">
1.1       mike      202: 
                    203:   <p><i>This section only applies to documents, authoring tools, and
                    204:   markup generators. In particular, it does not apply to conformance
                    205:   checkers; conformance checkers must use the requirements given in
                    206:   the next section ("parsing HTML documents").</i></p>
                    207: 
1.97      mike      208:   </div>
                    209: 
                    210:   <p>Documents must consist of the following parts, in the given
                    211:   order:</p>
                    212: 
                    213:   <ol><li>Optionally, a single U+FEFF BYTE ORDER MARK (BOM) character.</li>
1.1       mike      214: 
                    215:    <li>Any number of <a href="#syntax-comments" title="syntax-comments">comments</a> and
                    216:    <a href="infrastructure.html#space-character" title="space character">space characters</a>.</li>
                    217: 
                    218:    <li>A <a href="#syntax-doctype" title="syntax-doctype">DOCTYPE</a>.
                    219: 
                    220:    </li><li>Any number of <a href="#syntax-comments" title="syntax-comments">comments</a> and
                    221:    <a href="infrastructure.html#space-character" title="space character">space characters</a>.</li>
                    222: 
                    223:    <li>The root element, in the form of an <code><a href="semantics.html#the-html-element">html</a></code> <a href="#syntax-elements" title="syntax-elements">element</a>.</li>
                    224: 
                    225:    <li>Any number of <a href="#syntax-comments" title="syntax-comments">comments</a> and
                    226:    <a href="infrastructure.html#space-character" title="space character">space characters</a>.</li>
                    227: 
                    228:   </ol><p>The various types of content mentioned above are described in the
1.97      mike      229:   next few sections.</p>
                    230: 
                    231:   <p>In addition, there are some restrictions on how <a href="semantics.html#character-encoding-declaration" title="character encoding declaration">character encoding
1.1       mike      232:   declarations</a> are to be serialized, as discussed in the
1.97      mike      233:   section on that topic.</p>
                    234: 
                    235:   <div class="note">
1.1       mike      236: 
                    237:    <p>Space characters before the root <code><a href="semantics.html#the-html-element">html</a></code> element, and
                    238:    space characters at the start of the <code><a href="semantics.html#the-html-element">html</a></code> element and
                    239:    before the <code><a href="semantics.html#the-head-element">head</a></code> element, will be dropped when the
                    240:    document is parsed; space characters <em>after</em> the root
                    241:    <code><a href="semantics.html#the-html-element">html</a></code> element will be parsed as if they were at the end
                    242:    of the <code><a href="semantics.html#the-body-element">body</a></code> element. Thus, space characters around the
                    243:    root element do not round-trip.</p>
                    244: 
                    245:    <p>It is suggested that newlines be inserted after the DOCTYPE,
                    246:    after any comments that are before the root element, after the
                    247:    <code><a href="semantics.html#the-html-element">html</a></code> element's start tag (if it is not <a href="#syntax-tag-omission" title="syntax-tag-omission">omitted</a>), and after any comments
                    248:    that are inside the <code><a href="semantics.html#the-html-element">html</a></code> element but before the
                    249:    <code><a href="semantics.html#the-head-element">head</a></code> element.</p>
                    250: 
1.97      mike      251:   </div>
                    252: 
                    253:   <p>Many strings in the HTML syntax (e.g. the names of elements and
1.1       mike      254:   their attributes) are case-insensitive, but only for characters in
                    255:   the ranges U+0041 .. U+005A (LATIN CAPITAL LETTER A to LATIN CAPITAL
                    256:   LETTER Z) and U+0061 .. U+007A (LATIN SMALL LETTER A to LATIN SMALL
                    257:   LETTER Z). For convenience, in this section this is just referred to
1.97      mike      258:   as "case-insensitive".</p>
                    259: 
                    260: 
                    261:   <h4 id="the-doctype"><span class="secno">9.1.1 </span>The DOCTYPE</h4>
                    262: 
                    263:   <p>A <dfn id="syntax-doctype" title="syntax-doctype">DOCTYPE</dfn> is a mostly useless,
                    264:   but required, header.</p>
                    265: 
                    266:   <p class="note">DOCTYPEs are required for legacy reasons. When
1.1       mike      267:   omitted, browsers tend to use a different rendering mode that is
                    268:   incompatible with some specifications. Including the DOCTYPE in a
                    269:   document ensures that the browser makes a best-effort attempt at
1.97      mike      270:   following the relevant specifications.</p>
                    271: 
                    272:   <p>A DOCTYPE must consist of the following characters, in this
                    273:   order:</p>
                    274: 
                    275:   <ol class="brief"><li>A U+003C LESS-THAN SIGN (<code>&lt;</code>) character.</li>
1.1       mike      276:    <li>A U+0021 EXCLAMATION MARK (<code>!</code>) character.</li>
                    277:    <li>A string that is an <a href="infrastructure.html#ascii-case-insensitive">ASCII case-insensitive</a> match for the string "<code title="">DOCTYPE</code>".</li>
                    278:    <li>One or more <a href="infrastructure.html#space-character" title="space character">space characters</a>.</li>
                    279:    <li>A string that is an <a href="infrastructure.html#ascii-case-insensitive">ASCII case-insensitive</a> match for the string "<code title="">HTML</code>".</li>
                    280:    <li>Optionally, a <a href="#doctype-legacy-string">DOCTYPE legacy string</a> (defined below).</li>
                    281:    <li>Zero or more <a href="infrastructure.html#space-character" title="space character">space characters</a>.</li>
                    282:    <li>A U+003E GREATER-THAN SIGN (<code>&gt;</code>) character.</li>
                    283:   </ol><p class="note">In other words, <code>&lt;!DOCTYPE HTML&gt;</code>,
1.97      mike      284:   case-insensitively.</p>
                    285: 
                    286:   <p>For the purposes of HTML generators that cannot output HTML
1.1       mike      287:   markup with the short DOCTYPE "<code title="">&lt;!DOCTYPE
                    288:   HTML&gt;</code>", a <dfn id="doctype-legacy-string">DOCTYPE legacy string</dfn> may be inserted
                    289:   into the DOCTYPE (in the position defined above). This string must
1.97      mike      290:   consist of:</p>
                    291: 
                    292:   <ol class="brief"><li>One or more <a href="infrastructure.html#space-character" title="space character">space characters</a>.</li>
1.1       mike      293:    <li>A string that is an <a href="infrastructure.html#ascii-case-insensitive">ASCII case-insensitive</a> match for the string "<code title="">SYSTEM</code>".</li>
                    294:    <li>One or more <a href="infrastructure.html#space-character" title="space character">space characters</a>.</li>
                    295:    <li>A U+0022 QUOTATION MARK or U+0027 APOSTROPHE character (the <i>quote mark</i>).</li>
                    296:    <li>The literal string "<code title="">about:legacy-compat</code>".</li>
                    297:    <li>A matching U+0022 QUOTATION MARK or U+0027 APOSTROPHE character (i.e. the same character as in the earlier step marked <i>quote mark</i>).</li>
                    298:   </ol><p class="note">In other words, <code>&lt;!DOCTYPE HTML SYSTEM
                    299:   "about:legacy-compat"&gt;</code> or <code>&lt;!DOCTYPE HTML SYSTEM
                    300:   'about:legacy-compat'&gt;</code>, case-insensitively except for the bit
1.97      mike      301:   in quotes.</p>
                    302: 
                    303:   <p>The <a href="#doctype-legacy-string">DOCTYPE legacy string</a> should not be used unless
1.1       mike      304:   the document is generated from a system that cannot output the
1.97      mike      305:   shorter string.</p>
                    306: 
                    307: 
                    308: 
                    309:   <h4 id="elements-0"><span class="secno">9.1.2 </span>Elements</h4>
                    310: 
                    311:   <p>There are five different kinds of <dfn id="syntax-elements" title="syntax-elements">elements</dfn>: void elements, raw text
1.1       mike      312:   elements, RCDATA elements, foreign elements, and normal
1.97      mike      313:   elements.</p>
                    314: 
                    315:   <dl><dt><dfn id="void-elements">Void elements</dfn></dt>
1.1       mike      316: 
                    317:    <dd><code><a href="the-canvas-element.html#the-area-element">area</a></code>, <code><a href="semantics.html#the-base-element">base</a></code>, <code><a href="semantics.html#the-br-element">br</a></code>,
                    318:    <code><a href="tabular-data.html#the-col-element">col</a></code>, <code><a href="interactive-elements.html#the-command">command</a></code>, <code><a href="embedded-content-0.html#the-embed-element">embed</a></code>,
                    319:    <code><a href="semantics.html#the-hr-element">hr</a></code>, <code><a href="embedded-content-0.html#the-img-element">img</a></code>, <code><a href="forms.html#the-input-element">input</a></code>,
                    320:    <code><a href="forms.html#the-keygen-element">keygen</a></code>, <code><a href="semantics.html#the-link-element">link</a></code>, <code><a href="semantics.html#meta">meta</a></code>,
                    321:    <code><a href="embedded-content-0.html#the-param-element">param</a></code>, <code><a href="video.html#the-source-element">source</a></code></dd>
                    322: 
1.91      mike      323:    <dt>Raw text elements</dt>
1.1       mike      324: 
                    325:    <dd><code><a href="semantics.html#script">script</a></code>, <code><a href="semantics.html#the-style-element">style</a></code></dd> <!-- iframe and
1.91      mike      326:    noscript don't count as raw text for syntax purposes -->
1.1       mike      327: 
                    328:    <dt>RCDATA elements</dt>
                    329: 
                    330:    <dd><code><a href="forms.html#the-textarea-element">textarea</a></code>, <code><a href="semantics.html#the-title-element">title</a></code></dd>
                    331: 
                    332:    <dt>Foreign elements</dt>
                    333: 
                    334:    <dd>Elements from the <a href="#mathml-namespace">MathML namespace</a>
                    335:    and the <a href="#svg-namespace">SVG namespace</a>.</dd>
                    336: 
                    337:    <dt>Normal elements</dt>
                    338: 
                    339:    <dd>All other allowed <a href="infrastructure.html#html-elements">HTML elements</a> are normal
                    340:    elements.</dd>
                    341: 
                    342:   </dl><p><dfn id="syntax-tags" title="syntax-tags">Tags</dfn> are used to delimit the start
1.91      mike      343:   and end of elements in the markup. Raw text, RCDATA, and normal
1.1       mike      344:   elements have a <a href="#syntax-start-tag" title="syntax-start-tag">start tag</a> to
                    345:   indicate where they begin, and an <a href="#syntax-end-tag" title="syntax-end-tag">end
                    346:   tag</a> to indicate where they end. The start and end tags of
                    347:   certain normal elements can be <a href="#syntax-tag-omission" title="syntax-tag-omission">omitted</a>, as described
                    348:   later. Those that cannot be omitted must not be omitted. <a href="#void-elements">Void
                    349:   elements</a> only have a start tag; end tags must not be
                    350:   specified for void elements. Foreign elements must either have a
                    351:   start tag and an end tag, or a start tag that is marked as
1.97      mike      352:   self-closing, in which case they must not have an end tag.</p>
                    353: 
                    354:   <p>The contents of the element must be placed between just after the
1.1       mike      355:   start tag (which <a href="#syntax-tag-omission" title="syntax-tag-omission">might be implied,
                    356:   in certain cases</a>) and just before the end tag (which again,
                    357:   <a href="#syntax-tag-omission" title="syntax-tag-omission">might be implied in certain
                    358:   cases</a>). The exact allowed contents of each individual element
                    359:   depends on the content model of that element, as described earlier
                    360:   in this specification. Elements must not contain content that their
                    361:   content model disallows. In addition to the restrictions placed on
                    362:   the contents by those content models, however, the five types of
1.97      mike      363:   elements have additional <em>syntactic</em> requirements.</p>
                    364: 
                    365:   <p><a href="#void-elements">Void elements</a> can't have any contents (since there's
1.1       mike      366:   no end tag, no content can be put between the start tag and the end
1.97      mike      367:   tag).</p>
                    368: 
                    369:   <p>Raw text elements can have <a href="#syntax-text" title="syntax-text">text</a>,
1.1       mike      370:   though it has <a href="#cdata-rcdata-restrictions">restrictions</a>
1.97      mike      371:   described below.</p>
                    372: 
                    373:   <p>RCDATA elements can have <a href="#syntax-text" title="syntax-text">text</a>
1.1       mike      374:   and <a href="#syntax-charref" title="syntax-charref">character references</a>, but
                    375:   the text must not contain an <a href="#syntax-ambiguous-ampersand" title="syntax-ambiguous-ampersand">ambiguous ampersand</a>.
                    376:   There are also <a href="#cdata-rcdata-restrictions">further
1.97      mike      377:   restrictions</a> described below.</p>
                    378: 
                    379:   <p>Foreign elements whose start tag is marked as self-closing can't
1.1       mike      380:   have any contents (since, again, as there's no end tag, no content
                    381:   can be put between the start tag and the end tag). Foreign elements
                    382:   whose start tag is <em>not</em> marked as self-closing can have
                    383:   <a href="#syntax-text" title="syntax-text">text</a>, <a href="#syntax-charref" title="syntax-charref">character references</a>, <a href="#syntax-cdata" title="syntax-cdata">CDATA sections</a>, other <a href="#syntax-elements" title="syntax-elements">elements</a>, and <a href="#syntax-comments" title="syntax-comments">comments</a>, but the text must not
                    384:   contain the character U+003C LESS-THAN SIGN (<code>&lt;</code>) or
                    385:   an <a href="#syntax-ambiguous-ampersand" title="syntax-ambiguous-ampersand">ambiguous
1.97      mike      386:   ampersand</a>.</p>
                    387: 
                    388:   <p>Normal elements can have <a href="#syntax-text" title="syntax-text">text</a>,
1.1       mike      389:   <a href="#syntax-charref" title="syntax-charref">character references</a>, other
                    390:   <a href="#syntax-elements" title="syntax-elements">elements</a>, and <a href="#syntax-comments" title="syntax-comments">comments</a>, but the text must not
                    391:   contain the character U+003C LESS-THAN SIGN (<code>&lt;</code>) or
                    392:   an <a href="#syntax-ambiguous-ampersand" title="syntax-ambiguous-ampersand">ambiguous
                    393:   ampersand</a>. Some normal elements also have <a href="#element-restrictions">yet more restrictions</a> on what
                    394:   content they are allowed to hold, beyond the restrictions imposed by
                    395:   the content model and those described in this paragraph. Those
1.97      mike      396:   restrictions are described below.</p>
                    397: 
                    398:   <p>Tags contain a <dfn id="syntax-tag-name" title="syntax-tag-name">tag name</dfn>,
1.1       mike      399:   giving the element's name. HTML elements all have names that only
                    400:   use characters in the range U+0030 DIGIT ZERO .. U+0039 DIGIT NINE,
                    401:   U+0061 LATIN SMALL LETTER A .. U+007A LATIN SMALL LETTER Z, U+0041
                    402:   LATIN CAPITAL LETTER A .. U+005A LATIN CAPITAL LETTER Z, and U+002D
                    403:   HYPHEN-MINUS (<code>-</code>). In the HTML syntax, tag names may be
                    404:   written with any mix of lower- and uppercase letters that, when
                    405:   converted to all-lowercase, matches the element's tag name; tag
1.97      mike      406:   names are case-insensitive.</p>
                    407: 
                    408: 
                    409:   <h5 id="start-tags"><span class="secno">9.1.2.1 </span>Start tags</h5>
                    410: 
                    411:   <p><dfn id="syntax-start-tag" title="syntax-start-tag">Start tags</dfn> must have the
                    412:   following format:</p>
                    413: 
                    414:   <ol><li>The first character of a start tag must be a U+003C LESS-THAN
1.1       mike      415:    SIGN (<code>&lt;</code>).</li>
                    416: 
                    417:    <li>The next few characters of a start tag must be the element's
                    418:    <a href="#syntax-tag-name" title="syntax-tag-name">tag name</a>.</li>
                    419: 
                    420:    <li>If there are to be any attributes in the next step, there must
                    421:    first be one or more <a href="infrastructure.html#space-character" title="space character">space
                    422:    characters</a>.</li>
                    423: 
                    424:    <li>Then, the start tag may have a number of attributes, the <a href="#syntax-attributes" title="syntax-attributes">syntax for which</a> is described
                    425:    below. Attributes may be separated from each other by one or more
                    426:    <a href="infrastructure.html#space-character" title="space character">space characters</a>.</li>
                    427: 
                    428:    <li>After the attributes, there may be one or more <a href="infrastructure.html#space-character" title="space character">space characters</a>. (Some attributes
                    429:    are required to be followed by a space. See the <a href="#syntax-attributes" title="syntax-attributes">attributes section</a> below.)</li>
                    430: 
                    431:    <li>Then, if the element is one of the <a href="#void-elements">void elements</a>,
                    432:    or if the element is a foreign element, then there may be a single
                    433:    U+002F SOLIDUS (<code>/</code>) character. This character has no
                    434:    effect on void elements, but on foreign elements it marks the start
                    435:    tag as self-closing.</li>
                    436: 
                    437:    <li>Finally, start tags must be closed by a U+003E GREATER-THAN
                    438:    SIGN (<code>&gt;</code>) character.</li>
                    439: 
1.97      mike      440:   </ol><h5 id="end-tags"><span class="secno">9.1.2.2 </span>End tags</h5>
                    441: 
                    442:   <p><dfn id="syntax-end-tag" title="syntax-end-tag">End tags</dfn> must have the
                    443:   following format:</p>
                    444: 
                    445:   <ol><li>The first character of an end tag must be a U+003C LESS-THAN
1.1       mike      446:    SIGN (<code>&lt;</code>).</li>
                    447: 
                    448:    <li>The second character of an end tag must be a U+002F SOLIDUS
                    449:    (<code>/</code>).</li>
                    450: 
                    451:    <li>The next few characters of an end tag must be the element's
                    452:    <a href="#syntax-tag-name" title="syntax-tag-name">tag name</a>.</li>
                    453: 
                    454:    <li>After the tag name, there may be one or more <a href="infrastructure.html#space-character" title="space
                    455:    character">space characters</a>.</li>
                    456: 
                    457:    <li>Finally, end tags must be closed by a U+003E GREATER-THAN
                    458:    SIGN (<code>&gt;</code>) character.</li>
                    459: 
1.97      mike      460:   </ol><h5 id="attributes"><span class="secno">9.1.2.3 </span>Attributes</h5>
                    461: 
                    462:   <p><dfn id="syntax-attributes" title="syntax-attributes">Attributes</dfn> for an element
                    463:   are expressed inside the element's start tag.</p>
                    464: 
                    465:   <p>Attributes have a name and a value. <dfn id="syntax-attribute-name" title="syntax-attribute-name">Attribute names</dfn> must consist of
1.1       mike      466:   one or more characters other than the <a href="infrastructure.html#space-character" title="space
                    467:   character">space characters</a>, U+0000 NULL, U+0022 QUOTATION
                    468:   MARK ("), U+0027 APOSTROPHE ('), U+003E GREATER-THAN SIGN
                    469:   (&gt;), U+002F SOLIDUS (/), and U+003D EQUALS SIGN (=) characters,
                    470:   the control characters, and any characters that are not defined by
                    471:   Unicode. In the HTML syntax, attribute names may be written with any
                    472:   mix of lower- and uppercase letters that are an <a href="infrastructure.html#ascii-case-insensitive">ASCII
1.97      mike      473:   case-insensitive</a> match for the attribute's name.</p>
                    474: 
                    475:   <p><dfn id="syntax-attribute-value" title="syntax-attribute-value">Attribute values</dfn> are a
1.1       mike      476:   mixture of <a href="#syntax-text" title="syntax-text">text</a> and <a href="#syntax-charref" title="syntax-charref">character references</a>, except with the
1.97      mike      477:   additional restriction that the text cannot contain an <a href="#syntax-ambiguous-ampersand" title="syntax-ambiguous-ampersand">ambiguous ampersand</a>.</p>
                    478: 
                    479:   <p>Attributes can be specified in four different ways:</p>
                    480: 
                    481:   <dl><dt>Empty attribute syntax</dt>
1.1       mike      482: 
                    483:    <dd>
                    484: 
                    485:     <p>Just the <a href="#syntax-attribute-name" title="syntax-attribute-name">attribute
                    486:     name</a>.</p>
                    487: 
                    488:     <div class="example">
                    489: 
                    490:      <p>In the following example, the <code title="attr-fe-disabled"><a href="forms.html#attr-fe-disabled">disabled</a></code> attribute is given with
                    491:      the empty attribute syntax:</p>
                    492: 
                    493:      <pre>&lt;input <em>disabled</em>&gt;</pre>
                    494: 
                    495:     </div>
                    496: 
                    497:     <p>If an attribute using the empty attribute syntax is to be
                    498:     followed by another attribute, then there must be a <a href="infrastructure.html#space-character">space
                    499:     character</a> separating the two.</p>
                    500: 
                    501:    </dd>
                    502: 
1.2       mike      503:    <dt id="unquoted">Unquoted attribute value syntax</dt>
1.1       mike      504: 
                    505:    <dd>
                    506: 
                    507:     <p>The <a href="#syntax-attribute-name" title="syntax-attribute-name">attribute name</a>,
                    508:     followed by zero or more <a href="infrastructure.html#space-character" title="space character">space
                    509:     characters</a>, followed by a single U+003D EQUALS SIGN
                    510:     character, followed by zero or more <a href="infrastructure.html#space-character" title="space
                    511:     character">space characters</a>, followed by the <a href="#syntax-attribute-value" title="syntax-attribute-value">attribute value</a>, which, in
                    512:     addition to the requirements given above for attribute values,
                    513:     must not contain any literal <a href="infrastructure.html#space-character" title="space character">space
                    514:     characters</a>, any U+0022 QUOTATION MARK (<code>"</code>)
                    515:     characters, U+0027 APOSTROPHE (<code>'</code>) characters,
                    516:     U+003D EQUALS SIGN (<code>=</code>) characters, U+003C LESS-THAN
                    517:     SIGN (<code>&lt;</code>) characters, or U+003E GREATER-THAN SIGN
                    518:     (<code>&gt;</code>) characters, and must not be the empty
                    519:     string.</p>
                    520: 
                    521:     <div class="example">
                    522: 
                    523:      <p>In the following example, the <code title="attr-input-value"><a href="forms.html#attr-input-value">value</a></code> attribute is given
                    524:      with the unquoted attribute value syntax:</p>
                    525: 
                    526:      <pre>&lt;input <em>value=yes</em>&gt;</pre>
                    527: 
                    528:     </div>
                    529: 
                    530:     <p>If an attribute using the unquoted attribute syntax is to be
1.101     mike      531:     followed by another attribute or by the optional U+002F SOLIDUS
                    532:     (<code>/</code>) character allowed in step 6 of the <a href="#syntax-start-tag" title="syntax-start-tag">start tag</a> syntax above, then there
1.1       mike      533:     must be a <a href="infrastructure.html#space-character">space character</a> separating the two.</p>
                    534: 
                    535:    </dd>
                    536: 
                    537:    <dt>Single-quoted attribute value syntax</dt>
                    538: 
                    539:    <dd>
                    540: 
                    541:     <p>The <a href="#syntax-attribute-name" title="syntax-attribute-name">attribute name</a>,
                    542:     followed by zero or more <a href="infrastructure.html#space-character" title="space character">space
                    543:     characters</a>, followed by a single U+003D EQUALS SIGN
                    544:     character, followed by zero or more <a href="infrastructure.html#space-character" title="space
                    545:     character">space characters</a>, followed by a single U+0027
                    546:     APOSTROPHE (<code>'</code>) character, followed by the <a href="#syntax-attribute-value" title="syntax-attribute-value">attribute value</a>, which, in
                    547:     addition to the requirements given above for attribute values,
                    548:     must not contain any literal U+0027 APOSTROPHE (<code>'</code>)
                    549:     characters, and finally followed by a second single U+0027
                    550:     APOSTROPHE (<code>'</code>) character.</p>
                    551: 
                    552:     <div class="example">
                    553: 
                    554:      <p>In the following example, the <code title="attr-input-type"><a href="forms.html#attr-input-type">type</a></code> attribute is given with the
                    555:      single-quoted attribute value syntax:</p>
                    556: 
                    557:      <pre>&lt;input <em>type='checkbox'</em>&gt;</pre>
                    558: 
                    559:     </div>
                    560: 
                    561:     <p>If an attribute using the single-quoted attribute syntax is to
                    562:     be followed by another attribute, then there must be a <a href="infrastructure.html#space-character">space
                    563:     character</a> separating the two.</p>
                    564: 
                    565:    </dd>
                    566: 
                    567:    <dt>Double-quoted attribute value syntax</dt>
                    568: 
                    569:    <dd>
                    570: 
                    571:     <p>The <a href="#syntax-attribute-name" title="syntax-attribute-name">attribute name</a>,
                    572:     followed by zero or more <a href="infrastructure.html#space-character" title="space character">space
                    573:     characters</a>, followed by a single U+003D EQUALS SIGN
                    574:     character, followed by zero or more <a href="infrastructure.html#space-character" title="space
                    575:     character">space characters</a>, followed by a single U+0022
                    576:     QUOTATION MARK (<code>"</code>) character, followed by the <a href="#syntax-attribute-value" title="syntax-attribute-value">attribute value</a>, which, in
                    577:     addition to the requirements given above for attribute values,
                    578:     must not contain any literal U+0022 QUOTATION MARK
                    579:     (<code>"</code>) characters, and finally followed by a second
                    580:     single U+0022 QUOTATION MARK (<code>"</code>) character.</p>
                    581: 
                    582:     <div class="example">
                    583: 
                    584:      <p>In the following example, the <code title="attr-fe-name"><a href="forms.html#attr-fe-name">name</a></code> attribute is given with the
                    585:      double-quoted attribute value syntax:</p>
                    586: 
                    587:      <pre>&lt;input <em>name="be evil"</em>&gt;</pre>
                    588: 
                    589:     </div>
                    590: 
                    591:     <p>If an attribute using the double-quoted attribute syntax is to
                    592:     be followed by another attribute, then there must be a <a href="infrastructure.html#space-character">space
                    593:     character</a> separating the two.</p>
                    594: 
                    595:    </dd>
                    596: 
                    597:   </dl><p>There must never be two or more attributes on the same start tag
                    598:   whose names are an <a href="infrastructure.html#ascii-case-insensitive">ASCII case-insensitive</a> match for
1.97      mike      599:   each other.</p>
                    600: 
                    601: 
                    602:   <h5 id="optional-tags"><span class="secno">9.1.2.4 </span>Optional tags</h5>
                    603: 
                    604:   <p>Certain tags can be <dfn id="syntax-tag-omission" title="syntax-tag-omission">omitted</dfn>.</p>
                    605: 
                    606:   <p class="note">Omitting an element's <a href="#syntax-start-tag" title="syntax-start-tag">start tag</a> does not mean the element
1.1       mike      607:   is not present; it is implied, but it is still there. An HTML
                    608:   document always has a root <code><a href="semantics.html#the-html-element">html</a></code> element, even if the
                    609:   string <code title="">&lt;html&gt;</code> doesn't appear anywhere in
1.97      mike      610:   the markup.</p>
                    611: 
                    612:   <!-- <html> -->
                    613:   <p>An <code><a href="semantics.html#the-html-element">html</a></code> element's <a href="#syntax-start-tag" title="syntax-start-tag">start tag</a> may be omitted if the
                    614:   first thing inside the <code><a href="semantics.html#the-html-element">html</a></code> element is not a <a href="#syntax-comments" title="syntax-comments">comment</a>.</p>
                    615: 
                    616:   <!-- </html> -->
                    617:   <p>An <code><a href="semantics.html#the-html-element">html</a></code> element's <a href="#syntax-end-tag" title="syntax-end-tag">end
1.1       mike      618:   tag</a> may be omitted if the <code><a href="semantics.html#the-html-element">html</a></code> element is not
1.97      mike      619:   immediately followed by a <a href="#syntax-comments" title="syntax-comments">comment</a>.</p>
                    620: 
                    621:   <!-- <head> -->
                    622:   <p>A <code><a href="semantics.html#the-head-element">head</a></code> element's <a href="#syntax-start-tag" title="syntax-start-tag">start tag</a> may be omitted <!--if the
1.1       mike      623:   element is empty, or--> if the first thing inside the
1.97      mike      624:   <code><a href="semantics.html#the-head-element">head</a></code> element is an element.</p>
                    625: 
                    626:   <!-- </head> -->
                    627:   <p>A <code><a href="semantics.html#the-head-element">head</a></code> element's <a href="#syntax-end-tag" title="syntax-end-tag">end
1.1       mike      628:   tag</a> may be omitted if the <code><a href="semantics.html#the-head-element">head</a></code> element is not
1.97      mike      629:   immediately followed by a <a href="infrastructure.html#space-character">space character</a> or a <a href="#syntax-comments" title="syntax-comments">comment</a>.</p>
                    630: 
                    631:   <!-- <body> -->
                    632:   <p>A <code><a href="semantics.html#the-body-element">body</a></code> element's <a href="#syntax-start-tag" title="syntax-start-tag">start tag</a> may be omitted if the
1.1       mike      633:   element is empty, or if the first thing inside the <code><a href="semantics.html#the-body-element">body</a></code>
                    634:   element is not a <a href="infrastructure.html#space-character">space character</a> or a <a href="#syntax-comments" title="syntax-comments">comment</a>, except if the first thing
                    635:   inside the <code><a href="semantics.html#the-body-element">body</a></code> element is a <code><a href="semantics.html#script">script</a></code> or
                    636:   <code><a href="semantics.html#the-style-element">style</a></code> element. <!-- Note that even if the </head> end
                    637:   tag is present, the parser makes <style> and <script> elements
                    638:   between </head> and <body> end up in the <head> instead of implying
1.97      mike      639:   the <body> --></p>
                    640: 
                    641:   <!-- </body> -->
                    642:   <p>A <code><a href="semantics.html#the-body-element">body</a></code> element's <a href="#syntax-end-tag" title="syntax-end-tag">end
1.1       mike      643:   tag</a> may be omitted if the <code><a href="semantics.html#the-body-element">body</a></code> element is not
1.97      mike      644:   immediately followed by a <a href="#syntax-comments" title="syntax-comments">comment</a>.</p>
                    645: 
                    646:   <!-- </li> -->
                    647:   <p>A <code><a href="semantics.html#the-li-element">li</a></code> element's <a href="#syntax-end-tag" title="syntax-end-tag">end
1.1       mike      648:   tag</a> may be omitted if the <code><a href="semantics.html#the-li-element">li</a></code> element is
                    649:   immediately followed by another <code><a href="semantics.html#the-li-element">li</a></code> element or if there
1.97      mike      650:   is no more content in the parent element.</p>
                    651: 
                    652:   <!-- </dt> -->
                    653:   <p>A <code><a href="semantics.html#the-dt-element">dt</a></code> element's <a href="#syntax-end-tag" title="syntax-end-tag">end
1.1       mike      654:   tag</a> may be omitted if the <code><a href="semantics.html#the-dt-element">dt</a></code> element is
                    655:   immediately followed by another <code><a href="semantics.html#the-dt-element">dt</a></code> element or a
1.97      mike      656:   <code><a href="semantics.html#the-dd-element">dd</a></code> element.</p>
                    657: 
                    658:   <!-- </dd> -->
                    659:   <p>A <code><a href="semantics.html#the-dd-element">dd</a></code> element's <a href="#syntax-end-tag" title="syntax-end-tag">end
1.1       mike      660:   tag</a> may be omitted if the <code><a href="semantics.html#the-dd-element">dd</a></code> element is
                    661:   immediately followed by another <code><a href="semantics.html#the-dd-element">dd</a></code> element or a
                    662:   <code><a href="semantics.html#the-dt-element">dt</a></code> element, or if there is no more content in the
1.97      mike      663:   parent element.</p>
                    664: 
                    665:   <!-- </p> -->
                    666:   <p>A <code><a href="semantics.html#the-p-element">p</a></code> element's <a href="#syntax-end-tag" title="syntax-end-tag">end
1.1       mike      667:   tag</a> may be omitted if the <code><a href="semantics.html#the-p-element">p</a></code> element is
                    668:   immediately followed by an <code><a href="semantics.html#the-address-element">address</a></code>,
                    669:   <code><a href="semantics.html#the-article-element">article</a></code>, <code><a href="semantics.html#the-aside-element">aside</a></code>, <code><a href="semantics.html#the-blockquote-element">blockquote</a></code>,
1.86      mike      670:   <!--v2DATAGRID <code>datagrid</code>,--> <code><a href="semantics.html#the-dialog-element">dialog</a></code>,
                    671:   <code><a href="obsolete.html#dir">dir</a></code>, <code><a href="interactive-elements.html#the-div-element">div</a></code>, <code><a href="semantics.html#the-dl-element">dl</a></code>,
                    672:   <code><a href="forms.html#the-fieldset-element">fieldset</a></code>, <code><a href="semantics.html#the-footer-element">footer</a></code>, <code><a href="forms.html#the-form-element">form</a></code>,
                    673:   <code><a href="semantics.html#the-h1-h2-h3-h4-h5-and-h6-elements">h1</a></code>, <code><a href="semantics.html#the-h1-h2-h3-h4-h5-and-h6-elements">h2</a></code>, <code><a href="semantics.html#the-h1-h2-h3-h4-h5-and-h6-elements">h3</a></code>, <code><a href="semantics.html#the-h1-h2-h3-h4-h5-and-h6-elements">h4</a></code>,
                    674:   <code><a href="semantics.html#the-h1-h2-h3-h4-h5-and-h6-elements">h5</a></code>, <code><a href="semantics.html#the-h1-h2-h3-h4-h5-and-h6-elements">h6</a></code>, <code><a href="semantics.html#the-header-element">header</a></code>,
                    675:   <code><a href="semantics.html#the-hgroup-element">hgroup</a></code>, <code><a href="semantics.html#the-hr-element">hr</a></code>, <code><a href="interactive-elements.html#menus">menu</a></code>,
                    676:   <code><a href="semantics.html#the-nav-element">nav</a></code>, <code><a href="semantics.html#the-ol-element">ol</a></code>, <code><a href="semantics.html#the-p-element">p</a></code>, <code><a href="semantics.html#the-pre-element">pre</a></code>,
1.1       mike      677:   <code><a href="semantics.html#the-section-element">section</a></code>, <code><a href="tabular-data.html#the-table-element">table</a></code>, or <code><a href="semantics.html#the-ul-element">ul</a></code>,
                    678:   element, or if there is no more content in the parent element and
1.97      mike      679:   the parent element is not an <code><a href="text-level-semantics.html#the-a-element">a</a></code> element.</p>
                    680: 
                    681:   <!-- </rt> -->
                    682:   <p>An <code><a href="text-level-semantics.html#the-rt-element">rt</a></code> element's <a href="#syntax-end-tag" title="syntax-end-tag">end
1.1       mike      683:   tag</a> may be omitted if the <code><a href="text-level-semantics.html#the-rt-element">rt</a></code> element is
                    684:   immediately followed by an <code><a href="text-level-semantics.html#the-rt-element">rt</a></code> or <code><a href="text-level-semantics.html#the-rp-element">rp</a></code>
1.97      mike      685:   element, or if there is no more content in the parent element.</p>
                    686: 
                    687:   <!-- </rp> -->
                    688:   <p>An <code><a href="text-level-semantics.html#the-rp-element">rp</a></code> element's <a href="#syntax-end-tag" title="syntax-end-tag">end
1.1       mike      689:   tag</a> may be omitted if the <code><a href="text-level-semantics.html#the-rp-element">rp</a></code> element is
                    690:   immediately followed by an <code><a href="text-level-semantics.html#the-rt-element">rt</a></code> or <code><a href="text-level-semantics.html#the-rp-element">rp</a></code>
1.97      mike      691:   element, or if there is no more content in the parent element.</p>
                    692: 
                    693:   <!-- </optgroup> (the text assumes <optgroup> can only be inside a
1.1       mike      694:   <select>; commented out text below can handle the non-<select> case
1.97      mike      695:   if we ever allow it) -->
                    696:   <p>An <code><a href="forms.html#the-optgroup-element">optgroup</a></code> element's <a href="#syntax-end-tag" title="syntax-end-tag">end tag</a> may be omitted if the
1.1       mike      697:   <code><a href="forms.html#the-optgroup-element">optgroup</a></code> element <!--has an ancestor
                    698:   <code>select</code> element and--> is immediately followed by
                    699:   another <code><a href="forms.html#the-optgroup-element">optgroup</a></code> element, or if <!--all of the elements
                    700:   that are ancestors of the <code>optgroup</code> element, up to and
                    701:   including the first ancestor element that is not an
                    702:   <code>optgroup</code> element, have no more content--> there is no
1.97      mike      703:   more content in the parent element.</p>
                    704:   <!-- so e.g. the max number of </optgroup>s are omitted here:
1.1       mike      705:    <select><optgroup></select>
                    706:    <p id=x><optgroup></optgroup>x</p>
                    707:    <p id=x><optgroup><optgroup></optgroup></optgroup>x</p>
                    708:    <p><optgroup id=x><optgroup></optgroup>x</p>
                    709:    <p><optgroup><optgroup id=x>x</p>
1.97      mike      710:   -->
                    711: 
                    712:   <!-- </option> -->
                    713:   <p>An <code><a href="forms.html#the-option-element">option</a></code> element's <a href="#syntax-end-tag" title="syntax-end-tag">end
1.1       mike      714:   tag</a> may be omitted if the <code><a href="forms.html#the-option-element">option</a></code> element is
                    715:   immediately followed by another <code><a href="forms.html#the-option-element">option</a></code> element, or if
                    716:   it is immediately followed by an <code><a href="forms.html#the-optgroup-element">optgroup</a></code> element, or
1.97      mike      717:   if there is no more content in the parent element.</p>
                    718: 
                    719:   <!-- <colgroup> -->
                    720:   <p>A <code><a href="tabular-data.html#the-colgroup-element">colgroup</a></code> element's <a href="#syntax-start-tag" title="syntax-start-tag">start tag</a> may be omitted if the
1.1       mike      721:   first thing inside the <code><a href="tabular-data.html#the-colgroup-element">colgroup</a></code> element is a
                    722:   <code><a href="tabular-data.html#the-col-element">col</a></code> element, and if the element is not immediately
                    723:   preceded by another <code><a href="tabular-data.html#the-colgroup-element">colgroup</a></code> element whose <a href="#syntax-end-tag" title="syntax-end-tag">end tag</a> has been omitted. (It can't be
1.97      mike      724:   omitted if the element is empty.)</p>
                    725: 
                    726:   <!-- </colgroup> -->
                    727:   <p>A <code><a href="tabular-data.html#the-colgroup-element">colgroup</a></code> element's <a href="#syntax-end-tag" title="syntax-end-tag">end tag</a> may be omitted if the
1.1       mike      728:   <code><a href="tabular-data.html#the-colgroup-element">colgroup</a></code> element is not immediately followed by a
1.97      mike      729:   <a href="infrastructure.html#space-character">space character</a> or a <a href="#syntax-comments" title="syntax-comments">comment</a>.</p>
                    730: 
                    731:   <!-- </thead> -->
                    732:   <p>A <code><a href="tabular-data.html#the-thead-element">thead</a></code> element's <a href="#syntax-end-tag" title="syntax-end-tag">end
1.1       mike      733:   tag</a> may be omitted if the <code><a href="tabular-data.html#the-thead-element">thead</a></code> element is
                    734:   immediately followed by a <code><a href="tabular-data.html#the-tbody-element">tbody</a></code> or <code><a href="tabular-data.html#the-tfoot-element">tfoot</a></code>
1.97      mike      735:   element.</p>
                    736: 
                    737:   <!-- <tbody> -->
                    738:   <p>A <code><a href="tabular-data.html#the-tbody-element">tbody</a></code> element's <a href="#syntax-start-tag" title="syntax-start-tag">start tag</a> may be omitted if the
1.1       mike      739:   first thing inside the <code><a href="tabular-data.html#the-tbody-element">tbody</a></code> element is a
                    740:   <code><a href="tabular-data.html#the-tr-element">tr</a></code> element, and if the element is not immediately
                    741:   preceded by a <code><a href="tabular-data.html#the-tbody-element">tbody</a></code>, <code><a href="tabular-data.html#the-thead-element">thead</a></code>, or
                    742:   <code><a href="tabular-data.html#the-tfoot-element">tfoot</a></code> element whose <a href="#syntax-end-tag" title="syntax-end-tag">end
                    743:   tag</a> has been omitted. (It can't be omitted if the element is
1.97      mike      744:   empty.)</p>
                    745: 
                    746:   <!-- </tbody> -->
                    747:   <p>A <code><a href="tabular-data.html#the-tbody-element">tbody</a></code> element's <a href="#syntax-end-tag" title="syntax-end-tag">end
1.1       mike      748:   tag</a> may be omitted if the <code><a href="tabular-data.html#the-tbody-element">tbody</a></code> element is
                    749:   immediately followed by a <code><a href="tabular-data.html#the-tbody-element">tbody</a></code> or <code><a href="tabular-data.html#the-tfoot-element">tfoot</a></code>
1.97      mike      750:   element, or if there is no more content in the parent element.</p>
                    751: 
                    752:   <!-- </tfoot> -->
                    753:   <p>A <code><a href="tabular-data.html#the-tfoot-element">tfoot</a></code> element's <a href="#syntax-end-tag" title="syntax-end-tag">end
1.1       mike      754:   tag</a> may be omitted if the <code><a href="tabular-data.html#the-tfoot-element">tfoot</a></code> element is
                    755:   immediately followed by a <code><a href="tabular-data.html#the-tbody-element">tbody</a></code> element, or if there is
1.97      mike      756:   no more content in the parent element.</p>
                    757: 
                    758:   <!-- </tr> -->
                    759:   <p>A <code><a href="tabular-data.html#the-tr-element">tr</a></code> element's <a href="#syntax-end-tag" title="syntax-end-tag">end
1.1       mike      760:   tag</a> may be omitted if the <code><a href="tabular-data.html#the-tr-element">tr</a></code> element is
                    761:   immediately followed by another <code><a href="tabular-data.html#the-tr-element">tr</a></code> element, or if there
1.97      mike      762:   is no more content in the parent element.</p>
                    763: 
                    764:   <!-- </td> -->
                    765:   <p>A <code><a href="tabular-data.html#the-td-element">td</a></code> element's <a href="#syntax-end-tag" title="syntax-end-tag">end
1.1       mike      766:   tag</a> may be omitted if the <code><a href="tabular-data.html#the-td-element">td</a></code> element is
                    767:   immediately followed by a <code><a href="tabular-data.html#the-td-element">td</a></code> or <code><a href="tabular-data.html#the-th-element">th</a></code>
1.97      mike      768:   element, or if there is no more content in the parent element.</p>
                    769: 
                    770:   <!-- </th> -->
                    771:   <p>A <code><a href="tabular-data.html#the-th-element">th</a></code> element's <a href="#syntax-end-tag" title="syntax-end-tag">end
1.1       mike      772:   tag</a> may be omitted if the <code><a href="tabular-data.html#the-th-element">th</a></code> element is
                    773:   immediately followed by a <code><a href="tabular-data.html#the-td-element">td</a></code> or <code><a href="tabular-data.html#the-th-element">th</a></code>
1.97      mike      774:   element, or if there is no more content in the parent element.</p>
                    775: 
                    776:   <p><strong>However</strong>, a <a href="#syntax-start-tag" title="syntax-start-tag">start
                    777:   tag</a> must never be omitted if it has any attributes.</p>
                    778: 
                    779: 
                    780:   <h5 id="element-restrictions"><span class="secno">9.1.2.5 </span>Restrictions on content models</h5>
                    781: 
                    782:   <p>For historical reasons, certain elements have extra restrictions
                    783:   beyond even the restrictions given by their content model.</p>
                    784: 
                    785:   <p>A <code><a href="tabular-data.html#the-table-element">table</a></code> element must not contain <code><a href="tabular-data.html#the-tr-element">tr</a></code>
1.1       mike      786:   elements, even though these elements are technically allowed inside
                    787:   <code><a href="tabular-data.html#the-table-element">table</a></code> elements according to the content models
                    788:   described in this specification. (If a <code><a href="tabular-data.html#the-tr-element">tr</a></code> element is
                    789:   put inside a <code><a href="tabular-data.html#the-table-element">table</a></code> in the markup, it will in fact imply
1.97      mike      790:   a <code><a href="tabular-data.html#the-tbody-element">tbody</a></code> start tag before it.)</p>
                    791: 
                    792:   <p>A single U+000A LINE FEED (LF) character may be placed
1.1       mike      793:   immediately after the <a href="#syntax-start-tag" title="syntax-start-tag">start
                    794:   tag</a> of <code><a href="semantics.html#the-pre-element">pre</a></code> and <code><a href="forms.html#the-textarea-element">textarea</a></code>
                    795:   elements. This does not affect the processing of the element. The
                    796:   otherwise optional U+000A LINE FEED (LF) character <em>must</em> be
                    797:   included if the element's contents start with that character
                    798:   (because otherwise the leading newline in the contents would be
1.97      mike      799:   treated like the optional newline, and ignored).</p>
                    800: 
                    801:   <div class="example">
1.1       mike      802:    <p>The following two <code><a href="semantics.html#the-pre-element">pre</a></code> blocks are equivalent:</p>
                    803:    <pre>&lt;pre&gt;Hello&lt;/pre&gt;</pre>
                    804:    <pre>&lt;pre&gt;<br>Hello&lt;/pre&gt;</pre>
1.97      mike      805:   </div>
                    806: 
                    807: 
                    808:   <h5 id="cdata-rcdata-restrictions"><span class="secno">9.1.2.6 </span>Restrictions on the contents of raw text and RCDATA elements</h5>
                    809: 
                    810:   <p>The text in raw text and RCDATA elements must not contain any
1.1       mike      811:   occurrences of the string "<code title="">&lt;/</code>" (U+003C
                    812:   LESS-THAN SIGN, U+002F SOLIDUS) followed by characters that
                    813:   case-insensitively match the tag name of the element followed by one
                    814:   of U+0009 CHARACTER TABULATION, U+000A LINE FEED (LF), U+000C FORM
                    815:   FEED (FF), U+0020 SPACE, U+003E GREATER-THAN SIGN (&gt;), or U+002F
1.97      mike      816:   SOLIDUS (/), unless that string is part of an <a href="#syntax-escape" title="syntax-escape">escaping text span</a>.</p>
                    817: 
                    818:   <p>An <dfn id="syntax-escape" title="syntax-escape">escaping text span</dfn> is a span
1.1       mike      819:   of <a href="#syntax-text" title="syntax-text">text</a> that starts with an <a href="#syntax-escape-start" title="syntax-escape-start">escaping text span start</a> that is
                    820:   not itself in an <a href="#syntax-escape" title="syntax-escape">escaping text
                    821:   span</a>, and ends at the next <a href="#syntax-escape-end" title="syntax-escape-end">escaping text span end</a>. There
                    822:   cannot be any <a href="#syntax-charref" title="syntax-charref">character
                    823:   references</a> inside an <a href="#syntax-escape" title="syntax-escape">escaping
                    824:   text span</a> &#8212; sequences of characters that would look
                    825:   like <a href="#syntax-charref" title="syntax-charref">character references</a> do not
1.97      mike      826:   have special meaning.</p>
                    827: 
                    828:   <p>An <dfn id="syntax-escape-start" title="syntax-escape-start">escaping text span
1.1       mike      829:   start</dfn> is a part of <a href="#syntax-text" title="syntax-text">text</a> that
                    830:   consists of the four character sequence "<code title="">&lt;!--</code>" (U+003C LESS-THAN SIGN, U+0021 EXCLAMATION
1.97      mike      831:   MARK, U+002D HYPHEN-MINUS, U+002D HYPHEN-MINUS).</p>
                    832: 
                    833:   <p>An <dfn id="syntax-escape-end" title="syntax-escape-end">escaping text span end</dfn> is
1.1       mike      834:   a part of <a href="#syntax-text" title="syntax-text">text</a> that consists of the
                    835:   three character sequence "<code title="">--&gt;</code>" (U+002D
                    836:   HYPHEN-MINUS, U+002D HYPHEN-MINUS, U+003E GREATER-THAN SIGN) whose
1.97      mike      837:   U+003E GREATER-THAN SIGN (&gt;).</p>
                    838: 
                    839:   <p>An <a href="#syntax-escape-start" title="syntax-escape-start">escaping text span
1.1       mike      840:   start</a> may share its U+002D HYPHEN-MINUS characters with its
                    841:   corresponding <a href="#syntax-escape-end" title="syntax-escape-end">escaping text span
1.97      mike      842:   end</a>.</p>
                    843: 
                    844:   <p>The text in raw text elements and RCDATA elements must not have
1.91      mike      845:   an <a href="#syntax-escape-start" title="syntax-escape-start">escaping text span start</a>
                    846:   that is not followed by an <a href="#syntax-escape-end" title="syntax-escape-end">escaping
1.97      mike      847:   text span end</a>.</p>
                    848: 
                    849: 
                    850:   <h4 id="text-0"><span class="secno">9.1.3 </span>Text</h4>
                    851: 
                    852:   <p><dfn id="syntax-text" title="syntax-text">Text</dfn> is allowed inside elements,
1.1       mike      853:   attributes, and comments. Text must consist of Unicode characters.
                    854:   Text must not contain U+0000 characters. Text must not contain
                    855:   permanently undefined Unicode characters. Text must not contain
                    856:   control characters other than <a href="infrastructure.html#space-character" title="space character">space
                    857:   characters</a>. Extra constraints are placed on what is and what
                    858:   is not allowed in text based on where the text is to be put, as
1.97      mike      859:   described in the other sections.</p>
                    860: 
                    861: 
                    862:   <h5 id="newlines"><span class="secno">9.1.3.1 </span>Newlines</h5>
                    863: 
                    864:   <p><dfn id="syntax-newlines" title="syntax-newlines">Newlines</dfn> in HTML may be
1.1       mike      865:   represented either as U+000D CARRIAGE RETURN (CR) characters, U+000A
                    866:   LINE FEED (LF) characters, or pairs of U+000D CARRIAGE RETURN (CR),
1.97      mike      867:   U+000A LINE FEED (LF) characters in that order.</p>
                    868: 
                    869: 
                    870:   <h4 id="character-references"><span class="secno">9.1.4 </span>Character references</h4>
                    871: 
                    872:   <p>In certain cases described in other sections, <a href="#syntax-text" title="syntax-text">text</a> may be mixed with <dfn id="syntax-charref" title="syntax-charref">character references</dfn>. These can be used
1.1       mike      873:   to escape characters that couldn't otherwise legally be included in
1.97      mike      874:   <a href="#syntax-text" title="syntax-text">text</a>.</p>
                    875: 
                    876:   <p>Character references must start with a U+0026 AMPERSAND
1.1       mike      877:   (<code>&amp;</code>). Following this, there are three possible kinds
1.97      mike      878:   of character references:</p>
                    879: 
                    880:   <dl><dt>Named character references</dt>
1.1       mike      881: 
                    882:    <dd>The ampersand must be followed by one of the names given in the
                    883:    <a href="named-character-references.html#named-character-references">named character references</a> section, using the same
                    884:    case. The name must be one that is terminated by a U+003B SEMICOLON
                    885:    (<code title="">;</code>) character.</dd>
                    886: 
                    887: 
                    888:    <dt>Decimal numeric character reference</dt>
                    889: 
                    890:    <dd>The ampersand must be followed by a U+0023 NUMBER SIGN
                    891:    (<code>#</code>) character, followed by one or more digits in the
                    892:    range U+0030 DIGIT ZERO .. U+0039 DIGIT NINE, representing a
                    893:    base-ten integer that itself is a Unicode code point that is
                    894:    not U+0000, U+000D, in the range U+0080 .. U+009F, or in the range
                    895:    0xD800 .. 0xDFFF (surrogates). The digits must then be followed by
                    896:    a U+003B SEMICOLON character (<code title="">;</code>).</dd>
                    897: 
                    898: 
                    899:    <dt>Hexadecimal numeric character reference</dt>
                    900: 
                    901:    <dd>The ampersand must be followed by a U+0023 NUMBER SIGN
                    902:    (<code>#</code>) character, which must be followed by either a
                    903:    U+0078 LATIN SMALL LETTER X or a U+0058 LATIN CAPITAL LETTER X
                    904:    character, which must then be followed by one or more digits in the
                    905:    range U+0030 DIGIT ZERO .. U+0039 DIGIT NINE, U+0061 LATIN SMALL
                    906:    LETTER A .. U+0066 LATIN SMALL LETTER F, and U+0041 LATIN CAPITAL
                    907:    LETTER A .. U+0046 LATIN CAPITAL LETTER F, representing a
                    908:    base-sixteen integer that itself is a Unicode code point that is
                    909:    not U+0000, U+000D, in the range U+0080 .. U+009F, or in the range
                    910:    0xD800 .. 0xDFFF (surrogates). The digits must then be followed by
                    911:    a U+003B SEMICOLON character (<code title="">;</code>).</dd>
                    912: 
                    913:   </dl><p>An <dfn id="syntax-ambiguous-ampersand" title="syntax-ambiguous-ampersand">ambiguous
                    914:   ampersand</dfn> is a U+0026 AMPERSAND (<code>&amp;</code>) character
                    915:   that is followed by some <a href="#syntax-text" title="syntax-text">text</a> other
                    916:   than a <a href="infrastructure.html#space-character">space character</a>, a U+003C LESS-THAN SIGN
                    917:   character ('&lt;'), or another U+0026 AMPERSAND (<code>&amp;</code>)
1.97      mike      918:   character.</p>
                    919: 
                    920: 
                    921:   <h4 id="cdata-sections"><span class="secno">9.1.5 </span>CDATA sections</h4>
                    922: 
                    923:   <p><dfn id="syntax-cdata" title="syntax-cdata">CDATA sections</dfn> must start with
1.1       mike      924:   the character sequence U+003C LESS-THAN SIGN, U+0021 EXCLAMATION
                    925:   MARK, U+005B LEFT SQUARE BRACKET, U+0043 LATIN CAPITAL LETTER C,
                    926:   U+0044 LATIN CAPITAL LETTER D, U+0041 LATIN CAPITAL LETTER A, U+0054
                    927:   LATIN CAPITAL LETTER T, U+0041 LATIN CAPITAL LETTER A, U+005B LEFT
                    928:   SQUARE BRACKET (<code title="">&lt;![CDATA[</code>). Following this
                    929:   sequence, the CDATA section may have <a href="#syntax-text" title="syntax-text">text</a>, with the additional restriction
                    930:   that the text must not contain the three character sequence U+005D
                    931:   RIGHT SQUARE BRACKET, U+005D RIGHT SQUARE BRACKET, U+003E
                    932:   GREATER-THAN SIGN (<code title="">]]&gt;</code>). Finally, the CDATA
                    933:   section must be ended by the three character sequence U+005D RIGHT
                    934:   SQUARE BRACKET, U+005D RIGHT SQUARE BRACKET, U+003E GREATER-THAN
1.97      mike      935:   SIGN (<code title="">]]&gt;</code>).</p>
                    936: 
                    937: 
                    938:   <h4 id="comments"><span class="secno">9.1.6 </span>Comments</h4>
                    939: 
                    940:   <p><dfn id="syntax-comments" title="syntax-comments">Comments</dfn> must start with the
1.1       mike      941:   four character sequence U+003C LESS-THAN SIGN, U+0021 EXCLAMATION
                    942:   MARK, U+002D HYPHEN-MINUS, U+002D HYPHEN-MINUS (<code title="">&lt;!--</code>). Following this sequence, the comment may
                    943:   have <a href="#syntax-text" title="syntax-text">text</a>, with the additional
                    944:   restriction that the text must not start with a single U+003E
                    945:   GREATER-THAN SIGN ('&gt;') character, nor start with a U+002D
                    946:   HYPHEN-MINUS (<code title="">-</code>) character followed by a
                    947:   U+003E GREATER-THAN SIGN ('&gt;') character, nor contain two
                    948:   consecutive U+002D HYPHEN-MINUS (<code title="">-</code>)
                    949:   characters, nor end with a U+002D HYPHEN-MINUS (<code title="">-</code>) character. Finally, the comment must be ended by
                    950:   the three character sequence U+002D HYPHEN-MINUS, U+002D
1.97      mike      951:   HYPHEN-MINUS, U+003E GREATER-THAN SIGN (<code title="">--&gt;</code>).</p>
                    952: 
                    953: 
                    954:   <div class="impl">
1.1       mike      955: 
                    956:   <h3 id="parsing"><span class="secno">9.2 </span>Parsing HTML documents</h3>
                    957: 
                    958:   <p><i>This section only applies to user agents, data mining tools,
                    959:   and conformance checkers.</i></p>
                    960: 
                    961:   <p class="note">The rules for parsing XML documents into DOM trees
                    962:   are covered by the next section, entitled "<a href="the-xhtml-syntax.html#the-xhtml-syntax">The XHTML
                    963:   syntax</a>".</p>
                    964: 
                    965:   <p>For <a href="dom.html#html-documents">HTML documents</a>, user agents must use the parsing
                    966:   rules described in this section to generate the DOM trees. Together,
                    967:   these rules define what is referred to as the <dfn id="html-parser">HTML
                    968:   parser</dfn>.</p>
                    969: 
                    970:   <div class="note">
                    971: 
                    972:    <p>While the HTML syntax described in this specification bears a
                    973:    close resemblance to SGML and XML, it is a separate language with
                    974:    its own parsing rules.</p>
                    975: 
                    976:    <p>Some earlier versions of HTML (in particular from HTML&#160;2 to
                    977:    HTML&#160;4) were based on SGML and used SGML parsing rules. However, few
                    978:    (if any) web browsers ever implemented true SGML parsing for HTML
                    979:    documents; the only user agents to strictly handle HTML as an SGML
                    980:    application have historically been validators. The resulting
                    981:    confusion &#8212; with validators claiming documents to have one
                    982:    representation while widely deployed Web browsers interoperably
                    983:    implemented a different representation &#8212; has wasted decades
                    984:    of productivity. This version of HTML thus returns to a non-SGML
                    985:    basis.</p>
                    986: 
                    987:    <p>Authors interested in using SGML tools in their authoring
                    988:    pipeline are encouraged to use XML tools and the XML serialization
                    989:    of HTML.</p>
                    990: 
                    991:   </div>
                    992: 
                    993:   <p>This specification defines the parsing rules for HTML documents,
                    994:   whether they are syntactically correct or not. Certain points in the
                    995:   parsing algorithm are said to be <dfn id="parse-error" title="parse error">parse
                    996:   errors</dfn>. The error handling for parse errors is well-defined:
                    997:   user agents must either act as described below when encountering
                    998:   such problems, or must abort processing at the first error that they
                    999:   encounter for which they do not wish to apply the rules described
                   1000:   below.</p>
                   1001: 
                   1002:   <p>Conformance checkers must report at least one parse error
                   1003:   condition to the user if one or more parse error conditions exist in
                   1004:   the document and must not report parse error conditions if none
                   1005:   exist in the document. Conformance checkers may report more than one
                   1006:   parse error condition if more than one parse error conditions exist
                   1007:   in the document. Conformance checkers are not required to recover
                   1008:   from parse errors.</p>
                   1009: 
                   1010:   <p class="note">Parse errors are only errors with the
                   1011:   <em>syntax</em> of HTML. In addition to checking for parse errors,
                   1012:   conformance checkers will also verify that the document obeys all
                   1013:   the other conformance requirements described in this
                   1014:   specification.</p>
                   1015: 
                   1016:   <p>For the purposes of conformance checkers, if a resource is
                   1017:   determined to be in <a href="#syntax">the HTML syntax</a>, then it is an
                   1018:   <a href="dom.html#html-documents" title="HTML documents">HTML document</a>.</p>
                   1019: 
                   1020: 
                   1021:   <h4 id="overview-of-the-parsing-model"><span class="secno">9.2.1 </span>Overview of the parsing model</h4>
                   1022: 
                   1023:   <p>The input to the HTML parsing process consists of a stream of
                   1024:   Unicode characters, which is passed through a
                   1025:   <a href="#tokenization">tokenization</a> stage followed by a <a href="#tree-construction">tree
                   1026:   construction</a> stage. The output is a <code>Document</code>
                   1027:   object.</p>
                   1028: 
                   1029:   <p class="note">Implementations that <a href="infrastructure.html#non-scripted">do not
                   1030:   support scripting</a> do not have to actually create a DOM
                   1031:   <code>Document</code> object, but the DOM tree in such cases is
                   1032:   still used as the model for the rest of the specification.</p>
                   1033: 
                   1034:   <p>In the common case, the data handled by the tokenization stage
                   1035:   comes from the network, but <a href="dom.html#dynamic-markup-insertion" title="dynamic markup
                   1036:   insertion">it can also come from script</a>, e.g. using the <code title="dom-document-write"><a href="dom.html#dom-document-write">document.write()</a></code> API.</p>
                   1037: 
                   1038:   <p><img alt="" src="images/parsing-model-overview.png"></p>
                   1039: 
                   1040:   <p id="nestedParsing">There is only one set of states for the
                   1041:   tokenizer stage and the tree construction stage, but the tree
                   1042:   construction stage is reentrant, meaning that while the tree
                   1043:   construction stage is handling one token, the tokenizer might be
                   1044:   resumed, causing further tokens to be emitted and processed before
                   1045:   the first token's processing is complete.</p>
                   1046: 
                   1047:   <div class="example">
                   1048: 
                   1049:    <p>In the following example, the tree construction stage will be
                   1050:    called upon to handle a "p" start tag token while handling the
                   1051:    "script" start tag token:</p>
                   1052: 
                   1053:    <pre>...
                   1054: &lt;script&gt;
                   1055:  document.write('&lt;p&gt;');
                   1056: &lt;/script&gt;
                   1057: ...</pre>
                   1058: 
                   1059:   </div>
                   1060: 
                   1061:   <p>To handle these cases, parsers have a <dfn id="script-nesting-level">script nesting
                   1062:   level</dfn>, which must be initially set to zero, and a <dfn id="parser-pause-flag">parser
                   1063:   pause flag</dfn>, which must be initially set to false.</p>
                   1064: 
                   1065: 
                   1066: 
                   1067:   <h4 id="the-input-stream"><span class="secno">9.2.2 </span>The <dfn>input stream</dfn></h4>
                   1068: 
                   1069:   <p>The stream of Unicode characters that comprises the input to the
                   1070:   tokenization stage will be initially seen by the user agent as a
                   1071:   stream of bytes (typically coming over the network or from the local
                   1072:   file system). The bytes encode the actual characters according to a
                   1073:   particular <em>character encoding</em>, which the user agent must
                   1074:   use to decode the bytes into characters.</p>
                   1075: 
                   1076:   <p class="note">For XML documents, the algorithm user agents must
                   1077:   use to determine the character encoding is given by the XML
1.104     mike     1078:   specification. This section does not apply to XML documents. <a href="references.html#refsXML">[XML]</a></p>
1.1       mike     1079: 
                   1080: 
                   1081:   <h5 id="determining-the-character-encoding"><span class="secno">9.2.2.1 </span>Determining the character encoding</h5>
                   1082: 
                   1083:   <p>In some cases, it might be impractical to unambiguously determine
                   1084:   the encoding before parsing the document. Because of this, this
                   1085:   specification provides for a two-pass mechanism with an optional
                   1086:   pre-scan. Implementations are allowed, as described below, to apply
                   1087:   a simplified parsing algorithm to whatever bytes they have available
                   1088:   before beginning to parse the document. Then, the real parser is
                   1089:   started, using a tentative encoding derived from this pre-parse and
                   1090:   other out-of-band metadata. If, while the document is being loaded,
                   1091:   the user agent discovers an encoding declaration that conflicts with
                   1092:   this information, then the parser can get reinvoked to perform a
                   1093:   parse of the document with the real encoding.</p>
                   1094: 
                   1095:   <p id="documentEncoding">User agents must use the following
                   1096:   algorithm (the <dfn id="encoding-sniffing-algorithm">encoding sniffing algorithm</dfn>) to determine
                   1097:   the character encoding to use when decoding a document in the first
                   1098:   pass. This algorithm takes as input any out-of-band metadata
                   1099:   available to the user agent (e.g. the <a href="infrastructure.html#content-type" title="Content-Type">Content-Type metadata</a> of the document)
                   1100:   and all the bytes available so far, and returns an encoding and a
                   1101:   <dfn id="concept-encoding-confidence" title="concept-encoding-confidence">confidence</dfn>. The
                   1102:   confidence is either <i>tentative</i>, <i>certain</i>, or
                   1103:   <i>irrelevant</i>. The encoding used, and whether the confidence in
                   1104:   that encoding is <i>tentative</i> or <i>certain</i>, is <a href="#meta-charset-during-parse">used during the parsing</a> to
                   1105:   determine whether to <a href="#change-the-encoding">change the encoding</a>. If no
                   1106:   encoding is necessary, e.g. because the parser is operating on a
                   1107:   stream of Unicode characters and doesn't have to use an encoding at
                   1108:   all, then the <a href="#concept-encoding-confidence" title="concept-encoding-confidence">confidence</a> is
                   1109:   <i>irrelevant</i>.</p>
                   1110: 
                   1111:   <ol><li><p>If the transport layer specifies an encoding, and it is
                   1112:    supported, return that encoding with the <a href="#concept-encoding-confidence" title="concept-encoding-confidence">confidence</a>
                   1113:    <i>certain</i>, and abort these steps.</p></li>
                   1114: 
                   1115:    <li><p>The user agent may wait for more bytes of the resource to be
                   1116:    available, either in this step or at any later step in this
                   1117:    algorithm. For instance, a user agent might wait 500ms or 512
                   1118:    bytes, whichever came first. In general preparsing the source to
                   1119:    find the encoding improves performance, as it reduces the need to
                   1120:    throw away the data structures used when parsing upon finding the
                   1121:    encoding information. However, if the user agent delays too long to
                   1122:    obtain data to determine the encoding, then the cost of the delay
                   1123:    could outweigh any performance improvements from the
                   1124:    preparse.</p></li>
                   1125: 
                   1126:    <li><p>For each of the rows in the following table, starting with
                   1127:    the first one and going down, if there are as many or more bytes
                   1128:    available than the number of bytes in the first column, and the
                   1129:    first bytes of the file match the bytes given in the first column,
                   1130:    then return the encoding given in the cell in the second column of
                   1131:    that row, with the <a href="#concept-encoding-confidence" title="concept-encoding-confidence">confidence</a>
                   1132:    <i>certain</i>, and abort these steps:</p>
                   1133: 
                   1134:     <!-- this table is present in several forms in this file; keep them in sync -->
                   1135:     <table><thead><tr><th>Bytes in Hexadecimal
                   1136:        </th><th>Encoding
                   1137:      </th></tr></thead><tbody><!-- nobody uses this
                   1138:       <tr>
                   1139:        <td>00 00 FE FF
                   1140:        <td>UTF-32BE
                   1141:       <tr>
                   1142:        <td>FF FE 00 00
                   1143:        <td>UTF-32LE
                   1144: --><tr><td>FE FF
                   1145:        </td><td>UTF-16BE
                   1146:       </td></tr><tr><td>FF FE
                   1147:        </td><td>UTF-16LE
                   1148:       </td></tr><tr><td>EF BB BF
                   1149:        </td><td>UTF-8
                   1150: <!-- nobody uses this
                   1151:       <tr>
                   1152:        <td>DD 73 66 73
                   1153:        <td>UTF-EBCDIC
                   1154: -->
                   1155:     </td></tr></tbody></table><p class="note">This step looks for Unicode Byte Order Marks
                   1156:    (BOMs).</p></li>
                   1157: 
                   1158:    <li><p>Otherwise, the user agent will have to search for explicit
                   1159:    character encoding information in the file itself. This should
                   1160:    proceed as follows:
                   1161: 
                   1162:     </p><p>Let <var title="">position</var> be a pointer to a byte in the
                   1163:     input stream, initially pointing at the first byte. If at any
                   1164:     point during these substeps the user agent either runs out of
                   1165:     bytes or decides that scanning further bytes would not be
                   1166:     efficient, then skip to the next step of the overall character
                   1167:     encoding detection algorithm. User agents may decide that scanning
                   1168:     <em>any</em> bytes is not efficient, in which case these substeps
                   1169:     are entirely skipped.</p>
                   1170: 
                   1171:     <p>Now, repeat the following "two" steps until the algorithm
                   1172:     aborts (either because user agent aborts, as described above, or
                   1173:     because a character encoding is found):</p>
                   1174: 
                   1175:     <ol><li><p>If <var title="">position</var> points to:</p>
                   1176: 
                   1177:       <dl class="switch"><dt>A sequence of bytes starting with: 0x3C 0x21 0x2D 0x2D (ASCII '&lt;!--')</dt>
                   1178:        <dd>
                   1179: 
                   1180:         <p>Advance the <var title="">position</var> pointer so that it
                   1181:         points at the first 0x3E byte which is preceded by two 0x2D
                   1182:         bytes (i.e. at the end of an ASCII '--&gt;' sequence) and comes
                   1183:         after the 0x3C byte that was found. (The two 0x2D bytes can be
                   1184:         the same as the those in the '&lt;!--' sequence.)</p>
                   1185: 
                   1186:        </dd>
                   1187: 
                   1188:        <dt>A sequence of bytes starting with: 0x3C, 0x4D or 0x6D, 0x45 or 0x65, 0x54 or 0x74, 0x41 or 0x61, and finally one of 0x09, 0x0A, 0x0C, 0x0D, 0x20, 0x2F (case-insensitive ASCII '&lt;meta' followed by a space or slash)</dt>
                   1189:        <dd>
                   1190: 
                   1191:         <ol><li><p>Advance the <var title="">position</var> pointer so
                   1192:          that it points at the next 0x09, 0x0A, 0x0C, 0x0D, 0x20, or
                   1193:          0x2F byte (the one in sequence of characters matched
                   1194:          above).</p></li>
                   1195: 
                   1196:          <li><p><a href="#concept-get-attributes-when-sniffing" title="concept-get-attributes-when-sniffing">Get
                   1197:          an attribute</a> and its value. If no attribute was
                   1198:          sniffed, then skip this inner set of steps, and jump to the
                   1199:          second step in the overall "two step" algorithm.</p></li>
                   1200: 
                   1201:          <li><p>If the attribute's name is neither "<code title="">charset</code>" nor "<code title="">content</code>",
                   1202:          then return to step 2 in these inner steps.</p></li>
                   1203: 
                   1204:          <li><p>If the attribute's name is "<code title="">charset</code>", let <var title="">charset</var> be
                   1205:          the attribute's value, interpreted as a character
                   1206:          encoding.</p></li>
                   1207: 
                   1208:          <li><p>Otherwise, the attribute's name is "<code title="">content</code>": apply the <a href="infrastructure.html#algorithm-for-extracting-an-encoding-from-a-content-type">algorithm for
                   1209:          extracting an encoding from a Content-Type</a>, giving the
                   1210:          attribute's value as the string to parse. If an encoding is
                   1211:          returned, let <var title="">charset</var> be that
                   1212:          encoding. Otherwise, return to step 2 in these inner
                   1213:          steps.</p></li>
                   1214: 
                   1215:          <li><p>If <var title="">charset</var> is a UTF-16 encoding,
                   1216:          change the value of <var title="">charset</var> to
                   1217:          UTF-8.</p></li>
                   1218: 
                   1219:          <li><p>If <var title="">charset</var> is a supported
                   1220:          character encoding, then return the given encoding, with
                   1221:          <a href="#concept-encoding-confidence" title="concept-encoding-confidence">confidence</a>
                   1222:          <i>tentative</i>, and abort all these steps.</p></li>
                   1223: 
                   1224:          <li><p>Otherwise, return to step 2 in these inner
                   1225:          steps.</p></li>
                   1226: 
                   1227:         </ol></dd>
                   1228: 
                   1229:        <dt>A sequence of bytes starting with a 0x3C byte (ASCII '&lt;'), optionally a 0x2F byte (ASCII '/'), and finally a byte in the range 0x41-0x5A or 0x61-0x7A (an ASCII letter)</dt>
                   1230:        <dd>
                   1231: 
                   1232:         <ol><li><p>Advance the <var title="">position</var> pointer so
                   1233:          that it points at the next 0x09 (ASCII TAB), 0x0A (ASCII LF),
                   1234:          0x0C (ASCII FF), 0x0D (ASCII CR), 0x20 (ASCII space), or 0x3E
                   1235:          (ASCII '&gt;') byte.</p></li>
                   1236: 
                   1237:          <li><p>Repeatedly <a href="#concept-get-attributes-when-sniffing" title="concept-get-attributes-when-sniffing">get an
                   1238:          attribute</a> until no further attributes can be found,
                   1239:          then jump to the second step in the overall "two step"
                   1240:          algorithm.</p></li>
                   1241: 
                   1242:         </ol></dd>
                   1243: 
                   1244:        <dt>A sequence of bytes starting with: 0x3C 0x21 (ASCII '&lt;!')</dt>
                   1245:        <dt>A sequence of bytes starting with: 0x3C 0x2F (ASCII '&lt;/')</dt>
                   1246:        <dt>A sequence of bytes starting with: 0x3C 0x3F (ASCII '&lt;?')</dt>
                   1247:        <dd>
                   1248: 
                   1249:         <p>Advance the <var title="">position</var> pointer so that it
                   1250:         points at the first 0x3E byte (ASCII '&gt;') that comes after the
                   1251:         0x3C byte that was found.</p>
                   1252: 
                   1253:        </dd>
                   1254: 
                   1255:        <dt>Any other byte</dt>
                   1256:        <dd>
                   1257: 
                   1258:         <p>Do nothing with that byte.</p>
                   1259: 
                   1260:        </dd>
                   1261: 
                   1262:       </dl></li>
                   1263: 
                   1264:      <li>Move <var title="">position</var> so it points at the next
                   1265:      byte in the input stream, and return to the first step of this
                   1266:      "two step" algorithm.</li>
                   1267: 
                   1268:     </ol><p>When the above "two step" algorithm says to <dfn id="concept-get-attributes-when-sniffing" title="concept-get-attributes-when-sniffing">get an
                   1269:     attribute</dfn>, it means doing this:</p>
                   1270: 
                   1271:     <ol><li><p>If the byte at <var title="">position</var> is one of 0x09
                   1272:      (ASCII TAB), 0x0A (ASCII LF), 0x0C (ASCII FF), 0x0D (ASCII CR),
                   1273:      0x20 (ASCII space), or 0x2F (ASCII '/') then advance <var title="">position</var> to the next byte and redo this
                   1274:      substep.</p></li>
                   1275: 
                   1276:      <li><p>If the byte at <var title="">position</var> is 0x3E (ASCII
                   1277:      '&gt;'), then abort the "get an attribute" algorithm. There isn't
                   1278:      one.</p></li>
                   1279: 
                   1280:      <li><p>Otherwise, the byte at <var title="">position</var> is the
                   1281:      start of the attribute name. Let <var title="">attribute
                   1282:      name</var> and <var title="">attribute value</var> be the empty
                   1283:      string.</p></li>
                   1284: 
                   1285:      <li><p><i>Attribute name</i>: Process the byte at <var title="">position</var> as follows:</p>
                   1286: 
                   1287:       <dl class="switch"><dt>If it is 0x3D (ASCII '='), and the <var title="">attribute
                   1288:        name</var> is longer than the empty string</dt>
                   1289: 
                   1290:        <dd>Advance <var title="">position</var> to the next byte and
                   1291:        jump to the step below labeled <i>value</i>.</dd>
                   1292: 
                   1293:        <dt>If it is 0x09 (ASCII TAB), 0x0A (ASCII LF), 0x0C (ASCII
                   1294:        FF), 0x0D (ASCII CR), or 0x20 (ASCII space)</dt>
                   1295: 
                   1296:        <dd>Jump to the step below labeled <i>spaces</i>.</dd>
                   1297: 
                   1298:        <dt>If it is 0x2F (ASCII '/') or 0x3E (ASCII '&gt;')</dt>
                   1299: 
                   1300:        <dd>Abort the "get an attribute" algorithm. The attribute's
                   1301:        name is the value of <var title="">attribute name</var>, its
                   1302:        value is the empty string.</dd>
                   1303: 
                   1304:        <dt>If it is in the range 0x41 (ASCII 'A') to 0x5A (ASCII
                   1305:        'Z')</dt>
                   1306: 
                   1307:        <dd>Append the Unicode character with code point <span title=""><var title="">b</var>+0x20</span> to <var title="">attribute
                   1308:        name</var> (where <var title="">b</var> is the value of the
                   1309:        byte at <var title="">position</var>).</dd>
                   1310: 
                   1311:        <dt>Anything else</dt>
                   1312: 
                   1313:        <dd>Append the Unicode character with the same code point as the
                   1314:        value of the byte at <var title="">position</var>) to <var title="">attribute name</var>. (It doesn't actually matter how
                   1315:        bytes outside the ASCII range are handled here, since only
                   1316:        ASCII characters can contribute to the detection of a character
                   1317:        encoding.)</dd>
                   1318: 
                   1319:       </dl></li>
                   1320: 
                   1321:      <li><p>Advance <var title="">position</var> to the next byte and
                   1322:      return to the previous step.</p></li>
                   1323: 
                   1324:      <li><p><i>Spaces</i>: If the byte at <var title="">position</var> is one of 0x09 (ASCII TAB), 0x0A (ASCII
                   1325:      LF), 0x0C (ASCII FF), 0x0D (ASCII CR), or 0x20 (ASCII space) then
                   1326:      advance <var title="">position</var> to the next byte, then,
                   1327:      repeat this step.</p></li>
                   1328: 
                   1329:      <li><p>If the byte at <var title="">position</var> is
                   1330:      <em>not</em> 0x3D (ASCII '='), abort the "get an attribute"
                   1331:      algorithm. The attribute's name is the value of <var title="">attribute name</var>, its value is the empty
                   1332:      string.</p></li>
                   1333: 
                   1334:      <li><p>Advance <var title="">position</var> past the 0x3D (ASCII
                   1335:      '=') byte.</p></li>
                   1336: 
                   1337:      <li><p><i>Value:</i> If the byte at <var title="">position</var> is one of 0x09 (ASCII TAB), 0x0A (ASCII
                   1338:      LF), 0x0C (ASCII FF), 0x0D (ASCII CR), or 0x20 (ASCII space) then
                   1339:      advance <var title="">position</var> to the next byte, then,
                   1340:      repeat this step.</p></li>
                   1341: 
                   1342:      <li><p>Process the byte at <var title="">position</var> as
                   1343:      follows:</p>
                   1344: 
                   1345:       <dl class="switch"><dt>If it is 0x22 (ASCII '"') or 0x27 ("'")</dt>
                   1346: 
                   1347:        <dd>
                   1348: 
                   1349:         <ol><li>Let <var title="">b</var> be the value of the byte at
                   1350:          <var title="">position</var>.</li>
                   1351: 
                   1352:          <li>Advance <var title="">position</var> to the next
                   1353:          byte.</li>
                   1354: 
                   1355:          <li>If the value of the byte at <var title="">position</var>
                   1356:          is the value of <var title="">b</var>, then advance <var title="">position</var> to the next byte and abort the "get
                   1357:          an attribute" algorithm. The attribute's name is the value of
                   1358:          <var title="">attribute name</var>, and its value is the
                   1359:          value of <var title="">attribute value</var>.</li>
                   1360: 
                   1361:          <li>Otherwise, if the value of the byte at <var title="">position</var> is in the range 0x41 (ASCII 'A') to
                   1362:          0x5A (ASCII 'Z'), then append a Unicode character to <var title="">attribute value</var> whose code point is 0x20 more
                   1363:          than the value of the byte at <var title="">position</var>.</li>
                   1364: 
                   1365:          <li>Otherwise, append a Unicode character to <var title="">attribute value</var> whose code point is the same as
                   1366:          the value of the byte at <var title="">position</var>.</li>
                   1367: 
                   1368:          <li>Return to the second step in these substeps.</li>
                   1369: 
                   1370:         </ol></dd>
                   1371: 
                   1372:        <dt>If it is 0x3E (ASCII '&gt;')</dt>
                   1373: 
                   1374:        <dd>Abort the "get an attribute" algorithm. The attribute's
                   1375:        name is the value of <var title="">attribute name</var>, its
                   1376:        value is the empty string.</dd>
                   1377: 
                   1378: 
                   1379:        <dt>If it is in the range 0x41 (ASCII 'A') to 0x5A (ASCII
                   1380:        'Z')</dt>
                   1381: 
                   1382:        <dd>Append the Unicode character with code point <span title=""><var title="">b</var>+0x20</span> to <var title="">attribute
                   1383:        value</var> (where <var title="">b</var> is the value of the
                   1384:        byte at <var title="">position</var>). Advance <var title="">position</var> to the next byte.</dd>
                   1385: 
                   1386:        <dt>Anything else</dt>
                   1387: 
                   1388:        <dd>Append the Unicode character with the same code point as the
                   1389:        value of the byte at <var title="">position</var>) to <var title="">attribute value</var>. Advance <var title="">position</var> to the next byte.</dd>
                   1390: 
                   1391:       </dl></li>
                   1392: 
                   1393:      <li><p>Process the byte at <var title="">position</var> as
                   1394:      follows:</p>
                   1395: 
                   1396:       <dl class="switch"><dt>If it is 0x09 (ASCII TAB), 0x0A (ASCII LF), 0x0C (ASCII
                   1397:        FF), 0x0D (ASCII CR), 0x20 (ASCII space), or 0x3E (ASCII
                   1398:        '&gt;')</dt>
                   1399: 
                   1400:        <dd>Abort the "get an attribute" algorithm. The attribute's
                   1401:        name is the value of <var title="">attribute name</var> and its
                   1402:        value is the value of <var title="">attribute value</var>.</dd>
                   1403: 
                   1404:        <dt>If it is in the range 0x41 (ASCII 'A') to 0x5A (ASCII
                   1405:        'Z')</dt>
                   1406: 
                   1407:        <dd>Append the Unicode character with code point <span title=""><var title="">b</var>+0x20</span> to <var title="">attribute
                   1408:        value</var> (where <var title="">b</var> is the value of the
                   1409:        byte at <var title="">position</var>).</dd>
                   1410: 
                   1411:        <dt>Anything else</dt>
                   1412: 
                   1413:        <dd>Append the Unicode character with the same code point as the
                   1414:        value of the byte at <var title="">position</var>) to <var title="">attribute value</var>.</dd>
                   1415: 
                   1416:       </dl></li>
                   1417: 
                   1418:      <li><p>Advance <var title="">position</var> to the next byte and
                   1419:      return to the previous step.</p></li>
                   1420: 
                   1421:     </ol><p>For the sake of interoperability, user agents should not use a
                   1422:     pre-scan algorithm that returns different results than the one
                   1423:     described above. (But, if you do, please at least let us know, so
                   1424:     that we can improve this algorithm and benefit everyone...)</p>
                   1425: 
                   1426:    </li>
                   1427: 
                   1428:    <li><p>If the user agent has information on the likely encoding for
                   1429:    this page, e.g. based on the encoding of the page when it was last
                   1430:    visited, then return that encoding, with the <a href="#concept-encoding-confidence" title="concept-encoding-confidence">confidence</a>
                   1431:    <i>tentative</i>, and abort these steps.</p></li>
                   1432: 
                   1433:    <li><p>The user agent may attempt to autodetect the character
                   1434:    encoding from applying frequency analysis or other algorithms to
                   1435:    the data stream. If autodetection succeeds in determining a
                   1436:    character encoding, then return that encoding, with the <a href="#concept-encoding-confidence" title="concept-encoding-confidence">confidence</a>
1.104     mike     1437:    <i>tentative</i>, and abort these steps. <a href="references.html#refsUNIVCHARDET">[UNIVCHARDET]</a></p></li>
1.1       mike     1438: 
                   1439:    <li><p>Otherwise, return an implementation-defined or
                   1440:    user-specified default character encoding, with the <a href="#concept-encoding-confidence" title="concept-encoding-confidence">confidence</a>
                   1441:    <i>tentative</i>. In non-legacy environments, the more
                   1442:    comprehensive <code title="">UTF-8</code> encoding is
                   1443:    recommended. Due to its use in legacy content, <code title="">windows-1252</code> is recommended as a default in
                   1444:    predominantly Western demographics instead. Since these encodings
                   1445:    can in many cases be distinguished by inspection, a user agent may
                   1446:    heuristically decide which to use as a default.</p></li>
                   1447: 
                   1448:   </ol><p>The <a href="dom.html#document-s-character-encoding">document's character encoding</a> must immediately
                   1449:   be set to the value returned from this algorithm, at the same time
                   1450:   as the user agent uses the returned value to select the decoder to
                   1451:   use for the input stream.</p>
                   1452: 
                   1453: 
                   1454: 
                   1455:   <h5 id="preprocessing-the-input-stream"><span class="secno">9.2.2.2 </span>Preprocessing the input stream</h5>
                   1456: 
                   1457:   <p>Given an encoding, the bytes in the input stream must be
                   1458:   converted to Unicode characters for the tokenizer, as described by
                   1459:   the rules for that encoding, except that the leading U+FEFF BYTE
                   1460:   ORDER MARK character, if any, must not be stripped by the encoding
                   1461:   layer (it is stripped by the rule below).</p> <!-- this is to
                   1462:   prevent two leading BOMs from being both stripped, once by the
                   1463:   decoder, and once by the parser -->
                   1464: 
                   1465:   <p>Bytes or sequences of bytes in the original byte stream that
                   1466:   could not be converted to Unicode characters must be converted to
                   1467:   U+FFFD REPLACEMENT CHARACTER code points.</p>
                   1468: 
                   1469:   <p class="note">Bytes or sequences of bytes in the original byte
                   1470:   stream that did not conform to the encoding specification
                   1471:   (e.g. invalid UTF-8 byte sequences in a UTF-8 input stream) are
                   1472:   errors that conformance checkers are expected to report.</p>
                   1473: 
                   1474:   <p>Any byte or sequences of bytes in the original byte stream that
                   1475:   is <a href="infrastructure.html#misinterpreted-for-compatibility">misinterpreted for compatibility</a> is a <a href="#parse-error">parse
                   1476:   error</a>.</p>
                   1477: 
                   1478:   <p>One leading U+FEFF BYTE ORDER MARK character must be ignored if
                   1479:   any are present.</p>
                   1480: 
                   1481:   <p>All U+0000 NULL characters in the input must be replaced by
                   1482:   U+FFFD REPLACEMENT CHARACTERs. Any occurrences of such characters is
                   1483:   a <a href="#parse-error">parse error</a>.</p>
                   1484: 
                   1485:   <p>Any occurrences of any characters in the ranges U+0001 to U+0008,
                   1486:   <!-- HT, LF allowed --> <!-- U+000B is in the next list --> <!-- FF,
                   1487:   CR allowed --> U+000E to U+001F, <!-- ASCII allowed --> U+007F
                   1488:   <!--to U+0084, (U+0085 NEL not allowed), U+0086--> to U+009F, U+D800
                   1489:   to U+DFFF<!-- surrogates not allowed -->, U+FDD0 to U+FDEF, and
                   1490:   characters U+000B, U+FFFE, U+FFFF, U+1FFFE, U+1FFFF, U+2FFFE,
                   1491:   U+2FFFF, U+3FFFE, U+3FFFF, U+4FFFE, U+4FFFF, U+5FFFE, U+5FFFF,
                   1492:   U+6FFFE, U+6FFFF, U+7FFFE, U+7FFFF, U+8FFFE, U+8FFFF, U+9FFFE,
                   1493:   U+9FFFF, U+AFFFE, U+AFFFF, U+BFFFE, U+BFFFF, U+CFFFE, U+CFFFF,
                   1494:   U+DFFFE, U+DFFFF, U+EFFFE, U+EFFFF, U+FFFFE, U+FFFFF, U+10FFFE, and
                   1495:   U+10FFFF are <a href="#parse-error" title="parse error">parse errors</a>. (These
                   1496:   are all control characters or permanently undefined Unicode
                   1497:   characters.)</p>
                   1498: 
                   1499:   <p>U+000D CARRIAGE RETURN (CR) characters and U+000A LINE FEED (LF)
                   1500:   characters are treated specially. Any CR characters that are
                   1501:   followed by LF characters must be removed, and any CR characters not
                   1502:   followed by LF characters must be converted to LF characters. Thus,
                   1503:   newlines in HTML DOMs are represented by LF characters, and there
                   1504:   are never any CR characters in the input to the
                   1505:   <a href="#tokenization">tokenization</a> stage.</p>
                   1506: 
                   1507:   <p>The <dfn id="next-input-character">next input character</dfn> is the first character in the
                   1508:   input stream that has not yet been <dfn id="consumed">consumed</dfn>. Initially,
                   1509:   the <i><a href="#next-input-character">next input character</a></i> is the first character in the
                   1510:   input. The <dfn id="current-input-character">current input character</dfn> is the last character
                   1511:   to have been <i><a href="#consumed">consumed</a></i>.</p>
                   1512: 
                   1513:   <p>The <dfn id="insertion-point">insertion point</dfn> is the position (just before a
                   1514:   character or just before the end of the input stream) where content
                   1515:   inserted using <code title="dom-document-write"><a href="dom.html#dom-document-write">document.write()</a></code> is actually
                   1516:   inserted. The insertion point is relative to the position of the
                   1517:   character immediately after it, it is not an absolute offset into
                   1518:   the input stream. Initially, the insertion point is
1.10      mike     1519:   undefined.</p>
1.1       mike     1520: 
                   1521:   <p>The "EOF" character in the tables below is a conceptual character
                   1522:   representing the end of the <a href="#the-input-stream">input stream</a>. If the parser
                   1523:   is a <a href="dom.html#script-created-parser">script-created parser</a>, then the end of the
                   1524:   <a href="#the-input-stream">input stream</a> is reached when an <dfn id="explicit-eof-character">explicit "EOF"
                   1525:   character</dfn> (inserted by the <code title="dom-document-close"><a href="dom.html#dom-document-close">document.close()</a></code> method) is
                   1526:   consumed. Otherwise, the "EOF" character is not a real character in
                   1527:   the stream, but rather the lack of any further characters.</p>
                   1528: 
                   1529: 
                   1530:   <h5 id="changing-the-encoding-while-parsing"><span class="secno">9.2.2.3 </span>Changing the encoding while parsing</h5>
                   1531: 
                   1532:   <p>When the parser requires the user agent to <dfn id="change-the-encoding">change the
                   1533:   encoding</dfn>, it must run the following steps. This might happen
                   1534:   if the <a href="#encoding-sniffing-algorithm">encoding sniffing algorithm</a> described above
                   1535:   failed to find an encoding, or if it found an encoding that was not
                   1536:   the actual encoding of the file.</p>
                   1537: 
                   1538:   <ol><li>If the new encoding is identical or equivalent to the encoding
                   1539:    that is already being used to interpret the input stream, then set
                   1540:    the <a href="#concept-encoding-confidence" title="concept-encoding-confidence">confidence</a> to
                   1541:    <i>certain</i> and abort these steps. This happens when the
                   1542:    encoding information found in the file matches what the
                   1543:    <a href="#encoding-sniffing-algorithm">encoding sniffing algorithm</a> determined to be the
                   1544:    encoding, and in the second pass through the parser if the first
                   1545:    pass found that the encoding sniffing algorithm described in the
                   1546:    earlier section failed to find the right encoding.</li>
                   1547: 
                   1548:    <li>If the encoding that is already being used to interpret the
                   1549:    input stream is a UTF-16 encoding, then set the <a href="#concept-encoding-confidence" title="concept-encoding-confidence">confidence</a> to
                   1550:    <i>certain</i> and abort these steps. The new encoding is ignored;
                   1551:    if it was anything but the same encoding, then it would be clearly
                   1552:    incorrect.</li>
                   1553: 
                   1554:    <li>If the new encoding is a UTF-16 encoding, change it to
                   1555:    UTF-8.</li>
                   1556: 
                   1557:    <li>If all the bytes up to the last byte converted by the current
                   1558:    decoder have the same Unicode interpretations in both the current
                   1559:    encoding and the new encoding, and if the user agent supports
                   1560:    changing the converter on the fly, then the user agent may change
                   1561:    to the new converter for the encoding on the fly. Set the
                   1562:    <a href="dom.html#document-s-character-encoding">document's character encoding</a> and the encoding used to
                   1563:    convert the input stream to the new encoding, set the <a href="#concept-encoding-confidence" title="concept-encoding-confidence">confidence</a> to
                   1564:    <i>certain</i>, and abort these steps.</li>
                   1565: 
                   1566:    <li>Otherwise, <a href="history.html#navigate">navigate</a> to the document again, with
                   1567:    <a href="history.html#replacement-enabled">replacement enabled</a>, and using the same <a href="history.html#source-browsing-context">source
                   1568:    browsing context</a>, but this time skip the <a href="#encoding-sniffing-algorithm">encoding
                   1569:    sniffing algorithm</a> and instead just set the encoding to the
                   1570:    new encoding and the <a href="#concept-encoding-confidence" title="concept-encoding-confidence">confidence</a> to
                   1571:    <i>certain</i>. Whenever possible, this should be done without
                   1572:    actually contacting the network layer (the bytes should be
                   1573:    re-parsed from memory), even if, e.g., the document is marked as
                   1574:    not being cacheable. If this is not possible and contacting the
                   1575:    network layer would involve repeating a request that uses a method
                   1576:    other than HTTP GET (<a href="infrastructure.html#concept-http-equivalent-get" title="concept-http-equivalent-get">or
                   1577:    equivalent</a> for non-HTTP URLs), then instead set the <a href="#concept-encoding-confidence" title="concept-encoding-confidence">confidence</a> to
                   1578:    <i>certain</i> and ignore the new encoding. The resource will be
                   1579:    misinterpreted. User agents may notify the user of the situation,
                   1580:    to aid in application development.</li>
                   1581: 
                   1582:   </ol><h4 id="parse-state"><span class="secno">9.2.3 </span>Parse state</h4>
                   1583: 
                   1584:   <h5 id="the-insertion-mode"><span class="secno">9.2.3.1 </span>The insertion mode</h5>
                   1585: 
                   1586:   <p>The <dfn id="insertion-mode">insertion mode</dfn> is a state variable that controls
                   1587:   the primary operation of the tree construction stage.</p>
                   1588: 
                   1589:   <p>Initially, the <a href="#insertion-mode">insertion mode</a> is "<a href="#the-initial-insertion-mode" title="insertion mode: initial">initial</a>". It can change to
                   1590:   "<a href="#the-before-html-insertion-mode" title="insertion mode: before html">before html</a>",
                   1591:   "<a href="#the-before-head-insertion-mode" title="insertion mode: before head">before head</a>",
                   1592:   "<a href="#parsing-main-inhead" title="insertion mode: in head">in head</a>", "<a href="#parsing-main-inheadnoscript" title="insertion mode: in head noscript">in head noscript</a>",
1.91      mike     1593:   "<a href="#the-after-head-insertion-mode" title="insertion mode: after head">after head</a>", "<a href="#parsing-main-inbody" title="insertion mode: in body">in body</a>", "<a href="#parsing-main-incdata" title="insertion mode: in RAWTEXT/RCDATA">in RAWTEXT/RCDATA</a>",
1.1       mike     1594:   "<a href="#parsing-main-intable" title="insertion mode: in table">in table</a>", "<a href="#parsing-main-intabletext" title="insertion mode: in table text">in table text</a>", "<a href="#parsing-main-incaption" title="insertion mode: in caption">in caption</a>", "<a href="#parsing-main-incolgroup" title="insertion mode: in column group">in column group</a>",
                   1595:   "<a href="#parsing-main-intbody" title="insertion mode: in table body">in table body</a>",
                   1596:   "<a href="#parsing-main-intr" title="insertion mode: in row">in row</a>", "<a href="#parsing-main-intd" title="insertion mode: in cell">in cell</a>", "<a href="#parsing-main-inselect" title="insertion mode: in select">in select</a>", "<a href="#parsing-main-inselectintable" title="insertion mode: in select in table">in select in
                   1597:   table</a>", "<a href="#parsing-main-inforeign" title="insertion mode: in foreign content">in
                   1598:   foreign content</a>", "<a href="#parsing-main-afterbody" title="insertion mode: after
                   1599:   body">after body</a>", "<a href="#parsing-main-inframeset" title="insertion mode: in
                   1600:   frameset">in frameset</a>", "<a href="#parsing-main-afterframeset" title="insertion mode: after
                   1601:   frameset">after frameset</a>", "<a href="#the-after-after-body-insertion-mode" title="insertion mode:
                   1602:   after after body">after after body</a>", and "<a href="#the-after-after-frameset-insertion-mode" title="insertion mode: after after frameset">after after
                   1603:   frameset</a>" during the course of the parsing, as described in
                   1604:   the <a href="#tree-construction">tree construction</a> stage. The insertion mode affects
                   1605:   how tokens are processed and whether CDATA sections are
                   1606:   supported.</p>
                   1607: 
                   1608:   <p>Seven of these modes, namely "<a href="#parsing-main-inhead" title="insertion mode: in
                   1609:   head">in head</a>", "<a href="#parsing-main-inbody" title="insertion mode: in body">in
                   1610:   body</a>", "<a href="#parsing-main-intable" title="insertion mode: in table">in
                   1611:   table</a>", "<a href="#parsing-main-intbody" title="insertion mode: in table body">in table
                   1612:   body</a>", "<a href="#parsing-main-intr" title="insertion mode: in row">in row</a>",
                   1613:   "<a href="#parsing-main-intd" title="insertion mode: in cell">in cell</a>", and "<a href="#parsing-main-inselect" title="insertion mode: in select">in select</a>", are special, in
                   1614:   that the other modes defer to them at various times. When the
                   1615:   algorithm below says that the user agent is to do something
                   1616:   "<dfn id="using-the-rules-for">using the rules for</dfn> the <var title="">m</var> insertion
                   1617:   mode", where <var title="">m</var> is one of these modes, the user
                   1618:   agent must use the rules described under the <var title="">m</var>
                   1619:   <a href="#insertion-mode">insertion mode</a>'s section, but must leave the
                   1620:   <a href="#insertion-mode">insertion mode</a> unchanged unless the rules in <var title="">m</var> themselves switch the <a href="#insertion-mode">insertion mode</a>
                   1621:   to a new value.</p>
                   1622: 
                   1623:   <p>When the insertion mode is switched to "<a href="#parsing-main-incdata" title="insertion
1.91      mike     1624:   mode: in RAWTEXT/RCDATA">in RAWTEXT/RCDATA</a>" or "<a href="#parsing-main-intabletext" title="insertion mode: in table text">in table text</a>", the
1.1       mike     1625:   <dfn id="original-insertion-mode">original insertion mode</dfn> is also set. This is the
                   1626:   insertion mode to which the tree construction stage will return.</p>
                   1627: 
                   1628:   <p>When the insertion mode is switched to "<a href="#parsing-main-inforeign" title="insertion
                   1629:   mode: in foreign content">in foreign content</a>", the
                   1630:   <dfn id="secondary-insertion-mode">secondary insertion mode</dfn> is also set. This secondary mode
                   1631:   is used within the rules for the "<a href="#parsing-main-inforeign" title="insertion mode: in
                   1632:   foreign content">in foreign content</a>" mode to handle HTML
                   1633:   (i.e. not foreign) content.</p>
                   1634: 
                   1635:   <hr><p>When the steps below require the UA to <dfn id="reset-the-insertion-mode-appropriately">reset the insertion
                   1636:   mode appropriately</dfn>, it means the UA must follow these
                   1637:   steps:</p>
                   1638: 
                   1639:   <ol><li>Let <var title="">last</var> be false.</li>
                   1640: 
                   1641:    <li>Let <var title="">node</var> be the last node in the
                   1642:    <a href="#stack-of-open-elements">stack of open elements</a>.</li>
                   1643: 
                   1644:    <li>If <var title="">node</var> is the first node in the stack of
                   1645:    open elements, then set <var title="">last</var> to true and set
                   1646:    <var title="">node</var> to the <var title="">context</var>
                   1647:    element. (<a href="#fragment-case">fragment case</a>)</li>
                   1648: 
                   1649:    <li>If <var title="">node</var> is a <code><a href="forms.html#the-select-element">select</a></code> element,
                   1650:    then switch the <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-inselect" title="insertion mode: in select">in select</a>" and abort these
                   1651:    steps. (<a href="#fragment-case">fragment case</a>)</li>
                   1652: 
                   1653:    <li>If <var title="">node</var> is a <code><a href="tabular-data.html#the-td-element">td</a></code> or
                   1654:    <code><a href="tabular-data.html#the-th-element">th</a></code> element and <var title="">last</var> is false, then
                   1655:    switch the <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-intd" title="insertion
                   1656:    mode: in cell">in cell</a>" and abort these steps.</li>
                   1657: 
                   1658:    <li>If <var title="">node</var> is a <code><a href="tabular-data.html#the-tr-element">tr</a></code> element, then
                   1659:    switch the <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-intr" title="insertion
                   1660:    mode: in row">in row</a>" and abort these steps.</li>
                   1661: 
                   1662:    <li>If <var title="">node</var> is a <code><a href="tabular-data.html#the-tbody-element">tbody</a></code>,
                   1663:    <code><a href="tabular-data.html#the-thead-element">thead</a></code>, or <code><a href="tabular-data.html#the-tfoot-element">tfoot</a></code> element, then switch the
                   1664:    <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-intbody" title="insertion mode: in
                   1665:    table body">in table body</a>" and abort these steps.</li>
                   1666: 
                   1667:    <li>If <var title="">node</var> is a <code><a href="tabular-data.html#the-caption-element">caption</a></code> element,
                   1668:    then switch the <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-incaption" title="insertion mode: in caption">in caption</a>" and abort
                   1669:    these steps.</li>
                   1670: 
                   1671:    <li>If <var title="">node</var> is a <code><a href="tabular-data.html#the-colgroup-element">colgroup</a></code> element,
                   1672:    then switch the <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-incolgroup" title="insertion mode: in column group">in column group</a>" and
                   1673:    abort these steps. (<a href="#fragment-case">fragment case</a>)</li>
                   1674: 
                   1675:    <li>If <var title="">node</var> is a <code><a href="tabular-data.html#the-table-element">table</a></code> element,
                   1676:    then switch the <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-intable" title="insertion mode: in table">in table</a>" and abort these
                   1677:    steps.</li>
                   1678: 
                   1679:    <li>If <var title="">node</var> is an element from the <a href="#mathml-namespace">MathML
                   1680:    namespace</a> or the <a href="#svg-namespace">SVG namespace</a>, then switch the
                   1681:    <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-inforeign" title="insertion mode: in
                   1682:    foreign content">in foreign content</a>", let the
                   1683:    <a href="#secondary-insertion-mode">secondary insertion mode</a> be "<a href="#parsing-main-inbody" title="insertion
                   1684:    mode: in body">in body</a>", and abort these steps.</li>
                   1685: 
                   1686:    <li>If <var title="">node</var> is a <code><a href="semantics.html#the-head-element">head</a></code> element,
                   1687:    then switch the <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-inbody" title="insertion mode: in body">in body</a>" ("<a href="#parsing-main-inbody" title="insertion mode: in body">in body</a>"! <em> not "<a href="#parsing-main-inhead" title="insertion mode: in head">in head</a>"</em>!) and abort
                   1688:    these steps. (<a href="#fragment-case">fragment case</a>)</li> <!-- This is only
                   1689:    here for now in case people think that the spec accidentally
                   1690:    omitted it and try to "fix" it. Note that noscript-in-head is also
                   1691:    handled this way. This is all intentional. The only thing it
                   1692:    doesn't handle is the scripting-disabled fragment parsing case for
                   1693:    a <head> element containing a <noscript> which itself contains
                   1694:    something other than a <link> or a <style> element; you'd expect
                   1695:    that to break out of the <noscript> but it doesn't. This is an edge
                   1696:    case that doesn't affect the spec, since the algorithm for fragment
                   1697:    parsing is only used for innerHTML/outerHTML/insertAdjacentHTML(),
                   1698:    where we know scripting is enabled. (XXX except maybe if innerHTML
                   1699:    is set from another browsing context on a document with designMode
                   1700:    set?) -->
                   1701: 
                   1702:    <li>If <var title="">node</var> is a <code><a href="semantics.html#the-body-element">body</a></code> element,
                   1703:    then switch the <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-inbody" title="insertion mode: in body">in body</a>" and abort these
                   1704:    steps.</li>
                   1705: 
1.5       mike     1706:    <li>If <var title="">node</var> is a <code><a href="obsolete.html#frameset">frameset</a></code> element,
1.1       mike     1707:    then switch the <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-inframeset" title="insertion mode: in frameset">in frameset</a>" and abort
                   1708:    these steps. (<a href="#fragment-case">fragment case</a>)</li>
                   1709: 
                   1710:    <li>If <var title="">node</var> is an <code><a href="semantics.html#the-html-element">html</a></code> element,
                   1711:    then: if the <a href="#head-element-pointer"><code title="">head</code> element
                   1712:    pointer</a> is null, switch the <a href="#insertion-mode">insertion mode</a> to
                   1713:    "<a href="#the-before-head-insertion-mode" title="insertion mode: before head">before head</a>",
                   1714:    otherwise, switch the <a href="#insertion-mode">insertion mode</a> to "<a href="#the-after-head-insertion-mode" title="insertion mode: after head">after head</a>". In either
                   1715:    case, abort these steps. (<a href="#fragment-case">fragment case</a>)</li> <!-- XXX
                   1716:    can the head element pointer ever be non-null when we're going
                   1717:    through these steps? -->
                   1718: 
                   1719:    <li>If <var title="">last</var> is true, then switch the
                   1720:    <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-inbody" title="insertion mode: in
                   1721:    body">in body</a>" and abort these steps. (<a href="#fragment-case">fragment
                   1722:    case</a>)</li>
                   1723: 
                   1724:    <li>Let <var title="">node</var> now be the node before <var title="">node</var> in the <a href="#stack-of-open-elements">stack of open
                   1725:    elements</a>.</li>
                   1726: 
                   1727:    <li>Return to step 3.</li>
                   1728: 
                   1729:   </ol><h5 id="the-stack-of-open-elements"><span class="secno">9.2.3.2 </span>The stack of open elements</h5>
                   1730: 
                   1731:   <p>Initially, the <dfn id="stack-of-open-elements">stack of open elements</dfn> is empty. The
                   1732:   stack grows downwards; the topmost node on the stack is the first
                   1733:   one added to the stack, and the bottommost node of the stack is the
                   1734:   most recently added node in the stack (notwithstanding when the
                   1735:   stack is manipulated in a random access fashion as part of <a href="#adoptionAgency">the handling for misnested tags</a>).</p>
                   1736: 
                   1737:   <p>The "<a href="#the-before-html-insertion-mode" title="insertion mode: before html">before
                   1738:   html</a>" <a href="#insertion-mode">insertion mode</a> creates the
                   1739:   <code><a href="semantics.html#the-html-element">html</a></code> root element node, which is then added to the
                   1740:   stack.</p>
                   1741: 
                   1742:   <p>In the <a href="#fragment-case">fragment case</a>, the <a href="#stack-of-open-elements">stack of open
                   1743:   elements</a> is initialized to contain an <code><a href="semantics.html#the-html-element">html</a></code>
                   1744:   element that is created as part of <a href="#html-fragment-parsing-algorithm" title="html fragment
                   1745:   parsing algorithm">that algorithm</a>. (The <a href="#fragment-case">fragment
                   1746:   case</a> skips the "<a href="#the-before-html-insertion-mode" title="insertion mode: before
                   1747:   html">before html</a>" <a href="#insertion-mode">insertion mode</a>.)</p>
                   1748: 
                   1749:   <p>The <code><a href="semantics.html#the-html-element">html</a></code> node, however it is created, is the topmost
                   1750:   node of the stack. It never gets popped off the stack.</p>
                   1751: 
                   1752:   <p>The <dfn id="current-node">current node</dfn> is the bottommost node in this
                   1753:   stack.</p>
                   1754: 
                   1755:   <p>The <dfn id="current-table">current table</dfn> is the last <code><a href="tabular-data.html#the-table-element">table</a></code>
                   1756:   element in the <a href="#stack-of-open-elements">stack of open elements</a>, if there is
                   1757:   one. If there is no <code><a href="tabular-data.html#the-table-element">table</a></code> element in the <a href="#stack-of-open-elements">stack of
                   1758:   open elements</a> (<a href="#fragment-case">fragment case</a>), then the
                   1759:   <a href="#current-table">current table</a> is the first element in the <a href="#stack-of-open-elements">stack
                   1760:   of open elements</a> (the <code><a href="semantics.html#the-html-element">html</a></code> element).</p>
                   1761: 
                   1762:   <p>Elements in the stack fall into the following categories:</p>
                   1763: 
                   1764:   <dl><dt><dfn id="special">Special</dfn></dt>
                   1765: 
                   1766:    <dd><p>The following HTML elements have varying levels of special
                   1767:    parsing rules: <code><a href="semantics.html#the-address-element">address</a></code>, <code><a href="the-canvas-element.html#the-area-element">area</a></code>,
                   1768:    <code><a href="semantics.html#the-article-element">article</a></code>, <code><a href="semantics.html#the-aside-element">aside</a></code>, <code><a href="semantics.html#the-base-element">base</a></code>,
1.5       mike     1769:    <code><a href="obsolete.html#basefont">basefont</a></code>, <code>bgsound</code>,
1.1       mike     1770:    <code><a href="semantics.html#the-blockquote-element">blockquote</a></code>, <code><a href="semantics.html#the-body-element">body</a></code>, <code><a href="semantics.html#the-br-element">br</a></code>,
1.5       mike     1771:    <code><a href="obsolete.html#center">center</a></code>, <code><a href="tabular-data.html#the-col-element">col</a></code>, <code><a href="tabular-data.html#the-colgroup-element">colgroup</a></code>,
1.86      mike     1772:    <code><a href="interactive-elements.html#the-command">command</a></code>, <!--v2DDATAGRID--><code>datagrid</code>,
                   1773:    <code><a href="semantics.html#the-dd-element">dd</a></code>, <code><a href="interactive-elements.html#the-details-element">details</a></code>, <code><a href="semantics.html#the-dialog-element">dialog</a></code>,
                   1774:    <code><a href="obsolete.html#dir">dir</a></code>, <code><a href="interactive-elements.html#the-div-element">div</a></code>, <code><a href="semantics.html#the-dl-element">dl</a></code>,
                   1775:    <code><a href="semantics.html#the-dt-element">dt</a></code>, <code><a href="embedded-content-0.html#the-embed-element">embed</a></code>, <code><a href="forms.html#the-fieldset-element">fieldset</a></code>,
                   1776:    <code><a href="embedded-content-0.html#the-figure-element">figure</a></code>, <code><a href="semantics.html#the-footer-element">footer</a></code>, <code><a href="forms.html#the-form-element">form</a></code>,
                   1777:    <code><a href="obsolete.html#frame">frame</a></code>, <code><a href="obsolete.html#frameset">frameset</a></code>, <code><a href="semantics.html#the-h1-h2-h3-h4-h5-and-h6-elements">h1</a></code>,
                   1778:    <code><a href="semantics.html#the-h1-h2-h3-h4-h5-and-h6-elements">h2</a></code>, <code><a href="semantics.html#the-h1-h2-h3-h4-h5-and-h6-elements">h3</a></code>, <code><a href="semantics.html#the-h1-h2-h3-h4-h5-and-h6-elements">h4</a></code>, <code><a href="semantics.html#the-h1-h2-h3-h4-h5-and-h6-elements">h5</a></code>,
                   1779:    <code><a href="semantics.html#the-h1-h2-h3-h4-h5-and-h6-elements">h6</a></code>, <code><a href="semantics.html#the-head-element">head</a></code>, <code><a href="semantics.html#the-header-element">header</a></code>,
                   1780:    <code><a href="semantics.html#the-hgroup-element">hgroup</a></code>, <code><a href="semantics.html#the-hr-element">hr</a></code>, <code><a href="embedded-content-0.html#the-iframe-element">iframe</a></code>, <!--
                   1781:    <code>image</code>, (commented out because this isn't an element
                   1782:    that can end up on the stack, so it doesn't matter) -->
                   1783:    <code><a href="embedded-content-0.html#the-img-element">img</a></code>, <code><a href="forms.html#the-input-element">input</a></code>, <code><a href="obsolete.html#isindex-0">isindex</a></code>,
                   1784:    <code><a href="semantics.html#the-li-element">li</a></code>, <code><a href="semantics.html#the-link-element">link</a></code>, <code><a href="obsolete.html#listing">listing</a></code>,
                   1785:    <code><a href="interactive-elements.html#menus">menu</a></code>, <code><a href="semantics.html#meta">meta</a></code>, <code><a href="semantics.html#the-nav-element">nav</a></code>,
                   1786:    <code><a href="obsolete.html#noembed">noembed</a></code>, <code><a href="obsolete.html#noframes">noframes</a></code>, <code><a href="semantics.html#the-noscript-element">noscript</a></code>,
                   1787:    <code><a href="semantics.html#the-ol-element">ol</a></code>, <code><a href="semantics.html#the-p-element">p</a></code>, <code><a href="embedded-content-0.html#the-param-element">param</a></code>,
                   1788:    <code><a href="obsolete.html#plaintext">plaintext</a></code>, <code><a href="semantics.html#the-pre-element">pre</a></code>, <code><a href="semantics.html#script">script</a></code>,
                   1789:    <code><a href="semantics.html#the-section-element">section</a></code>, <code><a href="forms.html#the-select-element">select</a></code>, <code><a href="obsolete.html#spacer">spacer</a></code>,
                   1790:    <code><a href="semantics.html#the-style-element">style</a></code>, <code><a href="tabular-data.html#the-tbody-element">tbody</a></code>, <code><a href="forms.html#the-textarea-element">textarea</a></code>,
                   1791:    <code><a href="tabular-data.html#the-tfoot-element">tfoot</a></code>, <code><a href="tabular-data.html#the-thead-element">thead</a></code>, <code><a href="semantics.html#the-title-element">title</a></code>,
                   1792:    <code><a href="tabular-data.html#the-tr-element">tr</a></code>, <code><a href="semantics.html#the-ul-element">ul</a></code>, and <code>wbr</code>.</p></dd>
1.1       mike     1793: 
                   1794:    <dt><dfn id="scoping">Scoping</dfn></dt>
                   1795:    <dd><p>The following HTML elements introduce new <a href="#has-an-element-in-scope" title="has
                   1796:    an element in scope">scopes</a> for various parts of the
1.5       mike     1797:    parsing: <code><a href="obsolete.html#the-applet-element">applet</a></code>, <code><a href="forms.html#the-button-element">button</a></code>,
                   1798:    <code><a href="tabular-data.html#the-caption-element">caption</a></code>, <code><a href="semantics.html#the-html-element">html</a></code>, <code><a href="obsolete.html#the-marquee-element-0">marquee</a></code>,
1.1       mike     1799:    <code><a href="embedded-content-0.html#the-object-element">object</a></code>, <code><a href="tabular-data.html#the-table-element">table</a></code>, <code><a href="tabular-data.html#the-td-element">td</a></code>,
                   1800:    <code><a href="tabular-data.html#the-th-element">th</a></code>, and SVG's <code>foreignObject</code>.</p></dd>
                   1801: 
                   1802:    <dt><dfn id="formatting">Formatting</dfn></dt>
                   1803:    <dd><p>The following HTML elements are those that end up in the
                   1804:    <a href="#list-of-active-formatting-elements">list of active formatting elements</a>: <code><a href="text-level-semantics.html#the-a-element">a</a></code>,
1.5       mike     1805:    <code><a href="text-level-semantics.html#the-b-element">b</a></code>, <code><a href="obsolete.html#big">big</a></code>, <code><a href="text-level-semantics.html#the-code-element">code</a></code>,
                   1806:    <code><a href="text-level-semantics.html#the-em-element">em</a></code>, <code><a href="obsolete.html#font">font</a></code>, <code><a href="text-level-semantics.html#the-i-element">i</a></code>,
                   1807:    <code>nobr</code>, <code><a href="obsolete.html#s">s</a></code>, <code><a href="text-level-semantics.html#the-small-element">small</a></code>,
                   1808:    <code><a href="obsolete.html#strike">strike</a></code>, <code><a href="text-level-semantics.html#the-strong-element">strong</a></code>, <code><a href="obsolete.html#tt">tt</a></code>, and
                   1809:    <code><a href="obsolete.html#u">u</a></code>.</p></dd>
1.1       mike     1810: 
                   1811:    <dt><dfn id="phrasing">Phrasing</dfn></dt>
                   1812:    <dd><p>All other elements found while parsing an HTML
                   1813:    document.</p></dd>
                   1814: 
                   1815:   </dl><p>The <a href="#stack-of-open-elements">stack of open elements</a> is said to <dfn id="has-an-element-in-scope" title="has an element in scope">have an element in scope</dfn> when
                   1816:   the following algorithm terminates in a match state:</p>
                   1817: 
                   1818:   <ol><li><p>Initialize <var title="">node</var> to be the <a href="#current-node">current
                   1819:    node</a> (the bottommost node of the stack).</p></li>
                   1820: 
                   1821:    <li><p>If <var title="">node</var> is the target node, terminate in
                   1822:    a match state.</p></li>
                   1823: 
                   1824:    <li><p>Otherwise, if <var title="">node</var> is one of the
                   1825:    following elements, terminate in a failure state:</p>
1.5       mike     1826:     <ul class="brief"><li><code><a href="obsolete.html#the-applet-element">applet</a></code> in the HTML namespace</li>
1.1       mike     1827:      <li><code><a href="tabular-data.html#the-caption-element">caption</a></code> in the HTML namespace</li>
                   1828:      <li><code><a href="semantics.html#the-html-element">html</a></code> in the HTML namespace</li> <!-- (This can only happen if the <var title="">node</var> is the topmost node of the <span>stack of open elements</span>, and prevents the next step from being invoked if there are no more elements in the stack.) -->
                   1829:      <li><code><a href="tabular-data.html#the-table-element">table</a></code> in the HTML namespace</li>
                   1830:      <li><code><a href="tabular-data.html#the-td-element">td</a></code> in the HTML namespace</li>
                   1831:      <li><code><a href="tabular-data.html#the-th-element">th</a></code> in the HTML namespace</li>
                   1832:      <li><code><a href="forms.html#the-button-element">button</a></code> in the HTML namespace</li>
1.5       mike     1833:      <li><code><a href="obsolete.html#the-marquee-element-0">marquee</a></code> in the HTML namespace</li>
1.1       mike     1834:      <li><code><a href="embedded-content-0.html#the-object-element">object</a></code> in the HTML namespace</li>
                   1835:      <li><code title="">foreignObject</code> in the SVG namespace</li>
                   1836:     </ul></li>
                   1837: 
                   1838:    <li><p>Otherwise, set <var title="">node</var> to the previous
                   1839:    entry in the <a href="#stack-of-open-elements">stack of open elements</a> and return to step
                   1840:    2. (This will never fail, since the loop will always terminate in
                   1841:    the previous step if the top of the stack &#8212; an
                   1842:    <code><a href="semantics.html#the-html-element">html</a></code> element &#8212; is reached.)</p></li>
                   1843: 
                   1844:   </ol><p>The <a href="#stack-of-open-elements">stack of open elements</a> is said to <dfn id="has-an-element-in-table-scope" title="has an element in table scope">have an element in <em>table
                   1845:   scope</em></dfn> when the following algorithm terminates in a match
                   1846:   state:</p>
                   1847: 
                   1848:   <ol><li><p>Initialize <var title="">node</var> to be the <a href="#current-node">current
                   1849:    node</a> (the bottommost node of the stack).</p></li>
                   1850: 
                   1851:    <li><p>If <var title="">node</var> is the target node, terminate in
                   1852:    a match state.</p></li>
                   1853: 
                   1854:    <li><p>Otherwise, if <var title="">node</var> is one of the
                   1855:    following elements, terminate in a failure state:</p>
                   1856:     <ul class="brief"><li><code><a href="semantics.html#the-html-element">html</a></code> in the HTML namespace</li> <!-- (This can only happen if the <var title="">node</var> is the topmost node of the <span>stack of open elements</span>, and prevents the next step from being invoked if there are no more elements in the stack.) -->
                   1857:      <li><code><a href="tabular-data.html#the-table-element">table</a></code> in the HTML namespace</li>
                   1858:     </ul></li>
                   1859: 
                   1860:    <li><p>Otherwise, set <var title="">node</var> to the previous
                   1861:    entry in the <a href="#stack-of-open-elements">stack of open elements</a> and return to step
                   1862:    2. (This will never fail, since the loop will always terminate in
                   1863:    the previous step if the top of the stack &#8212; an
                   1864:    <code><a href="semantics.html#the-html-element">html</a></code> element &#8212; is reached.)</p></li>
                   1865: 
                   1866:   </ol><p>Nothing happens if at any time any of the elements in the
                   1867:   <a href="#stack-of-open-elements">stack of open elements</a> are moved to a new location in,
                   1868:   or removed from, the <code>Document</code> tree. In particular, the
                   1869:   stack is not changed in this situation. This can cause, amongst
                   1870:   other strange effects, content to be appended to nodes that are no
                   1871:   longer in the DOM.</p>
                   1872: 
                   1873:   <p class="note">In some cases (namely, when <a href="#adoptionAgency">closing misnested formatting elements</a>),
                   1874:   the stack is manipulated in a random-access fashion.</p>
                   1875: 
                   1876: 
                   1877:   <h5 id="the-list-of-active-formatting-elements"><span class="secno">9.2.3.3 </span>The list of active formatting elements</h5>
                   1878: 
                   1879:   <p>Initially, the <dfn id="list-of-active-formatting-elements">list of active formatting elements</dfn> is
                   1880:   empty. It is used to handle mis-nested <a href="#formatting" title="formatting">formatting element tags</a>.</p>
                   1881: 
                   1882:   <p>The list contains elements in the <a href="#formatting">formatting</a>
                   1883:   category, and scope markers. The scope markers are inserted when
1.5       mike     1884:   entering <code><a href="obsolete.html#the-applet-element">applet</a></code> elements, buttons, <code><a href="embedded-content-0.html#the-object-element">object</a></code>
1.1       mike     1885:   elements, marquees, table cells, and table captions, and are used to
1.5       mike     1886:   prevent formatting from "leaking" <em>into</em> <code><a href="obsolete.html#the-applet-element">applet</a></code>
1.1       mike     1887:   elements, buttons, <code><a href="embedded-content-0.html#the-object-element">object</a></code> elements, marquees, and
                   1888:   tables.</p>
                   1889: 
                   1890:   <p class="note">The scope markers are unrelated to the concept of an
                   1891:   element being <a href="#has-an-element-in-scope" title="has an element in scope">in
                   1892:   scope</a>.</p>
                   1893: 
                   1894:   <p>In addition, each element in the <a href="#list-of-active-formatting-elements">list of active formatting
                   1895:   elements</a> is associated with the token for which it was
                   1896:   created, so that further elements can be created for that token if
                   1897:   necessary.</p>
                   1898: 
                   1899:   <p>When the steps below require the UA to <dfn id="reconstruct-the-active-formatting-elements">reconstruct the
                   1900:   active formatting elements</dfn>, the UA must perform the following
                   1901:   steps:</p>
                   1902: 
                   1903:   <ol><li>If there are no entries in the <a href="#list-of-active-formatting-elements">list of active formatting
                   1904:    elements</a>, then there is nothing to reconstruct; stop this
                   1905:    algorithm.</li>
                   1906: 
                   1907:    <li>If the last (most recently added) entry in the <a href="#list-of-active-formatting-elements">list of
                   1908:    active formatting elements</a> is a marker, or if it is an
                   1909:    element that is in the <a href="#stack-of-open-elements">stack of open elements</a>, then
                   1910:    there is nothing to reconstruct; stop this algorithm.</li>
                   1911: 
                   1912:    <li>Let <var title="">entry</var> be the last (most recently added)
                   1913:    element in the <a href="#list-of-active-formatting-elements">list of active formatting
                   1914:    elements</a>.</li>
                   1915: 
                   1916:    <li>If there are no entries before <var title="">entry</var> in the
                   1917:    <a href="#list-of-active-formatting-elements">list of active formatting elements</a>, then jump to step
                   1918:    8.</li>
                   1919: 
                   1920:    <li>Let <var title="">entry</var> be the entry one earlier than
                   1921:    <var title="">entry</var> in the <a href="#list-of-active-formatting-elements">list of active formatting
                   1922:    elements</a>.</li>
                   1923: 
                   1924:    <li>If <var title="">entry</var> is neither a marker nor an element
                   1925:    that is also in the <a href="#stack-of-open-elements">stack of open elements</a>, go to step
                   1926:    4.</li>
                   1927: 
                   1928:    <li>Let <var title="">entry</var> be the element one later than
                   1929:    <var title="">entry</var> in the <a href="#list-of-active-formatting-elements">list of active formatting
                   1930:    elements</a>.</li>
                   1931: 
                   1932:    <li><a href="#create-an-element-for-the-token">Create an element for the token</a> for which the
                   1933:    element <var title="">entry</var> was created, to obtain <var title="">new element</var>.</li>
                   1934: 
                   1935:    <li>Append <var title="">new element</var> to the <a href="#current-node">current
                   1936:    node</a> and push it onto the <a href="#stack-of-open-elements">stack of open
                   1937:    elements</a> so that it is the new <a href="#current-node">current
                   1938:    node</a>.</li>
                   1939: 
                   1940:    <li>Replace the entry for <var title="">entry</var> in the list
                   1941:    with an entry for <var title="">new element</var>.</li>
                   1942: 
                   1943:    <li>If the entry for <var title="">new element</var> in the
                   1944:    <a href="#list-of-active-formatting-elements">list of active formatting elements</a> is not the last
                   1945:    entry in the list, return to step 7.</li>
                   1946: 
                   1947:   </ol><p>This has the effect of reopening all the formatting elements that
                   1948:   were opened in the current body, cell, or caption (whichever is
                   1949:   youngest) that haven't been explicitly closed.</p>
                   1950: 
                   1951:   <p class="note">The way this specification is written, the
                   1952:   <a href="#list-of-active-formatting-elements">list of active formatting elements</a> always consists of
                   1953:   elements in chronological order with the least recently added
                   1954:   element first and the most recently added element last (except for
                   1955:   while steps 8 to 11 of the above algorithm are being executed, of
                   1956:   course).</p>
                   1957: 
                   1958:   <p>When the steps below require the UA to <dfn id="clear-the-list-of-active-formatting-elements-up-to-the-last-marker">clear the list of
                   1959:   active formatting elements up to the last marker</dfn>, the UA must
                   1960:   perform the following steps:</p>
                   1961: 
                   1962:   <ol><li>Let <var title="">entry</var> be the last (most recently added)
                   1963:    entry in the <a href="#list-of-active-formatting-elements">list of active formatting elements</a>.</li>
                   1964: 
                   1965:    <li>Remove <var title="">entry</var> from the <a href="#list-of-active-formatting-elements">list of active
                   1966:    formatting elements</a>.</li>
                   1967: 
                   1968:    <li>If <var title="">entry</var> was a marker, then stop the
                   1969:    algorithm at this point. The list has been cleared up to the last
                   1970:    marker.</li>
                   1971: 
                   1972:    <li>Go to step 1.</li>
                   1973: 
                   1974:   </ol><h5 id="the-element-pointers"><span class="secno">9.2.3.4 </span>The element pointers</h5>
                   1975: 
                   1976:   <p>Initially, the <dfn id="head-element-pointer"><code title="">head</code> element
                   1977:   pointer</dfn> and the <dfn id="form-element-pointer"><code title="">form</code> element
                   1978:   pointer</dfn> are both null.</p>
                   1979: 
                   1980:   <p>Once a <code><a href="semantics.html#the-head-element">head</a></code> element has been parsed (whether
                   1981:   implicitly or explicitly) the <a href="#head-element-pointer"><code title="">head</code>
                   1982:   element pointer</a> gets set to point to this node.</p>
                   1983: 
                   1984:   <p>The <a href="#form-element-pointer"><code title="">form</code> element pointer</a>
                   1985:   points to the last <code><a href="forms.html#the-form-element">form</a></code> element that was opened and
                   1986:   whose end tag has not yet been seen. It is used to make form
                   1987:   controls associate with forms in the face of dramatically bad
                   1988:   markup, for historical reasons.</p>
                   1989: 
                   1990: 
                   1991:   <h5 id="other-parsing-state-flags"><span class="secno">9.2.3.5 </span>Other parsing state flags</h5>
                   1992: 
                   1993:   <p>The <dfn id="scripting-flag">scripting flag</dfn> is set to "enabled" if <a href="browsers.html#concept-n-script" title="concept-n-script">scripting was enabled</a> for the
                   1994:   <code>Document</code> with which the parser is associated when the
                   1995:   parser was created, and "disabled" otherwise.</p>
                   1996: 
                   1997:   <p class="note">The <a href="#scripting-flag">scripting flag</a> can be enabled even
                   1998:   when the parser was originally created for the <a href="#html-fragment-parsing-algorithm">HTML fragment
                   1999:   parsing algorithm</a>, even though <code><a href="semantics.html#script">script</a></code> elements
                   2000:   don't execute in that case.</p>
                   2001: 
                   2002:   <p>The <dfn id="frameset-ok-flag">frameset-ok flag</dfn> is set to "ok" when the parser is
                   2003:   created. It is set to "not ok" after certain tokens are seen.</p>
                   2004: 
                   2005: 
                   2006:   <h4 id="tokenization"><span class="secno">9.2.4 </span><dfn>Tokenization</dfn></h4>
                   2007: 
                   2008:   <p>Implementations must act as if they used the following state
                   2009:   machine to tokenize HTML. The state machine must start in the
                   2010:   <a href="#data-state">data state</a>. Most states consume a single character,
                   2011:   which may have various side-effects, and either switches the state
                   2012:   machine to a new state to <em>reconsume</em> the same character, or
                   2013:   switches it to a new state (to consume the next character), or
                   2014:   repeats the same state (to consume the next character). Some states
                   2015:   have more complicated behavior and can consume several characters
                   2016:   before switching to another state.</p>
                   2017: 
                   2018:   <p>The exact behavior of certain states depends on a <dfn id="content-model-flag">content
                   2019:   model flag</dfn> that is set after certain tokens are emitted. The
1.91      mike     2020:   flag has several states: <i title="">PCDATA</i>, <i title="">RCDATA</i>, <i title="">RAWTEXT</i>, and <i title="">PLAINTEXT</i>. Initially, it must be in the PCDATA
                   2021:   state. In the RCDATA and RAWTEXT states, a further <dfn id="escape-flag">escape
1.1       mike     2022:   flag</dfn> is used to control the behavior of the tokenizer. It is
                   2023:   either true or false, and initially must be set to the false
                   2024:   state. The <a href="#insertion-mode">insertion mode</a> and the <a href="#stack-of-open-elements">stack of open
                   2025:   elements</a> also affects tokenization.</p>
                   2026: 
                   2027:   <p>The output of the tokenization step is a series of zero or more
                   2028:   of the following tokens: DOCTYPE, start tag, end tag, comment,
                   2029:   character, end-of-file. DOCTYPE tokens have a name, a public
                   2030:   identifier, a system identifier, and a <i>force-quirks
                   2031:   flag</i>. When a DOCTYPE token is created, its name, public
                   2032:   identifier, and system identifier must be marked as missing (which
                   2033:   is a distinct state from the empty string), and the <i>force-quirks
                   2034:   flag</i> must be set to <i>off</i> (its other state is
                   2035:   <i>on</i>). Start and end tag tokens have a tag name, a
                   2036:   <i>self-closing flag</i>, and a list of attributes, each of which
                   2037:   has a name and a value. When a start or end tag token is created,
                   2038:   its <i>self-closing flag</i> must be unset (its other state is that
                   2039:   it be set), and its attributes list must be empty. Comment and
                   2040:   character tokens have data.</p>
                   2041: 
                   2042:   <p>When a token is emitted, it must immediately be handled by the
                   2043:   <a href="#tree-construction">tree construction</a> stage. The tree construction stage
                   2044:   can affect the state of the <a href="#content-model-flag">content model flag</a>, and can
                   2045:   insert additional characters into the stream. (For example, the
                   2046:   <code><a href="semantics.html#script">script</a></code> element can result in scripts executing and
                   2047:   using the <a href="dom.html#dynamic-markup-insertion">dynamic markup insertion</a> APIs to insert
                   2048:   characters into the stream being tokenized.)</p>
                   2049: 
                   2050:   <p>When a start tag token is emitted with its <i>self-closing
                   2051:   flag</i> set, if the flag is not <dfn id="acknowledge-self-closing-flag" title="acknowledge
                   2052:   self-closing flag">acknowledged</dfn> when it is processed by the
                   2053:   tree construction stage, that is a <a href="#parse-error">parse error</a>.</p>
                   2054: 
                   2055:   <p>When an end tag token is emitted, the <a href="#content-model-flag">content model
                   2056:   flag</a> must be switched to the PCDATA state.</p>
                   2057: 
                   2058:   <p>When an end tag token is emitted with attributes, that is a
                   2059:   <a href="#parse-error">parse error</a>.</p>
                   2060: 
                   2061:   <p>When an end tag token is emitted with its <i>self-closing
                   2062:   flag</i> set, that is a <a href="#parse-error">parse error</a>.</p>
                   2063: 
                   2064:   <p>Before each step of the tokenizer, the user agent must first
                   2065:   check the <a href="#parser-pause-flag">parser pause flag</a>. If it is true, then the
                   2066:   tokenizer must abort the processing of any nested invocations of the
                   2067:   tokenizer, yielding control back to the caller. If it is false, then
                   2068:   the user agent may then check to see if either one of the scripts in
                   2069:   the <a href="semantics.html#list-of-scripts-that-will-execute-as-soon-as-possible">list of scripts that will execute as soon as
                   2070:   possible</a> or the first script in the <a href="semantics.html#list-of-scripts-that-will-execute-asynchronously">list of scripts
                   2071:   that will execute asynchronously</a>, has <a href="semantics.html#completed-loading">completed
                   2072:   loading</a>. If one has, then it must be <a href="semantics.html#executing-a-script-block" title="executing a
                   2073:   script block">executed</a> and removed from its list.</p>
                   2074: 
                   2075:   <p>The tokenizer state machine consists of the states defined in the
                   2076:   following subsections.</p>
                   2077: 
                   2078:   <!-- XXX should go through these reordering the entries so that
                   2079:   they're in some consistent order, like, by Unicode, errors last, or
                   2080:   something -->
                   2081: 
                   2082:   <h5 id="data-state"><span class="secno">9.2.4.1 </span><dfn>Data state</dfn></h5>
                   2083: 
                   2084:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   2085: 
                   2086:   <dl class="switch"><dt>U+0026 AMPERSAND (&amp;)</dt>
                   2087:    <dd>When the <a href="#content-model-flag">content model flag</a> is set to one of the
                   2088:    PCDATA or RCDATA states and the <a href="#escape-flag">escape flag</a> is
                   2089:    false: switch to the <a href="#character-reference-data-state">character reference data
1.56      mike     2090:    state</a>.</dd>
                   2091:    <dd>Otherwise: treat it as per the "anything else" entry
                   2092:    below.</dd>
1.1       mike     2093: 
                   2094:    <dt>U+002D HYPHEN-MINUS (-)</dt>
                   2095:    <dd>
                   2096: 
                   2097:     <p>If the <a href="#content-model-flag">content model flag</a> is set to either the
1.91      mike     2098:     RCDATA state or the RAWTEXT state, and the <a href="#escape-flag">escape flag</a>
1.1       mike     2099:     is false, and there are at least three characters before this
                   2100:     one in the input stream, and the last four characters in the
                   2101:     input stream, including this one, are U+003C LESS-THAN SIGN,
                   2102:     U+0021 EXCLAMATION MARK, U+002D HYPHEN-MINUS, and U+002D
                   2103:     HYPHEN-MINUS ("&lt;!--"), then set the <a href="#escape-flag">escape flag</a>
                   2104:     to true.</p>
                   2105: 
                   2106:     <p>In any case, emit the input character as a character
                   2107:     token. Stay in the <a href="#data-state">data state</a>.</p>
                   2108: 
                   2109:    </dd>
                   2110: 
                   2111:    <dt>U+003C LESS-THAN SIGN (&lt;)</dt>
                   2112:    <dd>When the <a href="#content-model-flag">content model flag</a> is set to the PCDATA
                   2113:    state: switch to the <a href="#tag-open-state">tag open state</a>.</dd>
                   2114:    <dd>When the <a href="#content-model-flag">content model flag</a> is set to either the
1.91      mike     2115:    RCDATA state or the RAWTEXT state, and the <a href="#escape-flag">escape flag</a>
1.1       mike     2116:    is false: switch to the <a href="#tag-open-state">tag open state</a>.</dd>
                   2117:    <dd>Otherwise: treat it as per the "anything else" entry
                   2118:    below.</dd>
                   2119: 
                   2120:    <dt>U+003E GREATER-THAN SIGN (&gt;)</dt>
                   2121:    <dd>
                   2122: 
                   2123:     <p>If the <a href="#content-model-flag">content model flag</a> is set to either the
1.91      mike     2124:     RCDATA state or the RAWTEXT state, and the <a href="#escape-flag">escape
1.1       mike     2125:     flag</a> is true, and the last three characters in the input
                   2126:     stream including this one are U+002D HYPHEN-MINUS, U+002D
                   2127:     HYPHEN-MINUS, U+003E GREATER-THAN SIGN ("--&gt;"), set the
                   2128:     <a href="#escape-flag">escape flag</a> to false.</p> <!-- no need to check
                   2129:     that there are enough characters, since you can only run into
                   2130:     this if the flag is true in the first place, which requires four
                   2131:     characters. -->
                   2132: 
                   2133:     <p>In any case, emit the input character as a character
                   2134:     token. Stay in the <a href="#data-state">data state</a>.</p>
                   2135: 
                   2136:    </dd>
                   2137: 
                   2138:    <dt>EOF</dt>
                   2139:    <dd>Emit an end-of-file token.</dd>
                   2140: 
                   2141:    <dt>Anything else</dt>
                   2142:    <dd>Emit the input character as a character token. Stay in the
                   2143:    <a href="#data-state">data state</a>.</dd>
                   2144: 
                   2145:   </dl><h5 id="character-reference-data-state"><span class="secno">9.2.4.2 </span><dfn>Character reference data state</dfn></h5>
                   2146: 
                   2147:   <p><i>(This cannot happen if the <a href="#content-model-flag">content model flag</a>
1.91      mike     2148:   is set to the RAWTEXT state.)</i></p>
1.1       mike     2149: 
                   2150:   <p>Attempt to <a href="#consume-a-character-reference">consume a character reference</a>, with no
                   2151:   <a href="#additional-allowed-character">additional allowed character</a>.</p>
                   2152: 
                   2153:   <p>If nothing is returned, emit a U+0026 AMPERSAND character
                   2154:   token.</p>
                   2155: 
                   2156:   <p>Otherwise, emit the character token that was returned.</p>
                   2157: 
                   2158:   <p>Finally, switch to the <a href="#data-state">data state</a>.</p>
                   2159: 
                   2160: 
                   2161:   <h5 id="tag-open-state"><span class="secno">9.2.4.3 </span><dfn>Tag open state</dfn></h5>
                   2162: 
                   2163:   <p>The behavior of this state depends on the <a href="#content-model-flag">content model
                   2164:   flag</a>.</p>
                   2165: 
                   2166:   <dl><dt>If the <a href="#content-model-flag">content model flag</a> is set to the RCDATA
1.91      mike     2167:    or RAWTEXT states</dt>
1.1       mike     2168: 
                   2169:    <dd>
                   2170: 
                   2171:     <p>Consume the <a href="#next-input-character">next input character</a>. If it is a
                   2172:     U+002F SOLIDUS (/) character, switch to the <a href="#close-tag-open-state">close tag open
                   2173:     state</a>. Otherwise, emit a U+003C LESS-THAN SIGN character
                   2174:     token and reconsume the <a href="#current-input-character">current input character</a> in the
                   2175:     <a href="#data-state">data state</a>.</p>
                   2176: 
                   2177:    </dd>
                   2178: 
                   2179:    <dt>If the <a href="#content-model-flag">content model flag</a> is set to the PCDATA
                   2180:    state</dt>
                   2181: 
                   2182:    <dd>
                   2183: 
                   2184:     <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   2185: 
                   2186:     <dl class="switch"><dt>U+0021 EXCLAMATION MARK (!)</dt>
                   2187:      <dd>Switch to the <a href="#markup-declaration-open-state">markup declaration open state</a>.</dd>
                   2188: 
                   2189:      <dt>U+002F SOLIDUS (/)</dt>
                   2190:      <dd>Switch to the <a href="#close-tag-open-state">close tag open state</a>.</dd>
                   2191: 
                   2192:      <dt>U+0041 LATIN CAPITAL LETTER A through to U+005A LATIN CAPITAL LETTER Z</dt>
                   2193:      <dd>Create a new start tag token, set its tag name to the
                   2194:      lowercase version of the input character (add 0x0020 to the
                   2195:      character's code point), then switch to the <a href="#tag-name-state">tag name
                   2196:      state</a>. (Don't emit the token yet; further details will
                   2197:      be filled in before it is emitted.)</dd>
                   2198: 
                   2199:      <dt>U+0061 LATIN SMALL LETTER A through to U+007A LATIN SMALL LETTER Z</dt>
                   2200:      <dd>Create a new start tag token, set its tag name to the input
                   2201:      character, then switch to the <a href="#tag-name-state">tag name
                   2202:      state</a>. (Don't emit the token yet; further details will
                   2203:      be filled in before it is emitted.)</dd>
                   2204: 
                   2205:      <dt>U+003E GREATER-THAN SIGN (&gt;)</dt>
                   2206:      <dd><a href="#parse-error">Parse error</a>. Emit a U+003C LESS-THAN SIGN
                   2207:      character token and a U+003E GREATER-THAN SIGN character
                   2208:      token. Switch to the <a href="#data-state">data state</a>.</dd>
                   2209: 
                   2210:      <dt>U+003F QUESTION MARK (?)</dt>
                   2211:      <dd><a href="#parse-error">Parse error</a>. Switch to the <a href="#bogus-comment-state">bogus
                   2212:      comment state</a>.</dd>
                   2213: 
                   2214:      <dt>Anything else</dt>
                   2215:      <dd><a href="#parse-error">Parse error</a>. Emit a U+003C LESS-THAN SIGN
                   2216:      character token and reconsume the <a href="#current-input-character">current input character</a> in the
                   2217:      <a href="#data-state">data state</a>.</dd>
                   2218: 
                   2219:     </dl></dd>
                   2220: 
                   2221:   </dl><h5 id="close-tag-open-state"><span class="secno">9.2.4.4 </span><dfn>Close tag open state</dfn></h5>
                   2222: 
                   2223:   <p>If the <a href="#content-model-flag">content model flag</a> is set to the RCDATA or
1.91      mike     2224:   RAWTEXT states but no start tag token has ever been emitted by this
1.1       mike     2225:   instance of the tokenizer (<a href="#fragment-case">fragment case</a>), or, if the
1.91      mike     2226:   <a href="#content-model-flag">content model flag</a> is set to the RCDATA or RAWTEXT states
1.1       mike     2227:   and the next few characters do not match the tag name of the last
                   2228:   start tag token emitted (compared in an <a href="infrastructure.html#ascii-case-insensitive">ASCII
                   2229:   case-insensitive</a> manner), or if they do but they are not
                   2230:   immediately followed by one of the following characters:</p>
                   2231: 
                   2232:   <ul class="brief"><li>U+0009 CHARACTER TABULATION</li>
                   2233:    <li>U+000A LINE FEED (LF)</li>
                   2234:    <li>U+000C FORM FEED (FF)</li>
                   2235:    <!--<li>U+000D CARRIAGE RETURN (CR)</li>-->
                   2236:    <li>U+0020 SPACE</li>
                   2237:    <li>U+003E GREATER-THAN SIGN (&gt;)</li>
                   2238:    <li>U+002F SOLIDUS (/)</li>
                   2239:    <li>EOF</li>
                   2240:   </ul><p>...then emit a U+003C LESS-THAN SIGN character token, a U+002F
                   2241:   SOLIDUS character token, and switch to the <a href="#data-state">data state</a>
                   2242:   to process the <a href="#next-input-character">next input character</a>.</p>
                   2243: 
                   2244:   <p>Otherwise, if the <a href="#content-model-flag">content model flag</a> is set to the
                   2245:   PCDATA state, or if the next few characters <em>do</em> match that tag
                   2246:   name, consume the <a href="#next-input-character">next input character</a>:</p>
                   2247: 
                   2248:   <dl class="switch"><dt>U+0041 LATIN CAPITAL LETTER A through to U+005A LATIN CAPITAL LETTER Z</dt>
                   2249:    <dd>Create a new end tag token, set its tag name to the lowercase
                   2250:    version of the input character (add 0x0020 to the character's
                   2251:    code point), then switch to the <a href="#tag-name-state">tag name
                   2252:    state</a>. (Don't emit the token yet; further details will be
                   2253:    filled in before it is emitted.)</dd>
                   2254: 
                   2255:    <dt>U+0061 LATIN SMALL LETTER A through to U+007A LATIN SMALL LETTER Z</dt>
                   2256:    <dd>Create a new end tag token, set its tag name to the input
                   2257:    character, then switch to the <a href="#tag-name-state">tag name state</a>. (Don't
                   2258:    emit the token yet; further details will be filled in before it
                   2259:    is emitted.)</dd>
                   2260: 
                   2261:    <dt>U+003E GREATER-THAN SIGN (&gt;)</dt>
                   2262:    <dd><a href="#parse-error">Parse error</a>. Switch to the <a href="#data-state">data
                   2263:    state</a>.</dd>
                   2264: 
                   2265:    <dt>EOF</dt>
                   2266:    <dd><a href="#parse-error">Parse error</a>. Emit a U+003C LESS-THAN SIGN
                   2267:    character token and a U+002F SOLIDUS character token. Reconsume
                   2268:    the EOF character in the <a href="#data-state">data state</a>.</dd>
                   2269: 
                   2270:    <dt>Anything else</dt>
                   2271:    <dd><a href="#parse-error">Parse error</a>. Switch to the <a href="#bogus-comment-state">bogus
                   2272:    comment state</a>.</dd>
                   2273: 
                   2274:   </dl><h5 id="tag-name-state"><span class="secno">9.2.4.5 </span><dfn>Tag name state</dfn></h5>
                   2275: 
                   2276:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   2277: 
                   2278:   <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
                   2279:    <dt>U+000A LINE FEED (LF)</dt>
                   2280:    <dt>U+000C FORM FEED (FF)</dt>
                   2281:    <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
                   2282:    <dt>U+0020 SPACE</dt>
                   2283:    <dd>Switch to the <a href="#before-attribute-name-state">before attribute name state</a>.</dd>
                   2284: 
                   2285:    <dt>U+002F SOLIDUS (/)</dt>
                   2286:    <dd>Switch to the <a href="#self-closing-start-tag-state">self-closing start tag state</a>.</dd>
                   2287: 
                   2288:    <dt>U+003E GREATER-THAN SIGN (&gt;)</dt>
                   2289:    <dd>Emit the current tag token. Switch to the <a href="#data-state">data
                   2290:    state</a>.</dd>
                   2291: 
                   2292:    <dt>U+0041 LATIN CAPITAL LETTER A through to U+005A LATIN CAPITAL LETTER Z</dt>
                   2293:    <dd>Append the lowercase version of the <a href="#current-input-character">current input character</a>
                   2294:    (add 0x0020 to the character's code point) to the current tag
                   2295:    token's tag name. Stay in the <a href="#tag-name-state">tag name state</a>.</dd>
                   2296: 
                   2297:    <dt>EOF</dt>
                   2298:    <dd><a href="#parse-error">Parse error</a>. Reconsume the EOF character in the
                   2299:    <a href="#data-state">data state</a>.</dd>
                   2300: 
                   2301:    <dt>Anything else</dt>
                   2302:    <dd>Append the <a href="#current-input-character">current input character</a> to the current tag token's
                   2303:    tag name. Stay in the <a href="#tag-name-state">tag name state</a>.</dd>
                   2304: 
                   2305:   </dl><h5 id="before-attribute-name-state"><span class="secno">9.2.4.6 </span><dfn>Before attribute name state</dfn></h5>
                   2306: 
                   2307:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   2308: 
                   2309:   <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
                   2310:    <dt>U+000A LINE FEED (LF)</dt>
                   2311:    <dt>U+000C FORM FEED (FF)</dt>
                   2312:    <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
                   2313:    <dt>U+0020 SPACE</dt>
                   2314:    <dd>Stay in the <a href="#before-attribute-name-state">before attribute name state</a>.</dd>
                   2315: 
                   2316:    <dt>U+002F SOLIDUS (/)</dt>
                   2317:    <dd>Switch to the <a href="#self-closing-start-tag-state">self-closing start tag state</a>.</dd>
                   2318: 
                   2319:    <dt>U+003E GREATER-THAN SIGN (&gt;)</dt>
                   2320:    <dd>Emit the current tag token. Switch to the <a href="#data-state">data
                   2321:    state</a>.</dd>
                   2322: 
                   2323:    <dt>U+0041 LATIN CAPITAL LETTER A through to U+005A LATIN CAPITAL LETTER Z</dt>
                   2324:    <dd>Start a new attribute in the current tag token. Set that
                   2325:    attribute's name to the lowercase version of the <a href="#current-input-character">current input
                   2326:    character</a> (add 0x0020 to the character's code point), and its
                   2327:    value to the empty string. Switch to the <a href="#attribute-name-state">attribute name
                   2328:    state</a>.</dd>
                   2329: 
                   2330:    <dt>U+0022 QUOTATION MARK (")</dt>
                   2331:    <dt>U+0027 APOSTROPHE (')</dt>
                   2332:    <dt>U+003C LESS-THAN SIGN (&lt;)</dt>
                   2333:    <dt>U+003D EQUALS SIGN (=)</dt>
                   2334:    <dd><a href="#parse-error">Parse error</a>. Treat it as per the "anything else"
                   2335:    entry below.</dd>
                   2336: 
                   2337:    <dt>EOF</dt>
                   2338:    <dd><a href="#parse-error">Parse error</a>. Reconsume the EOF character in the
                   2339:    <a href="#data-state">data state</a>.</dd>
                   2340: 
                   2341:    <dt>Anything else</dt>
                   2342:    <dd>Start a new attribute in the current tag token. Set that
                   2343:    attribute's name to the <a href="#current-input-character">current input character</a>, and its value to
                   2344:    the empty string. Switch to the <a href="#attribute-name-state">attribute name
                   2345:    state</a>.</dd>
                   2346: 
                   2347:   </dl><h5 id="attribute-name-state"><span class="secno">9.2.4.7 </span><dfn>Attribute name state</dfn></h5>
                   2348: 
                   2349:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   2350: 
                   2351:   <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
                   2352:    <dt>U+000A LINE FEED (LF)</dt>
                   2353:    <dt>U+000C FORM FEED (FF)</dt>
                   2354:    <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
                   2355:    <dt>U+0020 SPACE</dt>
                   2356:    <dd>Switch to the <a href="#after-attribute-name-state">after attribute name state</a>.</dd>
                   2357: 
                   2358:    <dt>U+002F SOLIDUS (/)</dt>
                   2359:    <dd>Switch to the <a href="#self-closing-start-tag-state">self-closing start tag state</a>.</dd>
                   2360: 
                   2361:    <dt>U+003D EQUALS SIGN (=)</dt>
                   2362:    <dd>Switch to the <a href="#before-attribute-value-state">before attribute value state</a>.</dd>
                   2363: 
                   2364:    <dt>U+003E GREATER-THAN SIGN (&gt;)</dt>
                   2365:    <dd>Emit the current tag token. Switch to the <a href="#data-state">data
                   2366:    state</a>.</dd>
                   2367: 
                   2368:    <dt>U+0041 LATIN CAPITAL LETTER A through to U+005A LATIN CAPITAL LETTER Z</dt>
                   2369:    <dd>Append the lowercase version of the <a href="#current-input-character">current input character</a>
                   2370:    (add 0x0020 to the character's code point) to the current
                   2371:    attribute's name. Stay in the <a href="#attribute-name-state">attribute name
                   2372:    state</a>.</dd>
                   2373: 
                   2374:    <dt>U+0022 QUOTATION MARK (")</dt>
                   2375:    <dt>U+0027 APOSTROPHE (')</dt>
                   2376:    <dt>U+003C LESS-THAN SIGN (&lt;)</dt>
                   2377:    <dd><a href="#parse-error">Parse error</a>. Treat it as per the "anything else"
                   2378:    entry below.</dd>
                   2379: 
                   2380:    <dt>EOF</dt>
                   2381:    <dd><a href="#parse-error">Parse error</a>. Reconsume the EOF character in the
                   2382:    <a href="#data-state">data state</a>.</dd>
                   2383: 
                   2384:    <dt>Anything else</dt>
                   2385:    <dd>Append the <a href="#current-input-character">current input character</a> to the current attribute's
                   2386:    name. Stay in the <a href="#attribute-name-state">attribute name state</a>.</dd>
                   2387: 
                   2388:   </dl><p>When the user agent leaves the attribute name state (and before
                   2389:   emitting the tag token, if appropriate), the complete attribute's
                   2390:   name must be compared to the other attributes on the same token;
                   2391:   if there is already an attribute on the token with the exact same
                   2392:   name, then this is a <a href="#parse-error">parse error</a> and the new
                   2393:   attribute must be dropped, along with the value that gets
                   2394:   associated with it (if any).</p>
                   2395: 
                   2396: 
                   2397:   <h5 id="after-attribute-name-state"><span class="secno">9.2.4.8 </span><dfn>After attribute name state</dfn></h5>
                   2398: 
                   2399:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   2400: 
                   2401:   <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
                   2402:    <dt>U+000A LINE FEED (LF)</dt>
                   2403:    <dt>U+000C FORM FEED (FF)</dt>
                   2404:    <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
                   2405:    <dt>U+0020 SPACE</dt>
                   2406:    <dd>Stay in the <a href="#after-attribute-name-state">after attribute name state</a>.</dd>
                   2407: 
                   2408:    <dt>U+002F SOLIDUS (/)</dt>
                   2409:    <dd>Switch to the <a href="#self-closing-start-tag-state">self-closing start tag state</a>.</dd>
                   2410: 
                   2411:    <dt>U+003D EQUALS SIGN (=)</dt>
                   2412:    <dd>Switch to the <a href="#before-attribute-value-state">before attribute value state</a>.</dd>
                   2413: 
                   2414:    <dt>U+003E GREATER-THAN SIGN (&gt;)</dt>
                   2415:    <dd>Emit the current tag token. Switch to the <a href="#data-state">data
                   2416:    state</a>.</dd>
                   2417: 
                   2418:    <dt>U+0041 LATIN CAPITAL LETTER A through to U+005A LATIN CAPITAL LETTER Z</dt>
                   2419:    <dd>Start a new attribute in the current tag token. Set that
                   2420:    attribute's name to the lowercase version of the <a href="#current-input-character">current input character</a>
                   2421:    (add 0x0020 to the character's code point), and its value to
                   2422:    the empty string. Switch to the <a href="#attribute-name-state">attribute name
                   2423:    state</a>.</dd>
                   2424: 
                   2425:    <dt>U+0022 QUOTATION MARK (")</dt>
                   2426:    <dt>U+0027 APOSTROPHE (')</dt>
                   2427:    <dt>U+003C LESS-THAN SIGN (&lt;)</dt>
                   2428:    <dd><a href="#parse-error">Parse error</a>. Treat it as per the "anything else"
                   2429:    entry below.</dd>
                   2430: 
                   2431:    <dt>EOF</dt>
                   2432:    <dd><a href="#parse-error">Parse error</a>. Reconsume the EOF character in the
                   2433:    <a href="#data-state">data state</a>.</dd>
                   2434: 
                   2435:    <dt>Anything else</dt>
                   2436:    <dd>Start a new attribute in the current tag token. Set that
                   2437:    attribute's name to the <a href="#current-input-character">current input character</a>, and its value to
                   2438:    the empty string. Switch to the <a href="#attribute-name-state">attribute name
                   2439:    state</a>.</dd>
                   2440: 
                   2441:   </dl><h5 id="before-attribute-value-state"><span class="secno">9.2.4.9 </span><dfn>Before attribute value state</dfn></h5>
                   2442: 
                   2443:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   2444: 
                   2445:   <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
                   2446:    <dt>U+000A LINE FEED (LF)</dt>
                   2447:    <dt>U+000C FORM FEED (FF)</dt>
                   2448:    <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
                   2449:    <dt>U+0020 SPACE</dt>
                   2450:    <dd>Stay in the <a href="#before-attribute-value-state">before attribute value state</a>.</dd>
                   2451: 
                   2452:    <dt>U+0022 QUOTATION MARK (")</dt>
                   2453:    <dd>Switch to the <a href="#attribute-value-double-quoted-state">attribute value (double-quoted) state</a>.</dd>
                   2454: 
                   2455:    <dt>U+0026 AMPERSAND (&amp;)</dt>
                   2456:    <dd>Switch to the <a href="#attribute-value-unquoted-state">attribute value (unquoted) state</a>
                   2457:    and reconsume this input character.</dd>
                   2458: 
                   2459:    <dt>U+0027 APOSTROPHE (')</dt>
                   2460:    <dd>Switch to the <a href="#attribute-value-single-quoted-state">attribute value (single-quoted) state</a>.</dd>
                   2461: 
                   2462:    <dt>U+003E GREATER-THAN SIGN (&gt;)</dt>
                   2463:    <dd><a href="#parse-error">Parse error</a>. Emit the current tag token. Switch to
                   2464:    the <a href="#data-state">data state</a>.</dd>
                   2465: 
                   2466:    <dt>U+003C LESS-THAN SIGN (&lt;)</dt>
                   2467:    <dt>U+003D EQUALS SIGN (=)</dt>
                   2468:    <dd><a href="#parse-error">Parse error</a>. Treat it as per the "anything else"
                   2469:    entry below.</dd>
                   2470: 
                   2471:    <dt>EOF</dt>
                   2472:    <dd><a href="#parse-error">Parse error</a>. Reconsume the EOF character in the
                   2473:    <a href="#data-state">data state</a>.</dd>
                   2474: 
                   2475:    <dt>Anything else</dt>
                   2476:    <dd>Append the <a href="#current-input-character">current input character</a> to the current
                   2477:    attribute's value. Switch to the <a href="#attribute-value-unquoted-state">attribute value (unquoted)
                   2478:    state</a>.</dd>
                   2479: 
                   2480:   </dl><h5 id="attribute-value-double-quoted-state"><span class="secno">9.2.4.10 </span><dfn>Attribute value (double-quoted) state</dfn></h5>
                   2481: 
                   2482:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   2483: 
                   2484:   <dl class="switch"><dt>U+0022 QUOTATION MARK (")</dt>
                   2485:    <dd>Switch to the <a href="#after-attribute-value-quoted-state">after attribute value (quoted)
                   2486:    state</a>.</dd>
                   2487: 
                   2488:    <dt>U+0026 AMPERSAND (&amp;)</dt>
                   2489:    <dd>Switch to the <a href="#character-reference-in-attribute-value-state">character reference in attribute value
                   2490:    state</a>, with the <a href="#additional-allowed-character">additional allowed character</a>
                   2491:    being U+0022 QUOTATION MARK (").</dd>
                   2492: 
                   2493:    <dt>EOF</dt>
                   2494:    <dd><a href="#parse-error">Parse error</a>. Reconsume the EOF character in the
                   2495:    <a href="#data-state">data state</a>.</dd>
                   2496: 
                   2497:    <dt>Anything else</dt>
                   2498:    <dd>Append the <a href="#current-input-character">current input character</a> to the current attribute's
                   2499:    value. Stay in the <a href="#attribute-value-double-quoted-state">attribute value (double-quoted)
                   2500:    state</a>.</dd>
                   2501: 
                   2502:   </dl><h5 id="attribute-value-single-quoted-state"><span class="secno">9.2.4.11 </span><dfn>Attribute value (single-quoted) state</dfn></h5>
                   2503: 
                   2504:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   2505: 
                   2506:   <dl class="switch"><dt>U+0027 APOSTROPHE (')</dt>
                   2507:    <dd>Switch to the <a href="#after-attribute-value-quoted-state">after attribute value (quoted)
                   2508:    state</a>.</dd>
                   2509: 
                   2510:    <dt>U+0026 AMPERSAND (&amp;)</dt>
                   2511:    <dd>Switch to the <a href="#character-reference-in-attribute-value-state">character reference in attribute value
                   2512:    state</a>, with the <a href="#additional-allowed-character">additional allowed character</a>
                   2513:    being U+0027 APOSTROPHE (').</dd>
                   2514: 
                   2515:    <dt>EOF</dt>
                   2516:    <dd><a href="#parse-error">Parse error</a>. Reconsume the EOF character in the
                   2517:    <a href="#data-state">data state</a>.</dd>
                   2518: 
                   2519:    <dt>Anything else</dt>
                   2520:    <dd>Append the <a href="#current-input-character">current input character</a> to the current attribute's
                   2521:    value. Stay in the <a href="#attribute-value-single-quoted-state">attribute value (single-quoted)
                   2522:    state</a>.</dd>
                   2523: 
                   2524:   </dl><h5 id="attribute-value-unquoted-state"><span class="secno">9.2.4.12 </span><dfn>Attribute value (unquoted) state</dfn></h5>
                   2525: 
                   2526:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   2527: 
                   2528:   <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
                   2529:    <dt>U+000A LINE FEED (LF)</dt>
                   2530:    <dt>U+000C FORM FEED (FF)</dt>
                   2531:    <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
                   2532:    <dt>U+0020 SPACE</dt>
                   2533:    <dd>Switch to the <a href="#before-attribute-name-state">before attribute name state</a>.</dd>
                   2534: 
                   2535:    <dt>U+0026 AMPERSAND (&amp;)</dt>
                   2536:    <dd>Switch to the <a href="#character-reference-in-attribute-value-state">character reference in attribute value
                   2537:    state</a>, with no <a href="#additional-allowed-character">additional allowed
                   2538:    character</a>.</dd>
                   2539: 
                   2540:    <dt>U+003E GREATER-THAN SIGN (&gt;)</dt>
                   2541:    <dd>Emit the current tag token. Switch to the <a href="#data-state">data
                   2542:    state</a>.</dd>
                   2543: 
                   2544:    <dt>U+0022 QUOTATION MARK (")</dt>
                   2545:    <dt>U+0027 APOSTROPHE (')</dt>
                   2546:    <dt>U+003C LESS-THAN SIGN (&lt;)</dt>
                   2547:    <dt>U+003D EQUALS SIGN (=)</dt>
                   2548:    <dd><a href="#parse-error">Parse error</a>. Treat it as per the "anything else"
                   2549:    entry below.</dd>
                   2550: 
                   2551:    <dt>EOF</dt>
                   2552:    <dd><a href="#parse-error">Parse error</a>. Reconsume the EOF character in the
                   2553:    <a href="#data-state">data state</a>.</dd>
                   2554: 
                   2555:    <dt>Anything else</dt>
                   2556:    <dd>Append the <a href="#current-input-character">current input character</a> to the current attribute's
                   2557:    value. Stay in the <a href="#attribute-value-unquoted-state">attribute value (unquoted)
                   2558:    state</a>.</dd>
                   2559: 
                   2560:   </dl><h5 id="character-reference-in-attribute-value-state"><span class="secno">9.2.4.13 </span><dfn>Character reference in attribute value state</dfn></h5>
                   2561: 
                   2562:   <p>Attempt to <a href="#consume-a-character-reference">consume a character reference</a>.</p>
                   2563: 
                   2564:   <p>If nothing is returned, append a U+0026 AMPERSAND character to
                   2565:   the current attribute's value.</p>
                   2566: 
                   2567:   <p>Otherwise, append the returned character token to the current
                   2568:   attribute's value.</p>
                   2569: 
                   2570:   <p>Finally, switch back to the attribute value state that you were
                   2571:   in when were switched into this state.</p>
                   2572: 
                   2573: 
                   2574:   <h5 id="after-attribute-value-quoted-state"><span class="secno">9.2.4.14 </span><dfn>After attribute value (quoted) state</dfn></h5>
                   2575: 
                   2576:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   2577: 
                   2578:   <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
                   2579:    <dt>U+000A LINE FEED (LF)</dt>
                   2580:    <dt>U+000C FORM FEED (FF)</dt>
                   2581:    <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
                   2582:    <dt>U+0020 SPACE</dt>
                   2583:    <dd>Switch to the <a href="#before-attribute-name-state">before attribute name state</a>.</dd>
                   2584: 
                   2585:    <dt>U+002F SOLIDUS (/)</dt>
                   2586:    <dd>Switch to the <a href="#self-closing-start-tag-state">self-closing start tag state</a>.</dd>
                   2587: 
                   2588:    <dt>U+003E GREATER-THAN SIGN (&gt;)</dt>
                   2589:    <dd>Emit the current tag token. Switch to the <a href="#data-state">data
                   2590:    state</a>.</dd>
                   2591: 
                   2592:    <dt>EOF</dt>
                   2593:    <dd><a href="#parse-error">Parse error</a>. Reconsume the EOF character in the
                   2594:    <a href="#data-state">data state</a>.</dd>
                   2595: 
                   2596:    <dt>Anything else</dt>
                   2597:    <dd><a href="#parse-error">Parse error</a>. Reconsume the character in
                   2598:    the <a href="#before-attribute-name-state">before attribute name state</a>.</dd>
                   2599: 
                   2600:   </dl><h5 id="self-closing-start-tag-state"><span class="secno">9.2.4.15 </span><dfn>Self-closing start tag state</dfn></h5>
                   2601: 
                   2602:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   2603: 
                   2604:   <dl class="switch"><dt>U+003E GREATER-THAN SIGN (&gt;)</dt>
                   2605:    <dd>Set the <i>self-closing flag</i> of the current tag
                   2606:    token. Emit the current tag token. Switch to the <a href="#data-state">data
                   2607:    state</a>.</dd>
                   2608: 
                   2609:    <dt>EOF</dt>
                   2610:    <dd><a href="#parse-error">Parse error</a>. Reconsume the EOF character in the
                   2611:    <a href="#data-state">data state</a>.</dd>
                   2612: 
                   2613:    <dt>Anything else</dt>
                   2614:    <dd><a href="#parse-error">Parse error</a>. Reconsume the character in
                   2615:    the <a href="#before-attribute-name-state">before attribute name state</a>.</dd>
                   2616: 
                   2617:   </dl><h5 id="bogus-comment-state"><span class="secno">9.2.4.16 </span><dfn>Bogus comment state</dfn></h5>
                   2618: 
                   2619:   <p><i>(This can only happen if the <a href="#content-model-flag">content model
                   2620:   flag</a> is set to the PCDATA state.)</i></p>
                   2621: 
                   2622:   <p>Consume every character up to and including the first U+003E
                   2623:   GREATER-THAN SIGN character (&gt;) or the end of the file (EOF),
                   2624:   whichever comes first. Emit a comment token whose data is the
                   2625:   concatenation of all the characters starting from and including
                   2626:   the character that caused the state machine to switch into the
                   2627:   bogus comment state, up to and including the character immediately
                   2628:   before the last consumed character (i.e. up to the character just
                   2629:   before the U+003E or EOF character). (If the comment was started
                   2630:   by the end of the file (EOF), the token is empty.)</p>
                   2631: 
                   2632:   <p>Switch to the <a href="#data-state">data state</a>.</p>
                   2633: 
                   2634:   <p>If the end of the file was reached, reconsume the EOF
                   2635:   character.</p>
                   2636: 
                   2637: 
                   2638:   <h5 id="markup-declaration-open-state"><span class="secno">9.2.4.17 </span><dfn>Markup declaration open state</dfn></h5>
                   2639: 
                   2640:   <p><i>(This can only happen if the <a href="#content-model-flag">content model
                   2641:   flag</a> is set to the PCDATA state.)</i></p>
                   2642: 
                   2643:   <p>If the next two characters are both U+002D HYPHEN-MINUS (-)
                   2644:   characters, consume those two characters, create a comment token
                   2645:   whose data is the empty string, and switch to the <a href="#comment-start-state">comment
                   2646:   start state</a>.</p>
                   2647: 
                   2648:   <p>Otherwise, if the next seven characters are an <a href="infrastructure.html#ascii-case-insensitive">ASCII
                   2649:   case-insensitive</a> match for the word "DOCTYPE", then consume
                   2650:   those characters and switch to the <a href="#doctype-state">DOCTYPE state</a>.</p>
                   2651: 
                   2652:   <p>Otherwise, if the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-inforeign" title="insertion mode: in foreign content">in foreign
                   2653:   content</a>" and the <a href="#current-node">current node</a> is not an element
                   2654:   in the <a href="#html-namespace-0">HTML namespace</a> and the next seven characters are
                   2655:   an <span>ASCII case-sensitive</span> match for the string "[CDATA["
                   2656:   (the five uppercase letters "CDATA" with a U+005B LEFT SQUARE
                   2657:   BRACKET character before and after), then consume those characters
1.91      mike     2658:   and switch to the <a href="#cdata-section-state">CDATA section state</a>.</p>
1.1       mike     2659: 
                   2660:   <p>Otherwise, this is a <a href="#parse-error">parse error</a>. Switch to the
                   2661:   <a href="#bogus-comment-state">bogus comment state</a>. The next character that is
                   2662:   consumed, if any, is the first character that will be in the
                   2663:   comment.</p>
                   2664: 
                   2665: 
                   2666:   <h5 id="comment-start-state"><span class="secno">9.2.4.18 </span><dfn>Comment start state</dfn></h5>
                   2667: 
                   2668:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   2669: 
                   2670:   <dl class="switch"><dt>U+002D HYPHEN-MINUS (-)</dt>
                   2671:    <dd>Switch to the <a href="#comment-start-dash-state">comment start dash state</a>.</dd>
                   2672: 
                   2673:    <dt>U+003E GREATER-THAN SIGN (&gt;)</dt>
                   2674:    <dd><a href="#parse-error">Parse error</a>. Emit the comment token. Switch to the
                   2675:    <a href="#data-state">data state</a>.</dd> <!-- see comment in comment end state
                   2676:    -->
                   2677: 
                   2678:    <dt>EOF</dt>
                   2679:    <dd><a href="#parse-error">Parse error</a>. Emit the comment token. Reconsume
                   2680:    the EOF character in the <a href="#data-state">data state</a>.</dd>
                   2681: 
                   2682:    <dt>Anything else</dt>
                   2683:    <dd>Append the input character to the comment token's
                   2684:    data. Switch to the <a href="#comment-state">comment state</a>.</dd>
                   2685: 
                   2686:   </dl><h5 id="comment-start-dash-state"><span class="secno">9.2.4.19 </span><dfn>Comment start dash state</dfn></h5>
                   2687: 
                   2688:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   2689: 
                   2690:   <dl class="switch"><dt>U+002D HYPHEN-MINUS (-)</dt>
                   2691:    <dd>Switch to the <a href="#comment-end-state">comment end state</a></dd>
                   2692: 
                   2693:    <dt>U+003E GREATER-THAN SIGN (&gt;)</dt>
                   2694:    <dd><a href="#parse-error">Parse error</a>. Emit the comment token. Switch to
                   2695:    the <a href="#data-state">data state</a>.</dd>
                   2696: 
                   2697:    <dt>EOF</dt>
                   2698:    <dd><a href="#parse-error">Parse error</a>. Emit the comment token. Reconsume the
                   2699:    EOF character in the <a href="#data-state">data state</a>.</dd> <!-- see comment
                   2700:    in comment end state -->
                   2701: 
                   2702:    <dt>Anything else</dt>
                   2703:    <dd>Append a U+002D HYPHEN-MINUS (-) character and the input
                   2704:    character to the comment token's data. Switch to the
                   2705:    <a href="#comment-state">comment state</a>.</dd>
                   2706: 
                   2707:   </dl><h5 id="comment-state"><span class="secno">9.2.4.20 </span><dfn id="comment">Comment state</dfn></h5>
                   2708: 
                   2709:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   2710: 
                   2711:   <dl class="switch"><dt>U+002D HYPHEN-MINUS (-)</dt>
                   2712:    <dd>Switch to the <a href="#comment-end-dash-state">comment end dash state</a></dd>
                   2713: 
                   2714:    <dt>EOF</dt>
                   2715:    <dd><a href="#parse-error">Parse error</a>. Emit the comment token. Reconsume the
                   2716:    EOF character in the <a href="#data-state">data state</a>.</dd> <!-- see comment
                   2717:    in comment end state -->
                   2718: 
                   2719:    <dt>Anything else</dt>
                   2720:    <dd>Append the input character to the comment token's data. Stay
                   2721:    in the <a href="#comment-state">comment state</a>.</dd>
                   2722: 
                   2723:   </dl><h5 id="comment-end-dash-state"><span class="secno">9.2.4.21 </span><dfn>Comment end dash state</dfn></h5>
                   2724: 
                   2725:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   2726: 
                   2727:   <dl class="switch"><dt>U+002D HYPHEN-MINUS (-)</dt>
                   2728:    <dd>Switch to the <a href="#comment-end-state">comment end state</a></dd>
                   2729: 
                   2730:    <dt>EOF</dt>
                   2731:    <dd><a href="#parse-error">Parse error</a>. Emit the comment token. Reconsume the
                   2732:    EOF character in the <a href="#data-state">data state</a>.</dd> <!-- see comment
                   2733:    in comment end state -->
                   2734: 
                   2735:    <dt>Anything else</dt>
                   2736:    <dd>Append a U+002D HYPHEN-MINUS (-) character and the input
                   2737:    character to the comment token's data. Switch to the
                   2738:    <a href="#comment-state">comment state</a>.</dd>
                   2739: 
                   2740:   </dl><h5 id="comment-end-state"><span class="secno">9.2.4.22 </span><dfn>Comment end state</dfn></h5>
                   2741: 
                   2742:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   2743: 
                   2744:   <dl class="switch"><dt>U+003E GREATER-THAN SIGN (&gt;)</dt>
                   2745:    <dd>Emit the comment token. Switch to the <a href="#data-state">data
                   2746:    state</a>.</dd>
                   2747: 
                   2748:    <dt>U+002D HYPHEN-MINUS (-)</dt>
                   2749:    <dd><a href="#parse-error">Parse error</a>. Append a U+002D HYPHEN-MINUS
                   2750:    (-) character to the comment token's data. Stay in the
                   2751:    <a href="#comment-end-state">comment end state</a>.</dd>
                   2752: 
                   2753:    <dt>U+0009 CHARACTER TABULATION</dt>
                   2754:    <dt>U+000A LINE FEED (LF)</dt>
                   2755:    <dt>U+000C FORM FEED (FF)</dt>
                   2756:    <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
                   2757:    <dt>U+0020 SPACE</dt>
                   2758:    <dd><a href="#parse-error">Parse error</a>. Append two U+002D HYPHEN-MINUS (-)
                   2759:    characters and the input character to the comment token's
                   2760:    data. Switch to the <a href="#comment-end-space-state">comment end space state</a>.</dd>
                   2761: 
                   2762:    <dt>U+0021 EXCLAMATION MARK (!)</dt>
                   2763:    <dd><a href="#parse-error">Parse error</a>. Switch to the <a href="#comment-end-bang-state">comment end bang
                   2764:    state</a>.</dd>
                   2765: 
                   2766:    <dt>EOF</dt>
                   2767:    <dd><a href="#parse-error">Parse error</a>. Emit the comment token. Reconsume
                   2768:    the EOF character in the <a href="#data-state">data state</a>.</dd> <!-- For
                   2769:    security reasons: otherwise, hostile user could put a <script> in
                   2770:    a comment e.g. in a blog comment and then DOS the server so that
                   2771:    the end tag isn't read, and then the commented <script> tag would
                   2772:    be treated as live code -->
                   2773: 
                   2774:    <dt>Anything else</dt>
                   2775:    <dd><a href="#parse-error">Parse error</a>. Append two U+002D HYPHEN-MINUS (-)
                   2776:    characters and the input character to the comment token's
                   2777:    data. Switch to the <a href="#comment-state">comment state</a>.</dd>
                   2778: 
                   2779:   </dl><h5 id="comment-end-bang-state"><span class="secno">9.2.4.23 </span><dfn>Comment end bang state</dfn></h5>
                   2780: 
                   2781:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   2782: 
                   2783:   <dl class="switch"><dt>U+003E GREATER-THAN SIGN (&gt;)</dt>
                   2784:    <dd>Emit the comment token. Switch to the <a href="#data-state">data
                   2785:    state</a>.</dd>
                   2786: 
                   2787:    <dt>U+002D HYPHEN-MINUS (-)</dt>
                   2788:    <dd>Append two U+002D HYPHEN-MINUS (-) characters and a U+0021
                   2789:    EXCLAMATION MARK (!) character to the comment token's data. Switch
                   2790:    to the <a href="#comment-end-dash-state">comment end dash state</a>.</dd>
                   2791: 
                   2792:    <dt>EOF</dt>
                   2793:    <dd><a href="#parse-error">Parse error</a>. Emit the comment token. Reconsume
                   2794:    the EOF character in the <a href="#data-state">data state</a>.</dd> <!-- see
                   2795:    comment in comment end state -->
                   2796: 
                   2797:    <dt>Anything else</dt>
                   2798:    <dd>Append two U+002D HYPHEN-MINUS (-) characters, a U+0021
                   2799:    EXCLAMATION MARK (!) character, and the input character to the
                   2800:    comment token's data. Switch to the <a href="#comment-state">comment
                   2801:    state</a>.</dd>
                   2802: 
                   2803:   </dl><h5 id="comment-end-space-state"><span class="secno">9.2.4.24 </span><dfn>Comment end space state</dfn></h5>
                   2804: 
                   2805:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   2806: 
                   2807:   <dl class="switch"><dt>U+003E GREATER-THAN SIGN (&gt;)</dt>
                   2808:    <dd>Emit the comment token. Switch to the <a href="#data-state">data
                   2809:    state</a>.</dd>
                   2810: 
                   2811:    <dt>U+002D HYPHEN-MINUS (-)</dt>
                   2812:    <dd>Switch to the <a href="#comment-end-dash-state">comment end dash state</a>.</dd>
                   2813: 
                   2814:    <dt>U+0009 CHARACTER TABULATION</dt>
                   2815:    <dt>U+000A LINE FEED (LF)</dt>
                   2816:    <dt>U+000C FORM FEED (FF)</dt>
                   2817:    <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
                   2818:    <dt>U+0020 SPACE</dt>
                   2819:    <dd>Append the input character to the comment token's data. Stay in
                   2820:    the <a href="#comment-end-space-state">comment end space state</a>.</dd>
                   2821: 
                   2822:    <dt>EOF</dt>
                   2823:    <dd><a href="#parse-error">Parse error</a>. Emit the comment token. Reconsume
                   2824:    the EOF character in the <a href="#data-state">data state</a>.</dd> <!-- see
                   2825:    comment in comment end state -->
                   2826: 
                   2827:    <dt>Anything else</dt>
                   2828:    <dd>Append the input character to the comment token's data. Switch
                   2829:    to the <a href="#comment-state">comment state</a>.</dd>
                   2830: 
                   2831:   </dl><h5 id="doctype-state"><span class="secno">9.2.4.25 </span><dfn>DOCTYPE state</dfn></h5>
                   2832: 
                   2833:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   2834: 
                   2835:   <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
                   2836:    <dt>U+000A LINE FEED (LF)</dt>
                   2837:    <dt>U+000C FORM FEED (FF)</dt>
                   2838:    <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
                   2839:    <dt>U+0020 SPACE</dt>
                   2840:    <dd>Switch to the <a href="#before-doctype-name-state">before DOCTYPE name state</a>.</dd>
                   2841: 
                   2842:    <dt>EOF</dt>
                   2843:    <dd><a href="#parse-error">Parse error</a>. Create a new DOCTYPE token. Set its
                   2844:    <i>force-quirks flag</i> to <i>on</i>. Emit the token. Reconsume
                   2845:    the EOF character in the <a href="#data-state">data state</a>.</dd>
                   2846: 
                   2847:    <dt>Anything else</dt>
                   2848:    <dd><a href="#parse-error">Parse error</a>. Reconsume the current
                   2849:    character in the <a href="#before-doctype-name-state">before DOCTYPE name state</a>.</dd>
                   2850: 
                   2851:   </dl><h5 id="before-doctype-name-state"><span class="secno">9.2.4.26 </span><dfn>Before DOCTYPE name state</dfn></h5>
                   2852: 
                   2853:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   2854: 
                   2855:   <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
                   2856:    <dt>U+000A LINE FEED (LF)</dt>
                   2857:    <dt>U+000C FORM FEED (FF)</dt>
                   2858:    <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
                   2859:    <dt>U+0020 SPACE</dt>
                   2860:    <dd>Stay in the <a href="#before-doctype-name-state">before DOCTYPE name state</a>.</dd>
                   2861: 
                   2862:    <dt>U+003E GREATER-THAN SIGN (&gt;)</dt>
                   2863:    <dd><a href="#parse-error">Parse error</a>. Create a new DOCTYPE token. Set its
                   2864:    <i>force-quirks flag</i> to <i>on</i>. Emit the token. Switch to
                   2865:    the <a href="#data-state">data state</a>.</dd>
                   2866: 
                   2867:    <dt>U+0041 LATIN CAPITAL LETTER A through to U+005A LATIN CAPITAL LETTER Z</dt>
                   2868:    <dd>Create a new DOCTYPE token. Set the token's name to the
                   2869:    lowercase version of the input character (add 0x0020 to the
                   2870:    character's code point). Switch to the <a href="#doctype-name-state">DOCTYPE name
                   2871:    state</a>.</dd>
                   2872: 
                   2873:    <dt>EOF</dt>
                   2874:    <dd><a href="#parse-error">Parse error</a>. Create a new DOCTYPE token. Set its
                   2875:    <i>force-quirks flag</i> to <i>on</i>. Emit the token. Reconsume
                   2876:    the EOF character in the <a href="#data-state">data state</a>.</dd>
                   2877: 
                   2878:    <dt>Anything else</dt>
                   2879:    <dd>Create a new DOCTYPE token. Set the token's name to the
                   2880:    <a href="#current-input-character">current input character</a>. Switch to the <a href="#doctype-name-state">DOCTYPE name
                   2881:    state</a>.</dd>
                   2882: 
                   2883:   </dl><h5 id="doctype-name-state"><span class="secno">9.2.4.27 </span><dfn>DOCTYPE name state</dfn></h5>
                   2884: 
                   2885:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   2886: 
                   2887:   <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
                   2888:    <dt>U+000A LINE FEED (LF)</dt>
                   2889:    <dt>U+000C FORM FEED (FF)</dt>
                   2890:    <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
                   2891:    <dt>U+0020 SPACE</dt>
                   2892:    <dd>Switch to the <a href="#after-doctype-name-state">after DOCTYPE name state</a>.</dd>
                   2893: 
                   2894:    <dt>U+003E GREATER-THAN SIGN (&gt;)</dt>
                   2895:    <dd>Emit the current DOCTYPE token. Switch to the <a href="#data-state">data
                   2896:    state</a>.</dd>
                   2897: 
                   2898:    <dt>U+0041 LATIN CAPITAL LETTER A through to U+005A LATIN CAPITAL LETTER Z</dt>
                   2899:    <dd>Append the lowercase version of the input character (add 0x0020
                   2900:    to the character's code point) to the current DOCTYPE token's
                   2901:    name. Stay in the <a href="#doctype-name-state">DOCTYPE name state</a>.</dd>
                   2902: 
                   2903:    <dt>EOF</dt>
                   2904:    <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
                   2905:    <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE token.
                   2906:    Reconsume the EOF character in the <a href="#data-state">data state</a>.</dd>
                   2907: 
                   2908:    <dt>Anything else</dt>
                   2909:    <dd>Append the <a href="#current-input-character">current input character</a> to the current DOCTYPE
                   2910:    token's name. Stay in the <a href="#doctype-name-state">DOCTYPE name state</a>.</dd>
                   2911: 
                   2912:   </dl><h5 id="after-doctype-name-state"><span class="secno">9.2.4.28 </span><dfn>After DOCTYPE name state</dfn></h5>
                   2913: 
                   2914:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   2915: 
                   2916:   <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
                   2917:    <dt>U+000A LINE FEED (LF)</dt>
                   2918:    <dt>U+000C FORM FEED (FF)</dt>
                   2919:    <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
                   2920:    <dt>U+0020 SPACE</dt>
                   2921:    <dd>Stay in the <a href="#after-doctype-name-state">after DOCTYPE name state</a>.</dd>
                   2922: 
                   2923:    <dt>U+003E GREATER-THAN SIGN (&gt;)</dt>
                   2924:    <dd>Emit the current DOCTYPE token. Switch to the <a href="#data-state">data
                   2925:    state</a>.</dd>
                   2926: 
                   2927:    <dt>EOF</dt>
                   2928:    <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
                   2929:    <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE token.
                   2930:    Reconsume the EOF character in the <a href="#data-state">data state</a>.</dd>
                   2931: 
                   2932:    <dt>Anything else</dt>
                   2933:    <dd>
                   2934: 
                   2935:     <p>If the six characters starting from the <a href="#current-input-character">current input
                   2936:     character</a> are an <a href="infrastructure.html#ascii-case-insensitive">ASCII case-insensitive</a> match
                   2937:     for the word "PUBLIC", then consume those characters and switch to
                   2938:     the <a href="#before-doctype-public-identifier-state">before DOCTYPE public identifier state</a>.</p>
                   2939: 
                   2940:     <p>Otherwise, if the six characters starting from the
                   2941:     <a href="#current-input-character">current input character</a> are an <a href="infrastructure.html#ascii-case-insensitive">ASCII
                   2942:     case-insensitive</a> match for the word "SYSTEM", then consume
                   2943:     those characters and switch to the <a href="#before-doctype-system-identifier-state">before DOCTYPE system
                   2944:     identifier state</a>.</p>
                   2945: 
                   2946:     <p>Otherwise, this is the <a href="#parse-error">parse error</a>. Set the
                   2947:     DOCTYPE token's <i>force-quirks flag</i> to <i>on</i>. Switch to
                   2948:     the <a href="#bogus-doctype-state">bogus DOCTYPE state</a>.</p>
                   2949: 
                   2950:    </dd>
                   2951: 
                   2952:   </dl><h5 id="before-doctype-public-identifier-state"><span class="secno">9.2.4.29 </span><dfn>Before DOCTYPE public identifier state</dfn></h5>
                   2953: 
                   2954:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   2955: 
                   2956:   <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
                   2957:    <dt>U+000A LINE FEED (LF)</dt>
                   2958:    <dt>U+000C FORM FEED (FF)</dt>
                   2959:    <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
                   2960:    <dt>U+0020 SPACE</dt>
                   2961:    <dd>Stay in the <a href="#before-doctype-public-identifier-state">before DOCTYPE public identifier state</a>.</dd>
                   2962: 
                   2963:    <dt>U+0022 QUOTATION MARK (")</dt>
                   2964:    <dd>Set the DOCTYPE token's public identifier to the empty string
                   2965:    (not missing), then switch to the <a href="#doctype-public-identifier-double-quoted-state">DOCTYPE public identifier
                   2966:    (double-quoted) state</a>.</dd>
                   2967: 
                   2968:    <dt>U+0027 APOSTROPHE (')</dt>
                   2969:    <dd>Set the DOCTYPE token's public identifier to the empty string
                   2970:    (not missing), then switch to the <a href="#doctype-public-identifier-single-quoted-state">DOCTYPE public identifier
                   2971:    (single-quoted) state</a>.</dd>
                   2972: 
                   2973:    <dt>U+003E GREATER-THAN SIGN (&gt;)</dt>
                   2974:    <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
                   2975:    <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE
                   2976:    token. Switch to the <a href="#data-state">data state</a>.</dd>
                   2977: 
                   2978:    <dt>EOF</dt>
                   2979:    <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
                   2980:    <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE token.
                   2981:    Reconsume the EOF character in the <a href="#data-state">data state</a>.</dd>
                   2982: 
                   2983:    <dt>Anything else</dt>
                   2984:    <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
                   2985:    <i>force-quirks flag</i> to <i>on</i>. Switch to the <a href="#bogus-doctype-state">bogus
                   2986:    DOCTYPE state</a>.</dd>
                   2987: 
                   2988:   </dl><h5 id="doctype-public-identifier-double-quoted-state"><span class="secno">9.2.4.30 </span><dfn>DOCTYPE public identifier (double-quoted) state</dfn></h5>
                   2989: 
                   2990:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   2991: 
                   2992:   <dl class="switch"><dt>U+0022 QUOTATION MARK (")</dt>
                   2993:    <dd>Switch to the <a href="#after-doctype-public-identifier-state">after DOCTYPE public identifier state</a>.</dd>
                   2994: 
                   2995:    <dt>U+003E GREATER-THAN SIGN (&gt;)</dt>
                   2996:    <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
                   2997:    <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE
                   2998:    token. Switch to the <a href="#data-state">data state</a>.</dd>
                   2999: 
                   3000:    <dt>EOF</dt>
                   3001:    <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
                   3002:    <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE token.
                   3003:    Reconsume the EOF character in the <a href="#data-state">data state</a>.</dd>
                   3004: 
                   3005:    <dt>Anything else</dt>
                   3006:    <dd>Append the <a href="#current-input-character">current input character</a> to the current DOCTYPE
                   3007:    token's public identifier. Stay in the <a href="#doctype-public-identifier-double-quoted-state">DOCTYPE public
                   3008:    identifier (double-quoted) state</a>.</dd>
                   3009: 
                   3010:   </dl><h5 id="doctype-public-identifier-single-quoted-state"><span class="secno">9.2.4.31 </span><dfn>DOCTYPE public identifier (single-quoted) state</dfn></h5>
                   3011: 
                   3012:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   3013: 
                   3014:   <dl class="switch"><dt>U+0027 APOSTROPHE (')</dt>
                   3015:    <dd>Switch to the <a href="#after-doctype-public-identifier-state">after DOCTYPE public identifier state</a>.</dd>
                   3016: 
                   3017:    <dt>U+003E GREATER-THAN SIGN (&gt;)</dt>
                   3018:    <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
                   3019:    <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE
                   3020:    token. Switch to the <a href="#data-state">data state</a>.</dd>
                   3021: 
                   3022:    <dt>EOF</dt>
                   3023:    <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
                   3024:    <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE token.
                   3025:    Reconsume the EOF character in the <a href="#data-state">data state</a>.</dd>
                   3026: 
                   3027:    <dt>Anything else</dt>
                   3028:    <dd>Append the <a href="#current-input-character">current input character</a> to the current DOCTYPE
                   3029:    token's public identifier. Stay in the <a href="#doctype-public-identifier-single-quoted-state">DOCTYPE public
                   3030:    identifier (single-quoted) state</a>.</dd>
                   3031: 
                   3032:   </dl><h5 id="after-doctype-public-identifier-state"><span class="secno">9.2.4.32 </span><dfn>After DOCTYPE public identifier state</dfn></h5>
                   3033: 
                   3034:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   3035: 
                   3036:   <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
                   3037:    <dt>U+000A LINE FEED (LF)</dt>
                   3038:    <dt>U+000C FORM FEED (FF)</dt>
                   3039:    <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
                   3040:    <dt>U+0020 SPACE</dt>
                   3041:    <dd>Stay in the <a href="#after-doctype-public-identifier-state">after DOCTYPE public identifier state</a>.</dd>
                   3042: 
                   3043:    <dt>U+0022 QUOTATION MARK (")</dt>
                   3044:    <dd>Set the DOCTYPE token's system identifier to the empty string
                   3045:    (not missing), then switch to the <a href="#doctype-system-identifier-double-quoted-state">DOCTYPE system identifier
                   3046:    (double-quoted) state</a>.</dd>
                   3047: 
                   3048:    <dt>U+0027 APOSTROPHE (')</dt>
                   3049:    <dd>Set the DOCTYPE token's system identifier to the empty string
                   3050:    (not missing), then switch to the <a href="#doctype-system-identifier-single-quoted-state">DOCTYPE system identifier
                   3051:    (single-quoted) state</a>.</dd>
                   3052: 
                   3053:    <dt>U+003E GREATER-THAN SIGN (&gt;)</dt>
                   3054:    <dd>Emit the current DOCTYPE token. Switch to the <a href="#data-state">data
                   3055:    state</a>.</dd>
                   3056: 
                   3057:    <dt>EOF</dt>
                   3058:    <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
                   3059:    <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE token.
                   3060:    Reconsume the EOF character in the <a href="#data-state">data state</a>.</dd>
                   3061: 
                   3062:    <dt>Anything else</dt>
                   3063:    <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
                   3064:    <i>force-quirks flag</i> to <i>on</i>. Switch to the <a href="#bogus-doctype-state">bogus
                   3065:    DOCTYPE state</a>.</dd>
                   3066: 
                   3067:   </dl><h5 id="before-doctype-system-identifier-state"><span class="secno">9.2.4.33 </span><dfn>Before DOCTYPE system identifier state</dfn></h5>
                   3068: 
                   3069:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   3070: 
                   3071:   <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
                   3072:    <dt>U+000A LINE FEED (LF)</dt>
                   3073:    <dt>U+000C FORM FEED (FF)</dt>
                   3074:    <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
                   3075:    <dt>U+0020 SPACE</dt>
                   3076:    <dd>Stay in the <a href="#before-doctype-system-identifier-state">before DOCTYPE system identifier state</a>.</dd>
                   3077: 
                   3078:    <dt>U+0022 QUOTATION MARK (")</dt>
                   3079:    <dd>Set the DOCTYPE token's system identifier to the empty string
                   3080:    (not missing), then switch to the <a href="#doctype-system-identifier-double-quoted-state">DOCTYPE system identifier
                   3081:    (double-quoted) state</a>.</dd>
                   3082: 
                   3083:    <dt>U+0027 APOSTROPHE (')</dt>
                   3084:    <dd>Set the DOCTYPE token's system identifier to the empty string
                   3085:    (not missing), then switch to the <a href="#doctype-system-identifier-single-quoted-state">DOCTYPE system identifier
                   3086:    (single-quoted) state</a>.</dd>
                   3087: 
                   3088:    <dt>U+003E GREATER-THAN SIGN (&gt;)</dt>
                   3089:    <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
                   3090:    <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE
                   3091:    token. Switch to the <a href="#data-state">data state</a>.</dd>
                   3092: 
                   3093:    <dt>EOF</dt>
                   3094:    <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
                   3095:    <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE token.
                   3096:    Reconsume the EOF character in the <a href="#data-state">data state</a>.</dd>
                   3097: 
                   3098:    <dt>Anything else</dt>
                   3099:    <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
                   3100:    <i>force-quirks flag</i> to <i>on</i>. Switch to the <a href="#bogus-doctype-state">bogus
                   3101:    DOCTYPE state</a>.</dd>
                   3102: 
                   3103:   </dl><h5 id="doctype-system-identifier-double-quoted-state"><span class="secno">9.2.4.34 </span><dfn>DOCTYPE system identifier (double-quoted) state</dfn></h5>
                   3104: 
                   3105:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   3106: 
                   3107:   <dl class="switch"><dt>U+0022 QUOTATION MARK (")</dt>
                   3108:    <dd>Switch to the <a href="#after-doctype-system-identifier-state">after DOCTYPE system identifier state</a>.</dd>
                   3109: 
                   3110:    <dt>U+003E GREATER-THAN SIGN (&gt;)</dt>
                   3111:    <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
                   3112:    <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE
                   3113:    token. Switch to the <a href="#data-state">data state</a>.</dd>
                   3114: 
                   3115:    <dt>EOF</dt>
                   3116:    <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
                   3117:    <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE token.
                   3118:    Reconsume the EOF character in the <a href="#data-state">data state</a>.</dd>
                   3119: 
                   3120:    <dt>Anything else</dt>
                   3121:    <dd>Append the <a href="#current-input-character">current input character</a> to the current DOCTYPE
                   3122:    token's system identifier. Stay in the <a href="#doctype-system-identifier-double-quoted-state">DOCTYPE system
                   3123:    identifier (double-quoted) state</a>.</dd>
                   3124: 
                   3125:   </dl><h5 id="doctype-system-identifier-single-quoted-state"><span class="secno">9.2.4.35 </span><dfn>DOCTYPE system identifier (single-quoted) state</dfn></h5>
                   3126: 
                   3127:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   3128: 
                   3129:   <dl class="switch"><dt>U+0027 APOSTROPHE (')</dt>
                   3130:    <dd>Switch to the <a href="#after-doctype-system-identifier-state">after DOCTYPE system identifier state</a>.</dd>
                   3131: 
                   3132:    <dt>U+003E GREATER-THAN SIGN (&gt;)</dt>
                   3133:    <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
                   3134:    <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE
                   3135:    token. Switch to the <a href="#data-state">data state</a>.</dd>
                   3136: 
                   3137:    <dt>EOF</dt>
                   3138:    <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
                   3139:    <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE token.
                   3140:    Reconsume the EOF character in the <a href="#data-state">data state</a>.</dd>
                   3141: 
                   3142:    <dt>Anything else</dt>
                   3143:    <dd>Append the <a href="#current-input-character">current input character</a> to the current DOCTYPE
                   3144:    token's system identifier. Stay in the <a href="#doctype-system-identifier-single-quoted-state">DOCTYPE system
                   3145:    identifier (single-quoted) state</a>.</dd>
                   3146: 
                   3147:   </dl><h5 id="after-doctype-system-identifier-state"><span class="secno">9.2.4.36 </span><dfn>After DOCTYPE system identifier state</dfn></h5>
                   3148: 
                   3149:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   3150: 
                   3151:   <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
                   3152:    <dt>U+000A LINE FEED (LF)</dt>
                   3153:    <dt>U+000C FORM FEED (FF)</dt>
                   3154:    <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
                   3155:    <dt>U+0020 SPACE</dt>
                   3156:    <dd>Stay in the <a href="#after-doctype-system-identifier-state">after DOCTYPE system identifier state</a>.</dd>
                   3157: 
                   3158:    <dt>U+003E GREATER-THAN SIGN (&gt;)</dt>
                   3159:    <dd>Emit the current DOCTYPE token. Switch to the <a href="#data-state">data
                   3160:    state</a>.</dd>
                   3161: 
                   3162:    <dt>EOF</dt>
                   3163:    <dd><a href="#parse-error">Parse error</a>. Set the DOCTYPE token's
                   3164:    <i>force-quirks flag</i> to <i>on</i>. Emit that DOCTYPE token.
                   3165:    Reconsume the EOF character in the <a href="#data-state">data state</a>.</dd>
                   3166: 
                   3167:    <dt>Anything else</dt>
                   3168:    <dd><a href="#parse-error">Parse error</a>. Switch to the <a href="#bogus-doctype-state">bogus DOCTYPE
                   3169:    state</a>. (This does <em>not</em> set the DOCTYPE token's
                   3170:    <i>force-quirks flag</i> to <i>on</i>.)</dd>
                   3171: 
                   3172:   </dl><h5 id="bogus-doctype-state"><span class="secno">9.2.4.37 </span><dfn>Bogus DOCTYPE state</dfn></h5>
                   3173: 
                   3174:   <p>Consume the <a href="#next-input-character">next input character</a>:</p>
                   3175: 
                   3176:   <dl class="switch"><dt>U+003E GREATER-THAN SIGN (&gt;)</dt>
                   3177:    <dd>Emit the DOCTYPE token. Switch to the <a href="#data-state">data
                   3178:    state</a>.</dd>
                   3179: 
                   3180:    <dt>EOF</dt>
                   3181:    <dd>Emit the DOCTYPE token. Reconsume the EOF character in the
                   3182:    <a href="#data-state">data state</a>.</dd>
                   3183: 
                   3184:    <dt>Anything else</dt>
                   3185:    <dd>Stay in the <a href="#bogus-doctype-state">bogus DOCTYPE state</a>.</dd>
                   3186: 
                   3187:   </dl><h5 id="cdata-section-state"><span class="secno">9.2.4.38 </span><dfn>CDATA section state</dfn></h5>
                   3188: 
                   3189:   <p><i>(This can only happen if the <a href="#content-model-flag">content model
1.91      mike     3190:   flag</a> is set to the PCDATA state.)</i></p>
1.1       mike     3191: 
                   3192:   <p>Consume every character up to the next occurrence of the three
                   3193:   character sequence U+005D RIGHT SQUARE BRACKET U+005D RIGHT SQUARE
                   3194:   BRACKET U+003E GREATER-THAN SIGN (<code title="">]]&gt;</code>), or the
                   3195:   end of the file (EOF), whichever comes first. Emit a series of
                   3196:   character tokens consisting of all the characters consumed except
                   3197:   the matching three character sequence at the end (if one was found
                   3198:   before the end of the file).</p>
                   3199: 
                   3200:   <p>Switch to the <a href="#data-state">data state</a>.</p>
                   3201: 
                   3202:   <p>If the end of the file was reached, reconsume the EOF
                   3203:   character.</p>
                   3204: 
                   3205: 
                   3206: 
                   3207:   <h5 id="tokenizing-character-references"><span class="secno">9.2.4.39 </span>Tokenizing character references</h5>
                   3208: 
                   3209:   <p>This section defines how to <dfn id="consume-a-character-reference">consume a character
                   3210:   reference</dfn>. This definition is used when parsing character
                   3211:   references <a href="#character-reference-data-state" title="character reference data state">in
                   3212:   text</a> and <a href="#character-reference-in-attribute-value-state" title="character reference in attribute value
                   3213:   state">in attributes</a>.</p>
                   3214: 
                   3215:   <p>The behavior depends on the identity of the next character (the
                   3216:   one immediately after the U+0026 AMPERSAND character):</p>
                   3217: 
                   3218:   <dl class="switch"><dt>U+0009 CHARACTER TABULATION</dt>
                   3219:    <dt>U+000A LINE FEED (LF)</dt>
                   3220:    <dt>U+000C FORM FEED (FF)</dt>
                   3221:    <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
                   3222:    <dt>U+0020 SPACE</dt>
                   3223:    <dt>U+003C LESS-THAN SIGN</dt>
                   3224:    <dt>U+0026 AMPERSAND</dt>
                   3225:    <dt>EOF</dt>
                   3226:    <dt>The <dfn id="additional-allowed-character">additional allowed character</dfn>, if there is one</dt>
                   3227: 
                   3228:    <dd>Not a character reference. No characters are consumed, and
                   3229:    nothing is returned. (This is not an error, either.)</dd>
                   3230: 
                   3231: 
                   3232:    <dt>U+0023 NUMBER SIGN (#)</dt>
                   3233: 
                   3234:    <dd>
                   3235: 
                   3236:     <p>Consume the U+0023 NUMBER SIGN.</p>
                   3237: 
                   3238:     <p>The behavior further depends on the character after the U+0023
                   3239:     NUMBER SIGN:</p>
                   3240: 
                   3241:     <dl class="switch"><dt>U+0078 LATIN SMALL LETTER X</dt>
                   3242:      <dt>U+0058 LATIN CAPITAL LETTER X</dt>
                   3243: 
                   3244:      <dd>
                   3245: 
                   3246:       <p>Consume the X.</p>
                   3247: 
                   3248:       <p>Follow the steps below, but using the range of characters
                   3249:       U+0030 DIGIT ZERO through to U+0039 DIGIT NINE, U+0061 LATIN
                   3250:       SMALL LETTER A through to U+0066 LATIN SMALL LETTER F, and
                   3251:       U+0041 LATIN CAPITAL LETTER A, through to U+0046 LATIN CAPITAL
                   3252:       LETTER F (in other words, 0-9, A-F, a-f).</p>
                   3253: 
                   3254:       <p>When it comes to interpreting the number, interpret it as a
                   3255:       hexadecimal number.</p>
                   3256: 
                   3257:      </dd>
                   3258: 
                   3259: 
                   3260:      <dt>Anything else</dt>
                   3261: 
                   3262:      <dd>
                   3263: 
                   3264:       <p>Follow the steps below, but using the range of characters
                   3265:       U+0030 DIGIT ZERO through to U+0039 DIGIT NINE (i.e. just
                   3266:       0-9).</p>
                   3267: 
                   3268:       <p>When it comes to interpreting the number, interpret it as a
                   3269:       decimal number.</p>
                   3270: 
                   3271:      </dd>
                   3272: 
                   3273:     </dl><p>Consume as many characters as match the range of characters
                   3274:     given above.</p>
                   3275: 
                   3276:     <p>If no characters match the range, then don't consume any
                   3277:     characters (and unconsume the U+0023 NUMBER SIGN character and, if
                   3278:     appropriate, the X character). This is a <a href="#parse-error">parse
                   3279:     error</a>; nothing is returned.</p>
                   3280: 
                   3281:     <p>Otherwise, if the next character is a U+003B SEMICOLON, consume
                   3282:     that too. If it isn't, there is a <a href="#parse-error">parse
                   3283:     error</a>.</p>
                   3284: 
                   3285:     <p>If one or more characters match the range, then take them all
                   3286:     and interpret the string of characters as a number (either
                   3287:     hexadecimal or decimal as appropriate).</p>
                   3288: 
                   3289:     <p>If that number is one of the numbers in the first column of the
                   3290:     following table, then this is a <a href="#parse-error">parse error</a>. Find the
                   3291:     row with that number in the first column, and return a character
                   3292:     token for the Unicode character given in the second column of that
                   3293:     row.</p>
                   3294: 
                   3295:     <table><thead><tr><th>Number </th><th colspan="2">Unicode character
                   3296:      </th></tr></thead><tbody><tr><td>0x00 </td><td>U+FFFD </td><td>REPLACEMENT CHARACTER
                   3297:       </td></tr><tr><td>0x0D </td><td>U+000A </td><td>LINE FEED (LF)
                   3298:       </td></tr><tr><td>0x80 </td><td>U+20AC </td><td>EURO SIGN ('&#8364;')
                   3299:       </td></tr><tr><td>0x81 </td><td>U+0081 </td><td>&lt;control&gt;
                   3300:       </td></tr><tr><td>0x82 </td><td>U+201A </td><td>SINGLE LOW-9 QUOTATION MARK ('&#8218;')
                   3301:       </td></tr><tr><td>0x83 </td><td>U+0192 </td><td>LATIN SMALL LETTER F WITH HOOK ('&#402;')
                   3302:       </td></tr><tr><td>0x84 </td><td>U+201E </td><td>DOUBLE LOW-9 QUOTATION MARK ('&#8222;')
                   3303:       </td></tr><tr><td>0x85 </td><td>U+2026 </td><td>HORIZONTAL ELLIPSIS ('&#8230;')
                   3304:       </td></tr><tr><td>0x86 </td><td>U+2020 </td><td>DAGGER ('&#8224;')
                   3305:       </td></tr><tr><td>0x87 </td><td>U+2021 </td><td>DOUBLE DAGGER ('&#8225;')
                   3306:       </td></tr><tr><td>0x88 </td><td>U+02C6 </td><td>MODIFIER LETTER CIRCUMFLEX ACCENT ('&#710;')
                   3307:       </td></tr><tr><td>0x89 </td><td>U+2030 </td><td>PER MILLE SIGN ('&#8240;')
                   3308:       </td></tr><tr><td>0x8A </td><td>U+0160 </td><td>LATIN CAPITAL LETTER S WITH CARON ('&#352;')
                   3309:       </td></tr><tr><td>0x8B </td><td>U+2039 </td><td>SINGLE LEFT-POINTING ANGLE QUOTATION MARK ('&#8249;')
                   3310:       </td></tr><tr><td>0x8C </td><td>U+0152 </td><td>LATIN CAPITAL LIGATURE OE ('&#338;')
                   3311:       </td></tr><tr><td>0x8D </td><td>U+008D </td><td>&lt;control&gt;
                   3312:       </td></tr><tr><td>0x8E </td><td>U+017D </td><td>LATIN CAPITAL LETTER Z WITH CARON ('&#381;')
                   3313:       </td></tr><tr><td>0x8F </td><td>U+008F </td><td>&lt;control&gt;
                   3314:       </td></tr><tr><td>0x90 </td><td>U+0090 </td><td>&lt;control&gt;
                   3315:       </td></tr><tr><td>0x91 </td><td>U+2018 </td><td>LEFT SINGLE QUOTATION MARK ('&#8216;')
                   3316:       </td></tr><tr><td>0x92 </td><td>U+2019 </td><td>RIGHT SINGLE QUOTATION MARK ('&#8217;')
                   3317:       </td></tr><tr><td>0x93 </td><td>U+201C </td><td>LEFT DOUBLE QUOTATION MARK ('&#8220;')
                   3318:       </td></tr><tr><td>0x94 </td><td>U+201D </td><td>RIGHT DOUBLE QUOTATION MARK ('&#8221;')
                   3319:       </td></tr><tr><td>0x95 </td><td>U+2022 </td><td>BULLET ('&#8226;')
                   3320:       </td></tr><tr><td>0x96 </td><td>U+2013 </td><td>EN DASH ('&#8211;')
                   3321:       </td></tr><tr><td>0x97 </td><td>U+2014 </td><td>EM DASH ('&#8212;')
                   3322:       </td></tr><tr><td>0x98 </td><td>U+02DC </td><td>SMALL TILDE ('&#732;')
                   3323:       </td></tr><tr><td>0x99 </td><td>U+2122 </td><td>TRADE MARK SIGN ('&#8482;')
                   3324:       </td></tr><tr><td>0x9A </td><td>U+0161 </td><td>LATIN SMALL LETTER S WITH CARON ('&#353;')
                   3325:       </td></tr><tr><td>0x9B </td><td>U+203A </td><td>SINGLE RIGHT-POINTING ANGLE QUOTATION MARK ('&#8250;')
                   3326:       </td></tr><tr><td>0x9C </td><td>U+0153 </td><td>LATIN SMALL LIGATURE OE ('&#339;')
                   3327:       </td></tr><tr><td>0x9D </td><td>U+009D </td><td>&lt;control&gt;
                   3328:       </td></tr><tr><td>0x9E </td><td>U+017E </td><td>LATIN SMALL LETTER Z WITH CARON ('&#382;')
                   3329:       </td></tr><tr><td>0x9F </td><td>U+0178 </td><td>LATIN CAPITAL LETTER Y WITH DIAERESIS ('&#376;')
1.18      mike     3330:     </td></tr></tbody></table><p>Otherwise, if the number is greater than 0x10FFFF, then this is
                   3331:     a <a href="#parse-error">parse error</a>. Return a U+FFFD REPLACEMENT
                   3332:     CHARACTER.</p>
                   3333: 
                   3334:     <p>Otherwise, return a character token for the Unicode character
1.1       mike     3335:     whose code point is that number.
                   3336: 
                   3337:     <!-- this is the same as the equivalent list in the input stream
                   3338:     section -->
                   3339:     If the number is in the range 0x0001 to 0x0008, <!-- HT, LF
                   3340:     allowed --> <!-- U+000B is in the next list --> <!-- FF, CR
                   3341:     allowed --> 0x000E to 0x001F, <!-- ASCII allowed --> 0x007F <!--to
                   3342:     0x0084, (0x0085 NEL not allowed), 0x0086--> to 0x009F, 0xD800 to
                   3343:     0xDFFF<!-- surrogates not allowed -->, 0xFDD0 to 0xFDEF, or is one
                   3344:     of 0x000B, 0xFFFE, 0xFFFF, 0x1FFFE, 0x1FFFF, 0x2FFFE, 0x2FFFF,
                   3345:     0x3FFFE, 0x3FFFF, 0x4FFFE, 0x4FFFF, 0x5FFFE, 0x5FFFF, 0x6FFFE,
                   3346:     0x6FFFF, 0x7FFFE, 0x7FFFF, 0x8FFFE, 0x8FFFF, 0x9FFFE, 0x9FFFF,
                   3347:     0xAFFFE, 0xAFFFF, 0xBFFFE, 0xBFFFF, 0xCFFFE, 0xCFFFF, 0xDFFFE,
                   3348:     0xDFFFF, 0xEFFFE, 0xEFFFF, 0xFFFFE, 0xFFFFF, 0x10FFFE, or
1.18      mike     3349:     0x10FFFF, then this is a <a href="#parse-error">parse error</a>.</p>
1.1       mike     3350: 
                   3351:    </dd>
                   3352: 
                   3353: 
                   3354:    <dt>Anything else</dt>
                   3355: 
                   3356:    <dd>
                   3357: 
                   3358:     <p>Consume the maximum number of characters possible, with the
                   3359:     consumed characters matching one of the identifiers in the first
                   3360:     column of the <a href="named-character-references.html#named-character-references">named character references</a> table (in a
                   3361:     <a href="infrastructure.html#case-sensitive">case-sensitive</a> manner).</p>
                   3362: 
                   3363:     <p>If no match can be made, then this is a <a href="#parse-error">parse
                   3364:     error</a>. No characters are consumed, and nothing is
                   3365:     returned.</p>
                   3366: 
                   3367:     <p>If the last character matched is not a U+003B SEMICOLON (<code title="">;</code>), there is a <a href="#parse-error">parse error</a>.</p>
                   3368: 
                   3369:     <p>If the character reference is being consumed <a href="#character-reference-in-attribute-value-state" title="character reference in attribute value state">as part of an
                   3370:     attribute</a>, and the last character matched is not a U+003B
                   3371:     SEMICOLON (<code title="">;</code>), and the next character is in
                   3372:     the range U+0030 DIGIT ZERO to U+0039 DIGIT NINE, U+0041 LATIN
                   3373:     CAPITAL LETTER A to U+005A LATIN CAPITAL LETTER Z, or U+0061 LATIN
                   3374:     SMALL LETTER A to U+007A LATIN SMALL LETTER Z, then, for
                   3375:     historical reasons, all the characters that were matched after the
                   3376:     U+0026 AMPERSAND (&amp;) must be unconsumed, and nothing is
                   3377:     returned.</p>
                   3378: 
                   3379:     <p>Otherwise, return a character token for the character
                   3380:     corresponding to the character reference name (as given by the
                   3381:     second column of the <a href="named-character-references.html#named-character-references">named character references</a>
                   3382:     table).</p>
                   3383: 
                   3384:     <div class="example">
                   3385: 
                   3386:      <p>If the markup contains <code title="">I'm &amp;notit; I tell
                   3387:      you</code>, the character reference is parsed as "not", as in,
                   3388:      <code title="">I'm &#172;it; I tell you</code>. But if the markup
                   3389:      was <code title="">I'm &amp;notin; I tell you</code>, the
                   3390:      character reference would be parsed as "notin;", resulting in
                   3391:      <code title="">I'm &#8713; I tell you</code>.</p>
                   3392: 
                   3393:     </div>
                   3394: 
                   3395:    </dd>
                   3396: 
                   3397:   </dl><h4 id="tree-construction"><span class="secno">9.2.5 </span><dfn>Tree construction</dfn></h4>
                   3398: 
                   3399:   <p>The input to the tree construction stage is a sequence of tokens
                   3400:   from the <a href="#tokenization">tokenization</a> stage. The tree construction
                   3401:   stage is associated with a DOM <code>Document</code> object when a
                   3402:   parser is created. The "output" of this stage consists of
                   3403:   dynamically modifying or extending that document's DOM tree.</p>
                   3404: 
                   3405:   <p>This specification does not define when an interactive user agent
                   3406:   has to render the <code>Document</code> so that it is available to
                   3407:   the user, or when it has to begin accepting user input.</p>
                   3408: 
                   3409:   <p>As each token is emitted from the tokenizer, the user agent must
                   3410:   process the token according to the rules given in the section
                   3411:   corresponding to the current <a href="#insertion-mode">insertion mode</a>.</p>
                   3412: 
                   3413:   <p>When the steps below require the UA to <dfn id="insert-a-character">insert a
                   3414:   character</dfn> into a node, if that node has a child immediately
                   3415:   before where the character is to be inserted, and that child is a
                   3416:   <code>Text</code> node, and that <code>Text</code> node was the last
                   3417:   node that the parser inserted into the document, then the character
                   3418:   must be appended to that <code>Text</code> node; otherwise, a new
                   3419:   <code>Text</code> node whose data is just that character must be
                   3420:   inserted in the appropriate place.</p>
                   3421: 
                   3422:   <div class="example">
                   3423: 
                   3424:    <p>Here are some sample inputs to the parser and the corresponding
                   3425:    number of text nodes that they result in, assuming a user agent
                   3426:    that executes scripts.</p>
                   3427: 
                   3428:    <table><thead><tr><th>Input </th><th>Number of text nodes
                   3429:     </th></tr></thead><tbody><tr><td><pre>A&lt;script&gt;
                   3430: var&#160;script&#160;=&#160;document.getElementsByTagName('script')[0];
                   3431: document.body.removeChild(script);
                   3432: &lt;/script&gt;B</pre>
                   3433:       </td><td>Two adjacent text nodes in the document, containing "A" and "B".
                   3434:      </td></tr><tr><td><pre>A&lt;script&gt;
                   3435: var&#160;text&#160;=&#160;document.createTextNode('B');
                   3436: document.body.appendChild(text);
                   3437: &lt;/script&gt;C</pre>
                   3438:       </td><td>Four text nodes; "A" before the script, the script's contents, "B" after the script, and then, immediately after that, "C".
                   3439:      </td></tr><tr><td><pre>A&lt;script&gt;
                   3440: var&#160;text&#160;=&#160;document.getElementsByTagName('script')[0].firstChild;
                   3441: text.data&#160;=&#160;'B';
                   3442: document.body.appendChild(text);
                   3443: &lt;/script&gt;B</pre>
                   3444:       </td><td>Two adjacent text nodes in the document, containing "A" and "BB".
                   3445:      </td></tr><tr><td><pre>A&lt;table&gt;B&lt;tr&gt;C&lt;/tr&gt;C&lt;/table&gt;</pre>
                   3446:       </td><td>Three adjacent text nodes before the table, containing "A", "B", and "CC" respectively. (This is caused by <a href="#foster-parent" title="foster parent">foster parenting</a>.)
                   3447:      </td></tr><tr><td><pre>A&lt;table&gt;&lt;tr&gt;&#160;B&lt;/tr&gt;&#160;B&lt;/table&gt;</pre>
                   3448:       </td><td>Two adjacent text nodes before the table, containing "A" and "&#160;B&#160;B" (space-B-space-B) respectively. (This is caused by <a href="#foster-parent" title="foster parent">foster parenting</a>.)
                   3449:      </td></tr><tr><td><pre>A&lt;table&gt;&lt;tr&gt;&#160;B&lt;/tr&gt;&#160;&lt;/em&gt;C&lt;/table&gt;</pre>
                   3450:       </td><td>Three adjacent text nodes before the table, containing "A", "&#160;B" (space-B), and "C" respectively, and one text node inside the table (as a child of a <code><a href="tabular-data.html#the-tbody-element">tbody</a></code>) with a single space character. (Space characters separated from non-space characters by non-character tokens are not affected by <a href="#foster-parent" title="foster parent">foster parenting</a>, even if those other tokens then get ignored.)
                   3451:    </td></tr></tbody></table></div>
                   3452: 
                   3453:   <p id="mutation-during-parsing">DOM mutation events must not fire
                   3454:   for changes caused by the UA parsing the document. (Conceptually,
                   3455:   the parser is not mutating the DOM, it is constructing it.) This
1.104     mike     3456:   includes the parsing of any content inserted using <code title="dom-document-write"><a href="dom.html#dom-document-write">document.write()</a></code> and <code title="dom-document-writeln"><a href="dom.html#dom-document-writeln">document.writeln()</a></code> calls. <a href="references.html#refsDOMEVENTS">[DOMEVENTS]</a></p>
1.1       mike     3457: 
                   3458:   <p class="note">Not all of the tag names mentioned below are
                   3459:   conformant tag names in this specification; many are included to
                   3460:   handle legacy content. They still form part of the algorithm that
                   3461:   implementations are required to implement to claim conformance.</p>
                   3462: 
                   3463:   <p class="note">The algorithm described below places no limit on the
                   3464:   depth of the DOM tree generated, or on the length of tag names,
                   3465:   attribute names, attribute values, text nodes, etc. While
                   3466:   implementors are encouraged to avoid arbitrary limits, it is
                   3467:   recognized that <a href="infrastructure.html#hardwareLimitations">practical
                   3468:   concerns</a> will likely force user agents to impose nesting
                   3469:   depths.</p>
                   3470: 
                   3471: 
                   3472:   <h5 id="creating-and-inserting-elements"><span class="secno">9.2.5.1 </span>Creating and inserting elements</h5>
                   3473: 
                   3474:   <p>When the steps below require the UA to <dfn id="create-an-element-for-the-token" title="create an
                   3475:   element for the token">create an element for a token</dfn> in a
                   3476:   particular namespace, the UA must create a node implementing the
                   3477:   interface appropriate for the element type corresponding to the tag
                   3478:   name of the token in the given namespace (as given in the
                   3479:   specification that defines that element, e.g. for an <code><a href="text-level-semantics.html#the-a-element">a</a></code>
                   3480:   element in the <a href="#html-namespace-0">HTML namespace</a>, this specification
                   3481:   defines it to be the <code><a href="text-level-semantics.html#htmlanchorelement">HTMLAnchorElement</a></code> interface), with
                   3482:   the tag name being the name of that element, with the node being in
                   3483:   the given namespace, and with the attributes on the node being those
                   3484:   given in the given token.</p>
                   3485: 
                   3486:   <p>The interface appropriate for an element in the <a href="#html-namespace-0">HTML
                   3487:   namespace</a> that is not defined in this specification is
1.44      mike     3488:   <code><a href="dom.html#htmlunknownelement">HTMLUnknownElement</a></code>. Element in other namespaces whose
1.1       mike     3489:   interface is not defined by that namespace's specification must use
                   3490:   the interface <code>Element</code>.</p>
                   3491: 
                   3492:   <p>When a <a href="forms.html#category-reset" title="category-reset">resettable</a> element is
                   3493:   created in this manner, its <a href="forms.html#concept-form-reset-control" title="concept-form-reset-control">reset algorithm</a> must be
                   3494:   invoked once the attributes are set. (This initializes the element's
                   3495:   <a href="forms.html#concept-fe-value" title="concept-fe-value">value</a> and <a href="forms.html#concept-fe-checked" title="concept-fe-checked">checkedness</a> based on the element's
                   3496:   attributes.)</p>
                   3497: 
                   3498:   <hr><p>When the steps below require the UA to <dfn id="insert-an-html-element">insert an HTML
                   3499:   element</dfn> for a token, the UA must first <a href="#create-an-element-for-the-token">create an element
                   3500:   for the token</a> in the <a href="#html-namespace-0">HTML namespace</a>, and then
                   3501:   append this node to the <a href="#current-node">current node</a>, and push it onto
                   3502:   the <a href="#stack-of-open-elements">stack of open elements</a> so that it is the new
                   3503:   <a href="#current-node">current node</a>.</p>
                   3504: 
                   3505:   <p>The steps below may also require that the UA insert an HTML
                   3506:   element in a particular place, in which case the UA must follow the
                   3507:   same steps except that it must insert or append the new node in the
                   3508:   location specified instead of appending it to the <a href="#current-node">current
                   3509:   node</a>. (This happens in particular during the parsing of
                   3510:   tables with invalid content.)</p>
                   3511: 
                   3512:   <p>If an element created by the <a href="#insert-an-html-element">insert an HTML element</a>
                   3513:   algorithm is a <a href="forms.html#form-associated-element">form-associated element</a>, and the
                   3514:   <a href="#form-element-pointer"><code title="">form</code> element pointer</a> is not null,
                   3515:   and the newly created element doesn't have a <code title="attr-fae-form"><a href="forms.html#attr-fae-form">form</a></code> attribute, the user agent must
                   3516:   <a href="forms.html#concept-form-association" title="concept-form-association">associate</a> the newly
                   3517:   created element with the <code><a href="forms.html#the-form-element">form</a></code> element pointed to by the
                   3518:   <a href="#form-element-pointer"><code title="">form</code> element pointer</a> before
                   3519:   inserting it wherever it is to be inserted.</p>
                   3520: 
                   3521:   <hr><p>When the steps below require the UA to <dfn id="insert-a-foreign-element">insert a foreign
                   3522:   element</dfn> for a token, the UA must first <a href="#create-an-element-for-the-token">create an element
                   3523:   for the token</a> in the given namespace, and then append this
                   3524:   node to the <a href="#current-node">current node</a>, and push it onto the
                   3525:   <a href="#stack-of-open-elements">stack of open elements</a> so that it is the new
                   3526:   <a href="#current-node">current node</a>. If the newly created element has an <code title="">xmlns</code> attribute in the <a href="#xmlns-namespace">XMLNS namespace</a>
                   3527:   whose value is not exactly the same as the element's namespace, that
                   3528:   is a <a href="#parse-error">parse error</a>. Similarly, if the newly created
                   3529:   element has an <code title="">xmlns:xlink</code> attribute in the
                   3530:   <a href="#xmlns-namespace">XMLNS namespace</a> whose value is not the <a href="#xlink-namespace">XLink
                   3531:   Namespace</a>, that is a <a href="#parse-error">parse error</a>.</p>
                   3532: 
                   3533:   <p>When the steps below require the user agent to <dfn id="adjust-mathml-attributes">adjust MathML
                   3534:   attributes</dfn> for a token, then, if the token has an attribute
                   3535:   named <code title="">definitionurl</code>, change its name to <code title="">definitionURL</code> (note the case difference).</p>
                   3536: 
                   3537:   <p>When the steps below require the user agent to <dfn id="adjust-svg-attributes">adjust SVG
                   3538:   attributes</dfn> for a token, then, for each attribute on the token
                   3539:   whose attribute name is one of the ones in the first column of the
                   3540:   following table, change the attribute's name to the name given in
                   3541:   the corresponding cell in the second column. (This fixes the case of
                   3542:   SVG attributes that are not all lowercase.)</p>
                   3543: 
                   3544:   <table><thead><tr><th> Attribute name on token </th><th> Attribute name on element
                   3545:    </th></tr></thead><tbody><tr><td> <code title="">attributename</code> </td><td> <code title="">attributeName</code>
                   3546:     </td></tr><tr><td> <code title="">attributetype</code> </td><td> <code title="">attributeType</code>
                   3547:     </td></tr><tr><td> <code title="">basefrequency</code> </td><td> <code title="">baseFrequency</code>
                   3548:     </td></tr><tr><td> <code title="">baseprofile</code> </td><td> <code title="">baseProfile</code>
                   3549:     </td></tr><tr><td> <code title="">calcmode</code> </td><td> <code title="">calcMode</code>
                   3550:     </td></tr><tr><td> <code title="">clippathunits</code> </td><td> <code title="">clipPathUnits</code>
                   3551:     </td></tr><tr><td> <code title="">contentscripttype</code> </td><td> <code title="">contentScriptType</code>
                   3552:     </td></tr><tr><td> <code title="">contentstyletype</code> </td><td> <code title="">contentStyleType</code>
                   3553:     </td></tr><tr><td> <code title="">diffuseconstant</code> </td><td> <code title="">diffuseConstant</code>
                   3554:     </td></tr><tr><td> <code title="">edgemode</code> </td><td> <code title="">edgeMode</code>
                   3555:     </td></tr><tr><td> <code title="">externalresourcesrequired</code> </td><td> <code title="">externalResourcesRequired</code>
                   3556:     </td></tr><tr><td> <code title="">filterres</code> </td><td> <code title="">filterRes</code>
                   3557:     </td></tr><tr><td> <code title="">filterunits</code> </td><td> <code title="">filterUnits</code>
                   3558:     </td></tr><tr><td> <code title="">glyphref</code> </td><td> <code title="">glyphRef</code>
                   3559:     </td></tr><tr><td> <code title="">gradienttransform</code> </td><td> <code title="">gradientTransform</code>
                   3560:     </td></tr><tr><td> <code title="">gradientunits</code> </td><td> <code title="">gradientUnits</code>
                   3561:     </td></tr><tr><td> <code title="">kernelmatrix</code> </td><td> <code title="">kernelMatrix</code>
                   3562:     </td></tr><tr><td> <code title="">kernelunitlength</code> </td><td> <code title="">kernelUnitLength</code>
                   3563:     </td></tr><tr><td> <code title="">keypoints</code> </td><td> <code title="">keyPoints</code>
                   3564:     </td></tr><tr><td> <code title="">keysplines</code> </td><td> <code title="">keySplines</code>
                   3565:     </td></tr><tr><td> <code title="">keytimes</code> </td><td> <code title="">keyTimes</code>
                   3566:     </td></tr><tr><td> <code title="">lengthadjust</code> </td><td> <code title="">lengthAdjust</code>
                   3567:     </td></tr><tr><td> <code title="">limitingconeangle</code> </td><td> <code title="">limitingConeAngle</code>
                   3568:     </td></tr><tr><td> <code title="">markerheight</code> </td><td> <code title="">markerHeight</code>
                   3569:     </td></tr><tr><td> <code title="">markerunits</code> </td><td> <code title="">markerUnits</code>
                   3570:     </td></tr><tr><td> <code title="">markerwidth</code> </td><td> <code title="">markerWidth</code>
                   3571:     </td></tr><tr><td> <code title="">maskcontentunits</code> </td><td> <code title="">maskContentUnits</code>
                   3572:     </td></tr><tr><td> <code title="">maskunits</code> </td><td> <code title="">maskUnits</code>
                   3573:     </td></tr><tr><td> <code title="">numoctaves</code> </td><td> <code title="">numOctaves</code>
                   3574:     </td></tr><tr><td> <code title="">pathlength</code> </td><td> <code title="">pathLength</code>
                   3575:     </td></tr><tr><td> <code title="">patterncontentunits</code> </td><td> <code title="">patternContentUnits</code>
                   3576:     </td></tr><tr><td> <code title="">patterntransform</code> </td><td> <code title="">patternTransform</code>
                   3577:     </td></tr><tr><td> <code title="">patternunits</code> </td><td> <code title="">patternUnits</code>
                   3578:     </td></tr><tr><td> <code title="">pointsatx</code> </td><td> <code title="">pointsAtX</code>
                   3579:     </td></tr><tr><td> <code title="">pointsaty</code> </td><td> <code title="">pointsAtY</code>
                   3580:     </td></tr><tr><td> <code title="">pointsatz</code> </td><td> <code title="">pointsAtZ</code>
                   3581:     </td></tr><tr><td> <code title="">preservealpha</code> </td><td> <code title="">preserveAlpha</code>
                   3582:     </td></tr><tr><td> <code title="">preserveaspectratio</code> </td><td> <code title="">preserveAspectRatio</code>
                   3583:     </td></tr><tr><td> <code title="">primitiveunits</code> </td><td> <code title="">primitiveUnits</code>
                   3584:     </td></tr><tr><td> <code title="">refx</code> </td><td> <code title="">refX</code>
                   3585:     </td></tr><tr><td> <code title="">refy</code> </td><td> <code title="">refY</code>
                   3586:     </td></tr><tr><td> <code title="">repeatcount</code> </td><td> <code title="">repeatCount</code>
                   3587:     </td></tr><tr><td> <code title="">repeatdur</code> </td><td> <code title="">repeatDur</code>
                   3588:     </td></tr><tr><td> <code title="">requiredextensions</code> </td><td> <code title="">requiredExtensions</code>
                   3589:     </td></tr><tr><td> <code title="">requiredfeatures</code> </td><td> <code title="">requiredFeatures</code>
                   3590:     </td></tr><tr><td> <code title="">specularconstant</code> </td><td> <code title="">specularConstant</code>
                   3591:     </td></tr><tr><td> <code title="">specularexponent</code> </td><td> <code title="">specularExponent</code>
                   3592:     </td></tr><tr><td> <code title="">spreadmethod</code> </td><td> <code title="">spreadMethod</code>
                   3593:     </td></tr><tr><td> <code title="">startoffset</code> </td><td> <code title="">startOffset</code>
                   3594:     </td></tr><tr><td> <code title="">stddeviation</code> </td><td> <code title="">stdDeviation</code>
                   3595:     </td></tr><tr><td> <code title="">stitchtiles</code> </td><td> <code title="">stitchTiles</code>
                   3596:     </td></tr><tr><td> <code title="">surfacescale</code> </td><td> <code title="">surfaceScale</code>
                   3597:     </td></tr><tr><td> <code title="">systemlanguage</code> </td><td> <code title="">systemLanguage</code>
                   3598:     </td></tr><tr><td> <code title="">tablevalues</code> </td><td> <code title="">tableValues</code>
                   3599:     </td></tr><tr><td> <code title="">targetx</code> </td><td> <code title="">targetX</code>
                   3600:     </td></tr><tr><td> <code title="">targety</code> </td><td> <code title="">targetY</code>
                   3601:     </td></tr><tr><td> <code title="">textlength</code> </td><td> <code title="">textLength</code>
                   3602:     </td></tr><tr><td> <code title="">viewbox</code> </td><td> <code title="">viewBox</code>
                   3603:     </td></tr><tr><td> <code title="">viewtarget</code> </td><td> <code title="">viewTarget</code>
                   3604:     </td></tr><tr><td> <code title="">xchannelselector</code> </td><td> <code title="">xChannelSelector</code>
                   3605:     </td></tr><tr><td> <code title="">ychannelselector</code> </td><td> <code title="">yChannelSelector</code>
                   3606:     </td></tr><tr><td> <code title="">zoomandpan</code> </td><td> <code title="">zoomAndPan</code>
                   3607:   </td></tr></tbody></table><p>When the steps below require the user agent to <dfn id="adjust-foreign-attributes">adjust
                   3608:   foreign attributes</dfn> for a token, then, if any of the attributes
                   3609:   on the token match the strings given in the first column of the
                   3610:   following table, let the attribute be a namespaced attribute, with
                   3611:   the prefix being the string given in the corresponding cell in the
                   3612:   second column, the local name being the string given in the
                   3613:   corresponding cell in the third column, and the namespace being the
                   3614:   namespace given in the corresponding cell in the fourth
                   3615:   column. (This fixes the use of namespaced attributes, in particular
                   3616:   <a href="dom.html#attr-xml-lang" title="attr-xml-lang"><code title="">lang</code> attributes in
                   3617:   the <span>XML namespace</span></a>.)</p>
                   3618: 
                   3619:   <table><thead><tr><th> Attribute name </th><th> Prefix </th><th> Local name </th><th> Namespace
                   3620:    </th></tr></thead><tbody><tr><td> <code title="">xlink:actuate</code> </td><td> <code title="">xlink</code> </td><td> <code title="">actuate</code> </td><td> <a href="#xlink-namespace">XLink namespace</a>
                   3621:     </td></tr><tr><td> <code title="">xlink:arcrole</code> </td><td> <code title="">xlink</code> </td><td> <code title="">arcrole</code> </td><td> <a href="#xlink-namespace">XLink namespace</a>
                   3622:     </td></tr><tr><td> <code title="">xlink:href</code> </td><td> <code title="">xlink</code> </td><td> <code title="">href</code> </td><td> <a href="#xlink-namespace">XLink namespace</a>
                   3623:     </td></tr><tr><td> <code title="">xlink:role</code> </td><td> <code title="">xlink</code> </td><td> <code title="">role</code> </td><td> <a href="#xlink-namespace">XLink namespace</a>
                   3624:     </td></tr><tr><td> <code title="">xlink:show</code> </td><td> <code title="">xlink</code> </td><td> <code title="">show</code> </td><td> <a href="#xlink-namespace">XLink namespace</a>
                   3625:     </td></tr><tr><td> <code title="">xlink:title</code> </td><td> <code title="">xlink</code> </td><td> <code title="">title</code> </td><td> <a href="#xlink-namespace">XLink namespace</a>
                   3626:     </td></tr><tr><td> <code title="">xlink:type</code> </td><td> <code title="">xlink</code> </td><td> <code title="">type</code> </td><td> <a href="#xlink-namespace">XLink namespace</a>
                   3627:     </td></tr><tr><td> <code title="">xml:base</code> </td><td> <code title="">xml</code> </td><td> <code title="">base</code> </td><td> <a href="#xml-namespace">XML namespace</a> <!-- attr-xml-base -->
                   3628:     </td></tr><tr><td> <code title="">xml:lang</code> </td><td> <code title="">xml</code> </td><td> <code title="">lang</code> </td><td> <a href="#xml-namespace">XML namespace</a>
                   3629:     </td></tr><tr><td> <code title="">xml:space</code> </td><td> <code title="">xml</code> </td><td> <code title="">space</code> </td><td> <a href="#xml-namespace">XML namespace</a>
                   3630:     </td></tr><tr><td> <code title="">xmlns</code> </td><td> (none) </td><td> <code title="">xmlns</code> </td><td> <a href="#xmlns-namespace">XMLNS namespace</a>
                   3631:     </td></tr><tr><td> <code title="">xmlns:xlink</code> </td><td> <code title="">xmlns</code> </td><td> <code title="">xlink</code> </td><td> <a href="#xmlns-namespace">XMLNS namespace</a>
1.91      mike     3632:   </td></tr></tbody></table><hr><p>The <dfn id="generic-raw-text-element-parsing-algorithm">generic raw text element parsing algorithm</dfn> and the
1.1       mike     3633:   <dfn id="generic-rcdata-element-parsing-algorithm">generic RCDATA element parsing algorithm</dfn> consist of the
                   3634:   following steps. These algorithms are always invoked in response to
                   3635:   a start tag token.</p>
                   3636: 
                   3637:   <ol><li><p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p></li>
                   3638: 
1.91      mike     3639:    <li><p>If the algorithm that was invoked is the <a href="#generic-raw-text-element-parsing-algorithm">generic raw
                   3640:    text element parsing algorithm</a>, switch the tokenizer's
                   3641:    <a href="#content-model-flag">content model flag</a> to the RAWTEXT state; otherwise the
1.1       mike     3642:    algorithm invoked was the <a href="#generic-rcdata-element-parsing-algorithm">generic RCDATA element parsing
                   3643:    algorithm</a>, switch the tokenizer's <a href="#content-model-flag">content model
                   3644:    flag</a> to the RCDATA state.</p></li>
                   3645: 
                   3646:    <li><p>Let the <a href="#original-insertion-mode">original insertion mode</a> be the current
                   3647:    <a href="#insertion-mode">insertion mode</a>.</p>
                   3648: 
1.91      mike     3649:    </li><li><p>Then, switch the <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-incdata" title="insertion mode: in RAWTEXT/RCDATA">in
                   3650:    RAWTEXT/RCDATA</a>".</p></li>
1.1       mike     3651: 
                   3652:   </ol><h5 id="closing-elements-that-have-implied-end-tags"><span class="secno">9.2.5.2 </span>Closing elements that have implied end tags</h5>
                   3653: 
                   3654:   <p>When the steps below require the UA to <dfn id="generate-implied-end-tags">generate implied end
                   3655:   tags</dfn>, then, while the <a href="#current-node">current node</a> is a
                   3656:   <code><a href="semantics.html#the-dd-element">dd</a></code> element, a <code><a href="semantics.html#the-dt-element">dt</a></code> element, an
                   3657:   <code><a href="semantics.html#the-li-element">li</a></code> element, an <code><a href="forms.html#the-option-element">option</a></code> element, an
                   3658:   <code><a href="forms.html#the-optgroup-element">optgroup</a></code> element, a <code><a href="semantics.html#the-p-element">p</a></code> element, an
                   3659:   <code><a href="text-level-semantics.html#the-rp-element">rp</a></code> element, or an <code><a href="text-level-semantics.html#the-rt-element">rt</a></code> element, the UA must
                   3660:   pop the <a href="#current-node">current node</a> off the <a href="#stack-of-open-elements">stack of open
                   3661:   elements</a>.</p>
                   3662: 
                   3663:   <p>If a step requires the UA to generate implied end tags but lists
                   3664:   an element to exclude from the process, then the UA must perform the
                   3665:   above steps as if that element was not in the above list.</p>
                   3666: 
                   3667: 
                   3668:   <h5 id="foster-parenting"><span class="secno">9.2.5.3 </span>Foster parenting</h5>
                   3669: 
                   3670:   <p>Foster parenting happens when content is misnested in tables.</p>
                   3671: 
                   3672:   <p>When a node <var title="">node</var> is to be <dfn id="foster-parent" title="foster
                   3673:   parent">foster parented</dfn>, the node <var title="">node</var>
                   3674:   must be inserted into the <i><a href="#foster-parent-element">foster parent element</a></i>.</p>
                   3675: 
                   3676:   <p>The <dfn id="foster-parent-element">foster parent element</dfn> is the parent element of the
                   3677:   last <code><a href="tabular-data.html#the-table-element">table</a></code> element in the <a href="#stack-of-open-elements">stack of open
                   3678:   elements</a>, if there is a <code><a href="tabular-data.html#the-table-element">table</a></code> element and it has
                   3679:   such a parent element. If there is no <code><a href="tabular-data.html#the-table-element">table</a></code> element in
                   3680:   the <a href="#stack-of-open-elements">stack of open elements</a> (<a href="#fragment-case">fragment
                   3681:   case</a>), then the <i><a href="#foster-parent-element">foster parent element</a></i> is the first
                   3682:   element in the <a href="#stack-of-open-elements">stack of open elements</a> (the
                   3683:   <code><a href="semantics.html#the-html-element">html</a></code> element). Otherwise, if there is a
                   3684:   <code><a href="tabular-data.html#the-table-element">table</a></code> element in the <a href="#stack-of-open-elements">stack of open
                   3685:   elements</a>, but the last <code><a href="tabular-data.html#the-table-element">table</a></code> element in the
                   3686:   <a href="#stack-of-open-elements">stack of open elements</a> has no parent, or its parent
                   3687:   node is not an element, then the <i><a href="#foster-parent-element">foster parent element</a></i> is
                   3688:   the element before the last <code><a href="tabular-data.html#the-table-element">table</a></code> element in the
                   3689:   <a href="#stack-of-open-elements">stack of open elements</a>.</p>
                   3690: 
                   3691:   <p>If the <i><a href="#foster-parent-element">foster parent element</a></i> is the parent element of the
                   3692:   last <code><a href="tabular-data.html#the-table-element">table</a></code> element in the <a href="#stack-of-open-elements">stack of open
                   3693:   elements</a>, then <var title="">node</var> must be inserted
                   3694:   immediately <em>before</em> the last <code><a href="tabular-data.html#the-table-element">table</a></code> element in
                   3695:   the <a href="#stack-of-open-elements">stack of open elements</a> in the <i><a href="#foster-parent-element">foster parent
                   3696:   element</a></i>; otherwise, <var title="">node</var> must be
                   3697:   <em>appended</em> to the <i><a href="#foster-parent-element">foster parent element</a></i>.</p>
                   3698: 
                   3699: 
                   3700: 
                   3701:   <h5 id="the-initial-insertion-mode"><span class="secno">9.2.5.4 </span>The "<dfn title="insertion mode: initial">initial</dfn>" insertion mode</h5>
                   3702: 
                   3703:   <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#the-initial-insertion-mode" title="insertion
                   3704:   mode: initial">initial</a>", tokens must be handled as follows:</p>
                   3705: 
                   3706:   <dl class="switch"><dt>A character token that is one of U+0009 CHARACTER
                   3707:    TABULATION, U+000A LINE FEED (LF), U+000C FORM FEED (FF),
                   3708:    <!--U+000D CARRIAGE RETURN (CR),--> or U+0020 SPACE</dt>
                   3709:    <dd>
                   3710:     <p>Ignore the token.</p>
                   3711:    </dd>
                   3712: 
                   3713:    <dt>A comment token</dt>
                   3714:    <dd>
                   3715:     <p>Append a <code>Comment</code> node to the <code>Document</code>
                   3716:     object with the <code title="">data</code> attribute set to the
                   3717:     data given in the comment token.</p>
                   3718:    </dd>
                   3719: 
                   3720:    <dt>A DOCTYPE token</dt>
                   3721:    <dd>
                   3722: 
                   3723:     <p>If the DOCTYPE token's name is not a
                   3724:     <a href="infrastructure.html#case-sensitive">case-sensitive</a> match for the string "<code title="">html</code>", or the token's public identifier is not
                   3725:     missing, or the token's system identifier is neither missing nor a
                   3726:     <a href="infrastructure.html#case-sensitive">case-sensitive</a> match for the string
                   3727:     "<code>about:legacy-compat</code>", and none of the sets of
                   3728:     conditions in the following list are matched, then there is a
                   3729:     <a href="#parse-error">parse error</a>. If one of the sets of conditions in the
                   3730:     following list is matched, then there is an <dfn id="obsolete-permitted-doctype">obsolete
                   3731:     permitted DOCTYPE</dfn>.</p>
                   3732: 
                   3733:     <ul><!-- only things that trigger no-quirks mode and were valid in
                   3734:      some other spec are allowed in this list --><li>The DOCTYPE token's name is an <a href="infrastructure.html#ascii-case-insensitive">ASCII
1.98      mike     3735:      case-insensitive</a> match for the string "<code title="">html</code>", the token's public identifier is the
1.1       mike     3736:      <a href="infrastructure.html#case-sensitive">case-sensitive</a> string "<code title="">-//W3C//DTD&#160;HTML&#160;4.0//EN</code>", and the
                   3737:      token's system identifier is either missing or the
                   3738:      <a href="infrastructure.html#case-sensitive">case-sensitive</a> string "<code title="">http://www.w3.org/TR/REC-html40/strict.dtd</code>".</li>
                   3739: 
                   3740:      <li>The DOCTYPE token's name is an <a href="infrastructure.html#ascii-case-insensitive">ASCII
1.98      mike     3741:      case-insensitive</a> match for the string "<code title="">html</code>", the token's public identifier is the
1.1       mike     3742:      <a href="infrastructure.html#case-sensitive">case-sensitive</a> string "<code title="">-//W3C//DTD&#160;HTML&#160;4.01//EN</code>", and the
                   3743:      token's system identifier is either missing or the
                   3744:      <a href="infrastructure.html#case-sensitive">case-sensitive</a> string "<code title="">http://www.w3.org/TR/html4/strict.dtd</code>".</li>
                   3745: 
                   3746:      <li>The DOCTYPE token's name is an <a href="infrastructure.html#ascii-case-insensitive">ASCII
1.98      mike     3747:      case-insensitive</a> match for the string "<code title="">html</code>", the token's public identifier is the
1.1       mike     3748:      <a href="infrastructure.html#case-sensitive">case-sensitive</a> string "<code title="">-//W3C//DTD&#160;XHTML&#160;1.0&#160;Strict//EN</code>",
                   3749:      and the token's system identifier is the
                   3750:      <a href="infrastructure.html#case-sensitive">case-sensitive</a> string "<code title="">http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd</code>".</li>
                   3751: 
                   3752:      <li>The DOCTYPE token's name is an <a href="infrastructure.html#ascii-case-insensitive">ASCII
1.98      mike     3753:      case-insensitive</a> match for the string "<code title="">html</code>", the token's public identifier is the
1.1       mike     3754:      <a href="infrastructure.html#case-sensitive">case-sensitive</a> string "<code title="">-//W3C//DTD&#160;XHTML&#160;1.1//EN</code>", and the
                   3755:      token's system identifier is the <a href="infrastructure.html#case-sensitive">case-sensitive</a>
                   3756:      string "<code title="">http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd</code>".</li>
                   3757: 
                   3758:     </ul><p>Conformance checkers may, based on the values (including
                   3759:     presence or lack thereof) of the DOCTYPE token's name, public
                   3760:     identifier, or system identifier, switch to a conformance checking
                   3761:     mode for another language (e.g. based on the DOCTYPE token a
                   3762:     conformance checker could recognize that the document is an
                   3763:     HTML&#160;4-era document, and defer to an HTML&#160;4 conformance
                   3764:     checker.)</p>
                   3765: 
                   3766:     <p>Append a <code>DocumentType</code> node to the
                   3767:     <code>Document</code> node, with the <code title="">name</code>
                   3768:     attribute set to the name given in the DOCTYPE token, or the empty
                   3769:     string if the name was missing; the <code title="">publicId</code>
                   3770:     attribute set to the public identifier given in the DOCTYPE token,
                   3771:     or the empty string if the public identifier was missing; the
                   3772:     <code title="">systemId</code> attribute set to the system
                   3773:     identifier given in the DOCTYPE token, or the empty string if the
                   3774:     system identifier was missing; and the other attributes specific
                   3775:     to <code>DocumentType</code> objects set to null and empty lists
                   3776:     as appropriate. Associate the <code>DocumentType</code> node with
                   3777:     the <code>Document</code> object so that it is returned as the
                   3778:     value of the <code title="">doctype</code> attribute of the
                   3779:     <code>Document</code> object.</p>
                   3780: 
                   3781:     <p id="quirks-mode-doctypes">Then, if the DOCTYPE token matches
                   3782:     one of the conditions in the following list, then set the
                   3783:     <code>Document</code> to <a href="dom.html#quirks-mode">quirks mode</a>:</p>
                   3784: 
                   3785:     <ul class="brief"><li> The <i>force-quirks flag</i> is set to <i>on</i>. </li>
                   3786:      <li> The name is set to anything other than "<code title="">HTML</code>". </li>
                   3787:      <li> The public identifier starts with: "<code title="">+//Silmaril//dtd html Pro v0r11 19970101//<!--EN--></code>" </li>
                   3788:      <li> The public identifier starts with: "<code title="">-//AdvaSoft Ltd//DTD HTML 3.0 asWedit + extensions//<!--EN--></code>" </li>
                   3789:      <li> The public identifier starts with: "<code title="">-//AS//DTD HTML 3.0 asWedit + extensions//<!--EN--></code>" </li>
                   3790:      <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML 2.0 Level 1//<!--EN--></code>" </li>
                   3791:      <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML 2.0 Level 2//<!--EN--></code>" </li>
                   3792:      <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML 2.0 Strict Level 1//<!--EN--></code>" </li>
                   3793:      <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML 2.0 Strict Level 2//<!--EN--></code>" </li>
                   3794:      <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML 2.0 Strict//<!--EN--></code>" </li>
                   3795:      <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML 2.0//<!--EN--></code>" </li>
                   3796:      <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML 2.1E//<!--EN--></code>" </li>
                   3797:      <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML 3.0//<!--EN--></code>" </li>
                   3798:    <!--<li> The public identifier is set to: "<code title="">-//IETF//DTD HTML 3.0//EN//</code>" </li>-->
                   3799:      <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML 3.2 Final//<!--EN--></code>" </li>
                   3800:      <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML 3.2//<!--EN--></code>" </li>
                   3801:      <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML 3//<!--EN--></code>" </li>
                   3802:      <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML Level 0//<!--EN--></code>" </li>
                   3803:    <!--<li> The public identifier is set to: "<code title="">-//IETF//DTD HTML Level 0//EN//2.0</code>" </li>-->
                   3804:      <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML Level 1//<!--EN--></code>" </li>
                   3805:    <!--<li> The public identifier is set to: "<code title="">-//IETF//DTD HTML Level 1//EN//2.0</code>" </li>-->
                   3806:      <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML Level 2//<!--EN--></code>" </li>
                   3807:    <!--<li> The public identifier is set to: "<code title="">-//IETF//DTD HTML Level 2//EN//2.0</code>" </li>-->
                   3808:      <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML Level 3//<!--EN--></code>" </li>
                   3809:    <!--<li> The public identifier is set to: "<code title="">-//IETF//DTD HTML Level 3//EN//3.0</code>" </li>-->
                   3810:      <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML Strict Level 0//<!--EN--></code>" </li>
                   3811:    <!--<li> The public identifier is set to: "<code title="">-//IETF//DTD HTML Strict Level 0//EN//2.0</code>" </li>-->
                   3812:      <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML Strict Level 1//<!--EN--></code>" </li>
                   3813:    <!--<li> The public identifier is set to: "<code title="">-//IETF//DTD HTML Strict Level 1//EN//2.0</code>" </li>-->
                   3814:      <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML Strict Level 2//<!--EN--></code>" </li>
                   3815:    <!--<li> The public identifier is set to: "<code title="">-//IETF//DTD HTML Strict Level 2//EN//2.0</code>" </li>-->
                   3816:      <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML Strict Level 3//<!--EN--></code>" </li>
                   3817:    <!--<li> The public identifier is set to: "<code title="">-//IETF//DTD HTML Strict Level 3//EN//3.0</code>" </li>-->
                   3818:      <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML Strict//<!--EN--></code>" </li>
                   3819:    <!--<li> The public identifier is set to: "<code title="">-//IETF//DTD HTML Strict//EN//2.0</code>" </li>-->
                   3820:    <!--<li> The public identifier is set to: "<code title="">-//IETF//DTD HTML Strict//EN//3.0</code>" </li>-->
                   3821:      <li> The public identifier starts with: "<code title="">-//IETF//DTD HTML//<!--EN--></code>" </li>
                   3822:    <!--<li> The public identifier is set to: "<code title="">-//IETF//DTD HTML//EN//2.0</code>" </li>-->
                   3823:    <!--<li> The public identifier is set to: "<code title="">-//IETF//DTD HTML//EN//3.0</code>" </li>-->
                   3824:      <li> The public identifier starts with: "<code title="">-//Metrius//DTD Metrius Presentational//<!--EN--></code>" </li>
                   3825:      <li> The public identifier starts with: "<code title="">-//Microsoft//DTD Internet Explorer 2.0 HTML Strict//<!--EN--></code>" </li>
                   3826:      <li> The public identifier starts with: "<code title="">-//Microsoft//DTD Internet Explorer 2.0 HTML//<!--EN--></code>" </li>
                   3827:      <li> The public identifier starts with: "<code title="">-//Microsoft//DTD Internet Explorer 2.0 Tables//<!--EN--></code>" </li>
                   3828:      <li> The public identifier starts with: "<code title="">-//Microsoft//DTD Internet Explorer 3.0 HTML Strict//<!--EN--></code>" </li>
                   3829:      <li> The public identifier starts with: "<code title="">-//Microsoft//DTD Internet Explorer 3.0 HTML//<!--EN--></code>" </li>
                   3830:      <li> The public identifier starts with: "<code title="">-//Microsoft//DTD Internet Explorer 3.0 Tables//<!--EN--></code>" </li>
                   3831:      <li> The public identifier starts with: "<code title="">-//Netscape Comm. Corp.//DTD HTML//<!--EN--></code>" </li>
                   3832:      <li> The public identifier starts with: "<code title="">-//Netscape Comm. Corp.//DTD Strict HTML//<!--EN--></code>" </li>
                   3833:      <li> The public identifier starts with: "<code title="">-//O'Reilly and Associates//DTD HTML 2.0//<!--EN--></code>" </li>
                   3834:      <li> The public identifier starts with: "<code title="">-//O'Reilly and Associates//DTD HTML Extended 1.0//<!--EN--></code>" </li>
                   3835:      <li> The public identifier starts with: "<code title="">-//O'Reilly and Associates//DTD HTML Extended Relaxed 1.0//<!--EN--></code>" </li>
                   3836:      <li> The public identifier starts with: "<code title="">-//SoftQuad Software//DTD HoTMetaL PRO 6.0::19990601::extensions to HTML 4.0//<!--EN--></code>" </li>
                   3837:      <li> The public identifier starts with: "<code title="">-//SoftQuad//DTD HoTMetaL PRO 4.0::19971010::extensions to HTML 4.0//<!--EN--></code>" </li>
                   3838:      <li> The public identifier starts with: "<code title="">-//Spyglass//DTD HTML 2.0 Extended//<!--EN--></code>" </li>
                   3839:      <li> The public identifier starts with: "<code title="">-//SQ//DTD HTML 2.0 HoTMetaL + extensions//<!--EN--></code>" </li>
                   3840:      <li> The public identifier starts with: "<code title="">-//Sun Microsystems Corp.//DTD HotJava HTML//<!--EN--></code>" </li>
                   3841:      <li> The public identifier starts with: "<code title="">-//Sun Microsystems Corp.//DTD HotJava Strict HTML//<!--EN--></code>" </li>
                   3842:      <li> The public identifier starts with: "<code title="">-//W3C//DTD HTML 3 1995-03-24//<!--EN--></code>" </li>
                   3843:      <li> The public identifier starts with: "<code title="">-//W3C//DTD HTML 3.2 Draft//<!--EN--></code>" </li>
                   3844:      <li> The public identifier starts with: "<code title="">-//W3C//DTD HTML 3.2 Final//<!--EN--></code>" </li>
                   3845:      <li> The public identifier starts with: "<code title="">-//W3C//DTD HTML 3.2//<!--EN--></code>" </li>
                   3846:      <li> The public identifier starts with: "<code title="">-//W3C//DTD HTML 3.2S Draft//<!--EN--></code>" </li>
                   3847:      <li> The public identifier starts with: "<code title="">-//W3C//DTD HTML 4.0 Frameset//<!--EN--></code>" </li>
                   3848:      <li> The public identifier starts with: "<code title="">-//W3C//DTD HTML 4.0 Transitional//<!--EN--></code>" </li>
                   3849:      <li> The public identifier starts with: "<code title="">-//W3C//DTD HTML Experimental 19960712//<!--EN--></code>" </li>
                   3850:      <li> The public identifier starts with: "<code title="">-//W3C//DTD HTML Experimental 970421//<!--EN--></code>" </li>
                   3851:      <li> The public identifier starts with: "<code title="">-//W3C//DTD W3 HTML//<!--EN--></code>" </li>
                   3852:      <li> The public identifier starts with: "<code title="">-//W3O//DTD W3 HTML 3.0//<!--EN--></code>" </li>
                   3853:    <!--<li> The public identifier is set to: "<code title="">-//W3O//DTD W3 HTML 3.0//EN//</code>" </li>-->
                   3854:      <li> The public identifier is set to: "<code title="">-//W3O//DTD W3 HTML Strict 3.0//EN//</code>" </li>
                   3855:      <li> The public identifier starts with: "<code title="">-//WebTechs//DTD Mozilla HTML 2.0//<!--EN--></code>" </li>
                   3856:      <li> The public identifier starts with: "<code title="">-//WebTechs//DTD Mozilla HTML//<!--EN--></code>" </li>
                   3857:      <li> The public identifier is set to: "<code title="">-/W3C/DTD HTML 4.0 Transitional/EN</code>" </li>
                   3858:      <li> The public identifier is set to: "<code title="">HTML</code>" </li>
                   3859:      <li> The system identifier is set to: "<code title="">http://www.ibm.com/data/dtd/v11/ibmxhtml1-transitional.dtd</code>" </li>
                   3860:      <li> The system identifier is missing and the public identifier starts with: "<code title="">-//W3C//DTD HTML 4.01 Frameset//<!--EN--></code>" </li>
                   3861:      <li> The system identifier is missing and the public identifier starts with: "<code title="">-//W3C//DTD HTML 4.01 Transitional//<!--EN--></code>" </li>
                   3862:     </ul><p>Otherwise, if the DOCTYPE token matches one of the conditions
                   3863:     in the following list, then set the <code>Document</code> to
                   3864:     <a href="dom.html#limited-quirks-mode">limited quirks mode</a>:</p>
                   3865: 
                   3866:     <ul class="brief"><li> The public identifier starts with: "<code title="">-//W3C//DTD XHTML 1.0 Frameset//<!--EN--></code>" </li>
                   3867:      <li> The public identifier starts with: "<code title="">-//W3C//DTD XHTML 1.0 Transitional//<!--EN--></code>" </li>
                   3868:      <li> The system identifier is not missing and the public identifier starts with: "<code title="">-//W3C//DTD HTML 4.01 Frameset//<!--EN--></code>" </li>
                   3869:      <li> The system identifier is not missing and the public identifier starts with: "<code title="">-//W3C//DTD HTML 4.01 Transitional//<!--EN--></code>" </li>
                   3870:     </ul><p>The name, system identifier, and public identifier strings must
                   3871:     be compared to the values given in the lists above in an
                   3872:     <a href="infrastructure.html#ascii-case-insensitive">ASCII case-insensitive</a> manner. A system identifier
                   3873:     whose value is the empty string is not considered missing for the
                   3874:     purposes of the conditions above.</p>
                   3875: 
                   3876:     <p>Then, switch the <a href="#insertion-mode">insertion mode</a> to "<a href="#the-before-html-insertion-mode" title="insertion mode: before html">before html</a>".</p>
                   3877: 
                   3878:    </dd>
                   3879: 
                   3880:    <dt>Anything else</dt>
                   3881:    <dd>
                   3882: 
                   3883:     <p><a href="#parse-error">Parse error</a>.</p>
                   3884: 
                   3885:     <p>Set the <code>Document</code> to <a href="dom.html#quirks-mode">quirks mode</a>.</p>
                   3886: 
                   3887:     <p>Switch the <a href="#insertion-mode">insertion mode</a> to "<a href="#the-before-html-insertion-mode" title="insertion mode: before html">before html</a>", then
                   3888:     reprocess the current token.</p>
                   3889: 
                   3890:    </dd>
                   3891: 
                   3892:   </dl><h5 id="the-before-html-insertion-mode"><span class="secno">9.2.5.5 </span>The "<dfn title="insertion mode: before html">before html</dfn>" insertion mode</h5>
                   3893: 
                   3894:   <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#the-before-html-insertion-mode" title="insertion
                   3895:   mode: before html">before html</a>", tokens must be handled as follows:</p>
                   3896: 
                   3897:   <dl class="switch"><dt>A DOCTYPE token</dt>
                   3898:    <dd>
                   3899:     <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
                   3900:    </dd>
                   3901: 
                   3902:    <dt>A comment token</dt>
                   3903:    <dd>
                   3904:     <p>Append a <code>Comment</code> node to the <code>Document</code>
                   3905:     object with the <code title="">data</code> attribute set to the
                   3906:     data given in the comment token.</p>
                   3907:    </dd>
                   3908: 
                   3909:    <dt>A character token that is one of U+0009 CHARACTER
                   3910:    TABULATION, U+000A LINE FEED (LF), U+000C FORM FEED (FF),
                   3911:    <!--U+000D CARRIAGE RETURN (CR),--> or U+0020 SPACE</dt>
                   3912:    <dd>
                   3913:     <p>Ignore the token.</p>
                   3914:    </dd>
                   3915: 
                   3916:    <dt>A start tag whose tag name is "html"</dt>
                   3917:    <dd>
                   3918: 
                   3919:     <p><a href="#create-an-element-for-the-token">Create an element for the token</a> in the <a href="#html-namespace-0">HTML
                   3920:     namespace</a>. Append it to the <code>Document</code>
                   3921:     object. Put this element in the <a href="#stack-of-open-elements">stack of open
                   3922:     elements</a>.</p>
                   3923: 
                   3924:     <p id="parser-appcache">If the <code>Document</code> is being
                   3925:     loaded as part of <a href="history.html#navigate" title="navigate">navigation</a> of a
                   3926:     <a href="browsers.html#browsing-context">browsing context</a>, then: if the newly created element
                   3927:     has a <code title="attr-html-manifest"><a href="semantics.html#attr-html-manifest">manifest</a></code> attribute,
                   3928:     then <a href="infrastructure.html#resolve-a-url" title="resolve a url">resolve</a> the value of that
                   3929:     attribute to an <a href="infrastructure.html#absolute-url">absolute URL</a>, relative to the newly
                   3930:     created element, and if that is successful, run the <a href="offline.html#concept-appcache-init" title="concept-appcache-init">application cache selection
1.29      mike     3931:     algorithm</a> with the resulting <a href="infrastructure.html#absolute-url">absolute URL</a> with
                   3932:     any <a href="infrastructure.html#url-fragment" title="url-fragment">&lt;fragment&gt;</a> component
                   3933:     removed; otherwise, if there is no such attribute or resolving it
                   3934:     fails, run the <a href="offline.html#concept-appcache-init" title="concept-appcache-init">application
                   3935:     cache selection algorithm</a> with no manifest. The algorithm
                   3936:     must be passed the <code>Document</code> object.</p>
1.1       mike     3937: 
                   3938:     <p>Switch the <a href="#insertion-mode">insertion mode</a> to "<a href="#the-before-head-insertion-mode" title="insertion mode: before head">before head</a>".</p>
                   3939: 
                   3940:    </dd>
                   3941: 
                   3942:    <dt>Anything else</dt>
                   3943:    <dd>
                   3944: 
                   3945:     <p>Create an <code><a href="semantics.html#the-html-element">html</a></code> element. Append it to the
                   3946:     <code>Document</code> object. Put this element in the <a href="#stack-of-open-elements">stack
                   3947:     of open elements</a>.</p>
                   3948: 
                   3949:     <p>If the <code>Document</code> is being loaded as part of <a href="history.html#navigate" title="navigate">navigation</a> of a <a href="browsers.html#browsing-context">browsing
                   3950:     context</a>, then: run the <a href="offline.html#concept-appcache-init" title="concept-appcache-init">application cache selection
                   3951:     algorithm</a> with no manifest, passing it the
                   3952:     <code>Document</code> object.</p>
                   3953: 
                   3954:     <p>Switch the <a href="#insertion-mode">insertion mode</a> to "<a href="#the-before-head-insertion-mode" title="insertion mode: before head">before head</a>", then
                   3955:     reprocess the current token.</p>
                   3956: 
                   3957:     <p class="XXX">Should probably make end tags be ignored, so
                   3958:     that "&lt;/head&gt;&lt;!-- --&gt;&lt;html&gt;" puts the comment before the
                   3959:     root node (or should we?)</p>
                   3960: 
                   3961:    </dd>
                   3962: 
                   3963:   </dl><p>The root element can end up being removed from the
                   3964:   <code>Document</code> object, e.g. by scripts; nothing in particular
                   3965:   happens in such cases, content continues being appended to the nodes
                   3966:   as described in the next section.</p>
                   3967: 
                   3968: 
                   3969:   <h5 id="the-before-head-insertion-mode"><span class="secno">9.2.5.6 </span>The "<dfn title="insertion mode: before head">before head</dfn>" insertion mode</h5>
                   3970: 
                   3971:   <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#the-before-head-insertion-mode" title="insertion
                   3972:   mode: before head">before head</a>", tokens must be handled as follows:</p>
                   3973: 
                   3974:   <dl class="switch"><dt>A character token that is one of U+0009 CHARACTER
                   3975:    TABULATION, U+000A LINE FEED (LF), U+000C FORM FEED (FF),
                   3976:    <!--U+000D CARRIAGE RETURN (CR),--> or U+0020 SPACE</dt>
                   3977:    <dd>
                   3978:     <p>Ignore the token.</p> <!-- :-( -->
                   3979:    </dd>
                   3980: 
                   3981:    <dt>A comment token</dt>
                   3982:    <dd>
                   3983:     <p>Append a <code>Comment</code> node to the <a href="#current-node">current
                   3984:     node</a> with the <code title="">data</code> attribute set to
                   3985:     the data given in the comment token.</p>
                   3986:    </dd>
                   3987: 
                   3988:    <dt>A DOCTYPE token</dt>
                   3989:    <dd>
                   3990:     <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
                   3991:    </dd>
                   3992: 
                   3993:    <dt>A start tag whose tag name is "html"</dt>
                   3994:    <dd>
                   3995:     <p>Process the token <a href="#using-the-rules-for">using the rules for</a> the "<a href="#parsing-main-inbody" title="insertion mode: in body">in body</a>" <a href="#insertion-mode">insertion
                   3996:     mode</a>.</p>
                   3997:    </dd>
                   3998: 
                   3999:    <dt>A start tag whose tag name is "head"</dt>
                   4000:    <dd>
                   4001: 
                   4002:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
                   4003: 
                   4004:     <p>Set the <a href="#head-element-pointer"><code title="">head</code> element pointer</a>
                   4005:     to the newly created <code><a href="semantics.html#the-head-element">head</a></code> element.</p>
                   4006: 
                   4007:     <p>Switch the <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-inhead" title="insertion mode: in head">in head</a>".</p>
                   4008: 
                   4009:    </dd>
                   4010: 
                   4011:    <dt>An end tag whose tag name is one of: "head", "body", "html", "br"</dt>
                   4012:    <dd>
                   4013: 
                   4014:     <p>Act as if a start tag token with the tag name "head" and no
                   4015:     attributes had been seen, then reprocess the current token.</p>
                   4016: 
                   4017:    </dd>
                   4018: 
                   4019:    <dt>Any other end tag</dt>
                   4020:    <dd>
                   4021: 
                   4022:     <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
                   4023: 
                   4024:    </dd>
                   4025: 
                   4026:    <dt>Anything else</dt>
                   4027:    <dd>
                   4028: 
                   4029:     <p>Act as if a start tag token with the tag name "head" and no
                   4030:     attributes had been seen, then reprocess the current
                   4031:     token.</p>
                   4032: 
                   4033:    </dd>
                   4034: 
                   4035:   </dl><h5 id="parsing-main-inhead"><span class="secno">9.2.5.7 </span>The "<dfn title="insertion mode: in head">in head</dfn>" insertion mode</h5>
                   4036: 
                   4037:   <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-inhead" title="insertion
                   4038:   mode: in head">in head</a>", tokens must be handled as follows:</p>
                   4039: 
                   4040:   <dl class="switch"><dt>A character token that is one of U+0009 CHARACTER
                   4041:    TABULATION, U+000A LINE FEED (LF), U+000C FORM FEED (FF),
                   4042:    <!--U+000D CARRIAGE RETURN (CR),--> or U+0020 SPACE</dt>
                   4043:    <dd>
                   4044:     <p><a href="#insert-a-character" title="insert a character">Insert the character</a> into
                   4045:     the <a href="#current-node">current node</a>.</p>
                   4046:    </dd>
                   4047: 
                   4048:    <dt>A comment token</dt>
                   4049:    <dd>
                   4050:     <p>Append a <code>Comment</code> node to the <a href="#current-node">current
                   4051:     node</a> with the <code title="">data</code> attribute set to
                   4052:     the data given in the comment token.</p>
                   4053:    </dd>
                   4054: 
                   4055:    <dt>A DOCTYPE token</dt>
                   4056:    <dd>
                   4057:     <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
                   4058:    </dd>
                   4059: 
                   4060:    <dt>A start tag whose tag name is "html"</dt>
                   4061:    <dd>
                   4062:     <p>Process the token <a href="#using-the-rules-for">using the rules for</a> the "<a href="#parsing-main-inbody" title="insertion mode: in body">in body</a>" <a href="#insertion-mode">insertion
                   4063:     mode</a>.</p>
                   4064:    </dd>
                   4065: 
                   4066:    <dt>A start tag whose tag name is one of: "base", "command",
                   4067:    "link"</dt>
                   4068:    <dd>
                   4069: 
                   4070:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token. Immediately
                   4071:     pop the <a href="#current-node">current node</a> off the <a href="#stack-of-open-elements">stack of open
                   4072:     elements</a>.</p>
                   4073: 
                   4074:     <p><a href="#acknowledge-self-closing-flag" title="acknowledge self-closing flag">Acknowledge the
                   4075:     token's <i>self-closing flag</i></a>, if it is set.</p>
                   4076: 
                   4077:    </dd>
                   4078: 
                   4079:    <dt>A start tag whose tag name is "meta"</dt>
                   4080:    <dd>
                   4081: 
                   4082:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token. Immediately
                   4083:     pop the <a href="#current-node">current node</a> off the <a href="#stack-of-open-elements">stack of open
                   4084:     elements</a>.</p>
                   4085: 
                   4086:     <p><a href="#acknowledge-self-closing-flag" title="acknowledge self-closing flag">Acknowledge the
                   4087:     token's <i>self-closing flag</i></a>, if it is set.</p>
                   4088: 
                   4089:     <p id="meta-charset-during-parse">If the element has a <code title="attr-meta-charset"><a href="semantics.html#attr-meta-charset">charset</a></code> attribute, and its
                   4090:     value is a supported encoding, and the <a href="#concept-encoding-confidence" title="concept-encoding-confidence">confidence</a> is
                   4091:     currently <i>tentative</i>, then <a href="#change-the-encoding">change the
                   4092:     encoding</a> to the encoding given by the value of the
                   4093:     <code title="attr-meta-charset"><a href="semantics.html#attr-meta-charset">charset</a></code> attribute.</p>
                   4094: 
                   4095:     <p>Otherwise, if the element has a <code title="attr-meta-charset"><a href="semantics.html#attr-meta-charset">content</a></code> attribute, and
                   4096:     applying the <a href="infrastructure.html#algorithm-for-extracting-an-encoding-from-a-content-type">algorithm for extracting an encoding from a
                   4097:     Content-Type</a> to its value returns a supported encoding
                   4098:     <var title="">encoding</var>, and the <a href="#concept-encoding-confidence" title="concept-encoding-confidence">confidence</a> is
                   4099:     currently <i>tentative</i>, then <a href="#change-the-encoding">change the
                   4100:     encoding</a> to the encoding <var title="">encoding</var>.</p>
                   4101: 
                   4102:    </dd>
                   4103: 
                   4104:    <dt>A start tag whose tag name is "title"</dt>
                   4105:    <dd>
                   4106:     <p>Follow the <a href="#generic-rcdata-element-parsing-algorithm">generic RCDATA element parsing algorithm</a>.</p>
                   4107:    </dd>
                   4108: 
                   4109:    <dt>A start tag whose tag name is "noscript", if the <a href="#scripting-flag">scripting flag</a> is enabled</dt>
                   4110:    <dt>A start tag whose tag name is one of: "noframes", "style"</dt>
                   4111:    <dd>
1.91      mike     4112:     <p>Follow the <a href="#generic-raw-text-element-parsing-algorithm">generic raw text element parsing algorithm</a>.</p>
1.1       mike     4113:    </dd>
                   4114: 
                   4115:    <dt>A start tag whose tag name is "noscript", if the <a href="#scripting-flag">scripting flag</a> is disabled</dt>
                   4116:    <dd>
                   4117: 
                   4118:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
                   4119: 
                   4120:     <p>Switch the <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-inheadnoscript" title="insertion mode: in head noscript">in head
                   4121:     noscript</a>".</p>
                   4122: 
                   4123:    </dd>
                   4124: 
                   4125:    <dt id="scriptTag">A start tag whose tag name is "script"</dt>
                   4126:    <dd>
                   4127: 
                   4128:     <ol><li><p><a href="#create-an-element-for-the-token">Create an element for the token</a> in the
                   4129:      <a href="#html-namespace-0">HTML namespace</a>.</p></li>
                   4130: 
                   4131:      <li>
                   4132: 
                   4133:       <p>Mark the element as being <a href="semantics.html#parser-inserted">"parser-inserted"</a>.</p>
                   4134: 
                   4135:       <p class="note">This ensures that, if the script is external,
                   4136:       any <code title="dom-document-write"><a href="dom.html#dom-document-write">document.write()</a></code>
                   4137:       calls in the script will execute in-line, instead of blowing the
                   4138:       document away, as would happen in most other cases. It also
                   4139:       prevents the script from executing until the end tag is
                   4140:       seen.</p>
                   4141: 
                   4142:      </li>
                   4143: 
                   4144:      <li><p>If the parser was originally created for the <a href="#html-fragment-parsing-algorithm">HTML
                   4145:      fragment parsing algorithm</a>, then mark the
                   4146:      <code><a href="semantics.html#script">script</a></code> element as <a href="semantics.html#already-executed">"already
                   4147:      executed"</a>. (<a href="#fragment-case">fragment case</a>)</p></li>
                   4148: 
                   4149:      <li><p>Append the new element to the <a href="#current-node">current node</a>
                   4150:      and push it onto the <a href="#stack-of-open-elements">stack of open
                   4151:      elements</a>.</p></li>
                   4152: 
                   4153:      <li><p>Switch the tokenizer's <a href="#content-model-flag">content model flag</a> to
1.91      mike     4154:      the RAWTEXT state.</p></li>
1.1       mike     4155: 
                   4156:      <li><p>Let the <a href="#original-insertion-mode">original insertion mode</a> be the current
                   4157:      <a href="#insertion-mode">insertion mode</a>.</p>
                   4158: 
1.91      mike     4159:      </li><li><p>Switch the <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-incdata" title="insertion mode: in RAWTEXT/RCDATA">in
                   4160:      RAWTEXT/RCDATA</a>".</p></li>
1.1       mike     4161: 
                   4162:     </ol></dd>
                   4163: 
                   4164:    <dt>An end tag whose tag name is "head"</dt>
                   4165:    <dd>
                   4166: 
                   4167:     <p>Pop the <a href="#current-node">current node</a> (which will be the
                   4168:     <code><a href="semantics.html#the-head-element">head</a></code> element) off the <a href="#stack-of-open-elements">stack of open
                   4169:     elements</a>.</p>
                   4170: 
                   4171:     <p>Switch the <a href="#insertion-mode">insertion mode</a> to "<a href="#the-after-head-insertion-mode" title="insertion mode: after head">after head</a>".</p>
                   4172: 
                   4173:    </dd>
                   4174: 
                   4175:    <dt>An end tag whose tag name is one of: "body", "html", "br"</dt>
                   4176:    <dd>
                   4177:     <p>Act as described in the "anything else" entry below.</p>
                   4178:    </dd>
                   4179: 
                   4180:    <dt>A start tag whose tag name is "head"</dt>
                   4181:    <dt>Any other end tag</dt>
                   4182:    <dd>
                   4183:     <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
                   4184:    </dd>
                   4185: 
                   4186:    <dt>Anything else</dt>
                   4187:    <dd>
                   4188: 
                   4189:     <!-- can't get here with an EOF and a fragment case -->
                   4190: 
                   4191:     <p>Act as if an end tag token with the tag name "head" had
                   4192:     been seen, and reprocess the current token.</p>
                   4193: 
                   4194:     <p class="XXX">In certain UAs, <a href="https://bugzilla.mozilla.org/attachment.cgi?id=180157&amp;action=view">some
                   4195:     elements</a> don't trigger the "in body" mode straight away,
                   4196:     but instead get put into the head. Do we want to copy
                   4197:     that?</p>
                   4198: 
                   4199:    </dd>
                   4200: 
                   4201:   </dl><h5 id="parsing-main-inheadnoscript"><span class="secno">9.2.5.8 </span>The "<dfn title="insertion mode: in head noscript">in head noscript</dfn>" insertion mode</h5>
                   4202: 
                   4203:   <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-inheadnoscript" title="insertion
                   4204:   mode: in head noscript">in head noscript</a>", tokens must be handled as follows:</p>
                   4205: 
                   4206:   <dl class="switch"><dt>A DOCTYPE token</dt>
                   4207:    <dd>
                   4208:     <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
                   4209:    </dd>
                   4210: 
                   4211:    <dt>A start tag whose tag name is "html"</dt>
                   4212:    <dd>
                   4213:     <p>Process the token <a href="#using-the-rules-for">using the rules for</a> the "<a href="#parsing-main-inbody" title="insertion mode: in body">in body</a>" <a href="#insertion-mode">insertion
                   4214:     mode</a>.</p>
                   4215:    </dd>
                   4216: 
                   4217:    <dt>An end tag whose tag name is "noscript"</dt>
                   4218:    <dd>
                   4219: 
                   4220:     <p>Pop the <a href="#current-node">current node</a> (which will be a
                   4221:     <code><a href="semantics.html#the-noscript-element">noscript</a></code> element) from the <a href="#stack-of-open-elements">stack of open
                   4222:     elements</a>; the new <a href="#current-node">current node</a> will be a
                   4223:     <code><a href="semantics.html#the-head-element">head</a></code> element.</p>
                   4224: 
                   4225:     <p>Switch the <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-inhead" title="insertion mode: in head">in head</a>".</p>
                   4226: 
                   4227:    </dd>
                   4228: 
                   4229:    <dt>A character token that is one of U+0009 CHARACTER
                   4230:    TABULATION, U+000A LINE FEED (LF), U+000C FORM FEED (FF),
                   4231:    <!--U+000D CARRIAGE RETURN (CR),--> or U+0020 SPACE</dt>
                   4232:    <dt>A comment token</dt>
                   4233:    <dt>A start tag whose tag name is one of: "link", "meta", "noframes", "style"</dt>
                   4234:    <dd>
                   4235:     <p>Process the token <a href="#using-the-rules-for">using the rules for</a> the "<a href="#parsing-main-inhead" title="insertion mode: in head">in head</a>" <a href="#insertion-mode">insertion
                   4236:     mode</a>.</p>
                   4237:    </dd>
                   4238: 
                   4239:    <dt>An end tag whose tag name is "br"</dt>
                   4240:    <dd>
                   4241:     <p>Act as described in the "anything else" entry below.</p>
                   4242:    </dd>
                   4243: 
                   4244:    <dt>A start tag whose tag name is one of: "head", "noscript"</dt>
                   4245:    <dt>Any other end tag</dt>
                   4246:    <dd>
                   4247:     <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
                   4248:    </dd>
                   4249: 
                   4250:    <dt>Anything else</dt>
                   4251:    <dd>
                   4252: 
                   4253:     <!-- can't get here with an EOF and a fragment case -->
                   4254: 
                   4255:     <p><a href="#parse-error">Parse error</a>. Act as if an end tag with the tag
                   4256:     name "noscript" had been seen and reprocess the current
                   4257:     token.</p>
                   4258: 
                   4259:    </dd>
                   4260: 
                   4261:   </dl><h5 id="the-after-head-insertion-mode"><span class="secno">9.2.5.9 </span>The "<dfn title="insertion mode: after head">after head</dfn>" insertion mode</h5>
                   4262: 
                   4263:   <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#the-after-head-insertion-mode" title="insertion
                   4264:   mode: after head">after head</a>", tokens must be handled as follows:</p>
                   4265: 
                   4266:   <dl class="switch"><dt>A character token that is one of U+0009 CHARACTER
                   4267:    TABULATION, U+000A LINE FEED (LF), U+000C FORM FEED (FF),
                   4268:    <!--U+000D CARRIAGE RETURN (CR),--> or U+0020 SPACE</dt>
                   4269:    <dd>
                   4270:     <p><a href="#insert-a-character" title="insert a character">Insert the character</a> into
                   4271:     the <a href="#current-node">current node</a>.</p>
                   4272:    </dd>
                   4273: 
                   4274:    <dt>A comment token</dt>
                   4275:    <dd>
                   4276:     <p>Append a <code>Comment</code> node to the <a href="#current-node">current
                   4277:     node</a> with the <code title="">data</code> attribute set to
                   4278:     the data given in the comment token.</p>
                   4279:    </dd>
                   4280: 
                   4281:    <dt>A DOCTYPE token</dt>
                   4282:    <dd>
                   4283:     <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
                   4284:    </dd>
                   4285: 
                   4286:    <dt>A start tag whose tag name is "html"</dt>
                   4287:    <dd>
                   4288:     <p>Process the token <a href="#using-the-rules-for">using the rules for</a> the "<a href="#parsing-main-inbody" title="insertion mode: in body">in body</a>" <a href="#insertion-mode">insertion
                   4289:     mode</a>.</p>
                   4290:    </dd>
                   4291: 
                   4292:    <dt>A start tag whose tag name is "body"</dt>
                   4293:    <dd>
                   4294: 
                   4295:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
                   4296: 
                   4297:     <p>Set the <a href="#frameset-ok-flag">frameset-ok flag</a> to "not ok".</p>
                   4298: 
                   4299:     <p>Switch the <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-inbody" title="insertion mode: in body">in body</a>".</p>
                   4300: 
                   4301:    </dd>
                   4302: 
                   4303:    <dt>A start tag whose tag name is "frameset"</dt>
                   4304:    <dd>
                   4305: 
                   4306:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
                   4307: 
                   4308:     <p>Switch the <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-inframeset" title="insertion mode: in frameset">in frameset</a>".</p>
                   4309: 
                   4310:    </dd>
                   4311: 
                   4312:    <dt>A start tag token whose tag name is one of: "base", "link",
                   4313:    "meta", "noframes", "script", "style", "title"</dt>
                   4314:    <dd>
                   4315: 
                   4316:     <p><a href="#parse-error">Parse error</a>.</p>
                   4317: 
                   4318:     <p>Push the node pointed to by the <a href="#head-element-pointer"><code title="">head</code> element pointer</a> onto the
                   4319:     <a href="#stack-of-open-elements">stack of open elements</a>.</p>
                   4320: 
                   4321:     <p>Process the token <a href="#using-the-rules-for">using the rules for</a> the "<a href="#parsing-main-inhead" title="insertion mode: in head">in head</a>" <a href="#insertion-mode">insertion
                   4322:     mode</a>.</p>
                   4323: 
                   4324:     <p>Remove the node pointed to by the <a href="#head-element-pointer"><code title="">head</code> element pointer</a> from the <a href="#stack-of-open-elements">stack
                   4325:     of open elements</a>.</p>
                   4326: 
                   4327:     <p class="note">The <a href="#head-element-pointer"><code title="">head</code> element
                   4328:     pointer</a> cannot be null at this point.</p>
                   4329: 
                   4330:    </dd>
                   4331: 
                   4332:    <dt>An end tag whose tag name is one of: "body", "html", "br"</dt>
                   4333:    <dd>
                   4334:     <p>Act as described in the "anything else" entry below.</p>
                   4335:    </dd>
                   4336: 
                   4337:    <dt>A start tag whose tag name is "head"</dt>
                   4338:    <dt>Any other end tag</dt>
                   4339:    <dd>
                   4340:     <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
                   4341:    </dd>
                   4342: 
                   4343:    <dt>Anything else</dt>
                   4344:    <dd>
                   4345:     <p>Act as if a start tag token with the tag name "body" and no
                   4346:     attributes had been seen, then set the <a href="#frameset-ok-flag">frameset-ok
                   4347:     flag</a> back to "ok", and then reprocess the current
                   4348:     token.</p>
                   4349:    </dd>
                   4350: 
                   4351:   </dl><h5 id="parsing-main-inbody"><span class="secno">9.2.5.10 </span>The "<dfn title="insertion mode: in body">in body</dfn>" insertion mode</h5>
                   4352: 
                   4353:   <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-inbody" title="insertion
                   4354:   mode: in body">in body</a>", tokens must be handled as follows:</p>
                   4355: 
                   4356:   <dl class="switch"><dt>A character token</dt>
                   4357:    <dd>
                   4358: 
                   4359:     <p><a href="#reconstruct-the-active-formatting-elements">Reconstruct the active formatting elements</a>, if
                   4360:     any.</p>
                   4361: 
                   4362:     <p><a href="#insert-a-character" title="insert a character">Insert the token's
                   4363:     character</a> into the <a href="#current-node">current node</a>.</p>
                   4364: 
                   4365:     <p>If the token is not one of U+0009 CHARACTER TABULATION, U+000A
                   4366:     LINE FEED (LF), U+000C FORM FEED (FF), <!--U+000D CARRIAGE RETURN
                   4367:     (CR),--> or U+0020 SPACE, then set the <a href="#frameset-ok-flag">frameset-ok
                   4368:     flag</a> to "not ok".</p>
                   4369: 
                   4370:    </dd>
                   4371: 
                   4372:    <dt>A comment token</dt>
                   4373:    <dd>
                   4374:     <p>Append a <code>Comment</code> node to the <a href="#current-node">current
                   4375:     node</a> with the <code title="">data</code> attribute set to
                   4376:     the data given in the comment token.</p>
                   4377:    </dd>
                   4378: 
                   4379:    <dt>A DOCTYPE token</dt>
                   4380:    <dd>
                   4381:     <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
                   4382:    </dd>
                   4383: 
                   4384:    <dt>A start tag whose tag name is "html"</dt>
                   4385:    <dd>
                   4386:     <p><a href="#parse-error">Parse error</a>. For each attribute on the token,
                   4387:     check to see if the attribute is already present on the top
                   4388:     element of the <a href="#stack-of-open-elements">stack of open elements</a>. If it is not,
                   4389:     add the attribute and its corresponding value to that element.</p>
                   4390:    </dd>
                   4391: 
                   4392:    <dt>A start tag token whose tag name is one of: "base", "command",
                   4393:    "link", "meta", "noframes", "script", "style", "title"</dt>
                   4394:    <dd>
                   4395:     <p>Process the token <a href="#using-the-rules-for">using the rules for</a> the "<a href="#parsing-main-inhead" title="insertion mode: in head">in head</a>" <a href="#insertion-mode">insertion
                   4396:     mode</a>.</p>
                   4397:    </dd>
                   4398: 
                   4399:    <dt>A start tag whose tag name is "body"</dt>
                   4400:    <dd>
                   4401: 
                   4402:     <p><a href="#parse-error">Parse error</a>.</p>
                   4403: 
                   4404:     <p>If the second element on the <a href="#stack-of-open-elements">stack of open
                   4405:     elements</a> is not a <code><a href="semantics.html#the-body-element">body</a></code> element, or, if the
                   4406:     <a href="#stack-of-open-elements">stack of open elements</a> has only one node on it,
                   4407:     then ignore the token. (<a href="#fragment-case">fragment case</a>)</p>
                   4408: 
                   4409:     <p>Otherwise, for each attribute on the token, check to see if
                   4410:     the attribute is already present on the <code><a href="semantics.html#the-body-element">body</a></code>
                   4411:     element (the second element) on the <a href="#stack-of-open-elements">stack of open
                   4412:     elements</a>. If it is not, add the attribute and its
                   4413:     corresponding value to that element.</p>
                   4414: 
                   4415:    </dd>
                   4416: 
                   4417:    <dt>A start tag whose tag name is "frameset"</dt>
                   4418:    <dd>
                   4419: 
                   4420:     <p><a href="#parse-error">Parse error</a>.</p>
                   4421: 
                   4422:     <p>If the second element on the <a href="#stack-of-open-elements">stack of open
                   4423:     elements</a> is not a <code><a href="semantics.html#the-body-element">body</a></code> element, or, if the
                   4424:     <a href="#stack-of-open-elements">stack of open elements</a> has only one node on it,
                   4425:     then ignore the token. (<a href="#fragment-case">fragment case</a>)</p>
                   4426: 
                   4427:     <p>If the <a href="#frameset-ok-flag">frameset-ok flag</a> is set to "not ok", ignore
                   4428:     the token.</p>
                   4429: 
                   4430:     <p>Otherwise, run the following steps:</p>
                   4431: 
                   4432:     <ol><li><p>Remove the second element on the <a href="#stack-of-open-elements">stack of open
                   4433:      elements</a> from its parent node, if it has one.</p></li>
                   4434: 
                   4435:      <li><p>Pop all the nodes from the bottom of the <a href="#stack-of-open-elements">stack of
                   4436:      open elements</a>, from the <a href="#current-node">current node</a> up to,
                   4437:      but not including, the root <code><a href="semantics.html#the-html-element">html</a></code> element.</p>
                   4438: 
                   4439:      </li><li><p><a href="#insert-an-html-element">Insert an HTML element</a> for the
                   4440:      token.</p></li>
                   4441: 
                   4442:      <li><p>Switch the <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-inframeset" title="insertion mode: in frameset">in frameset</a>".</p>
                   4443: 
                   4444:     </li></ol></dd>
                   4445: 
                   4446:    <dt>An end-of-file token</dt>
                   4447:    <dd>
                   4448: 
                   4449:     <p>If there is a node in the <a href="#stack-of-open-elements">stack of open elements</a>
                   4450:     that is not either a <code><a href="semantics.html#the-dd-element">dd</a></code> element, a <code><a href="semantics.html#the-dt-element">dt</a></code>
                   4451:     element, an <code><a href="semantics.html#the-li-element">li</a></code> element, a <code><a href="semantics.html#the-p-element">p</a></code> element, a
                   4452:     <code><a href="tabular-data.html#the-tbody-element">tbody</a></code> element, a <code><a href="tabular-data.html#the-td-element">td</a></code> element, a
                   4453:     <code><a href="tabular-data.html#the-tfoot-element">tfoot</a></code> element, a <code><a href="tabular-data.html#the-th-element">th</a></code> element, a
                   4454:     <code><a href="tabular-data.html#the-thead-element">thead</a></code> element, a <code><a href="tabular-data.html#the-tr-element">tr</a></code> element, the
                   4455:     <code><a href="semantics.html#the-body-element">body</a></code> element, or the <code><a href="semantics.html#the-html-element">html</a></code> element, then
                   4456:     this is a <a href="#parse-error">parse error</a>.</p> <!-- (some of those are
                   4457:     fragment cases) -->
                   4458: 
                   4459:     <p><a href="#stop-parsing">Stop parsing</a>.</p>
                   4460: 
                   4461:    </dd>
                   4462: 
                   4463:    <dt>An end tag whose tag name is "body"</dt>
                   4464:    <dd>
                   4465: 
                   4466:     <p>If the <a href="#stack-of-open-elements">stack of open elements</a> does not <a href="#has-an-element-in-scope" title="has an element in scope">have a <code>body</code> element
                   4467:     in scope</a>, this is a <a href="#parse-error">parse error</a>; ignore the
                   4468:     token.</p>
                   4469: 
                   4470:     <!-- if we get here, the insertion mode here is forcibly "in
                   4471:     body". -->
                   4472: 
                   4473:     <p>Otherwise, if there is a node in the <a href="#stack-of-open-elements">stack of open
                   4474:     elements</a> that is not either a <code><a href="semantics.html#the-dd-element">dd</a></code> element, a
                   4475:     <code><a href="semantics.html#the-dt-element">dt</a></code> element, an <code><a href="semantics.html#the-li-element">li</a></code> element, an
                   4476:     <code><a href="forms.html#the-optgroup-element">optgroup</a></code> element, an <code><a href="forms.html#the-option-element">option</a></code> element, a
                   4477:     <code><a href="semantics.html#the-p-element">p</a></code> element, an <code><a href="text-level-semantics.html#the-rp-element">rp</a></code> element, an
                   4478:     <code><a href="text-level-semantics.html#the-rt-element">rt</a></code> element, a <code><a href="tabular-data.html#the-tbody-element">tbody</a></code> element, a
                   4479:     <code><a href="tabular-data.html#the-td-element">td</a></code> element, a <code><a href="tabular-data.html#the-tfoot-element">tfoot</a></code> element, a
                   4480:     <code><a href="tabular-data.html#the-th-element">th</a></code> element, a <code><a href="tabular-data.html#the-thead-element">thead</a></code> element, a
                   4481:     <code><a href="tabular-data.html#the-tr-element">tr</a></code> element, the <code><a href="semantics.html#the-body-element">body</a></code> element, or the
                   4482:     <code><a href="semantics.html#the-html-element">html</a></code> element, then this is a <a href="#parse-error">parse
                   4483:     error</a>.</p> <!-- (some of those are fragment cases, e.g. for
                   4484:     <tbody> you'd have hit the first paragraph since the <body>
                   4485:     wouldn't be in scope, unless it was a fragment case) -->
                   4486: 
                   4487:     <!-- If we ever change the frameset-ok flag to an insertion mode,
                   4488:     then we'd have to somehow keep track of its state when we switch
                   4489:     to after-body. -->
                   4490: 
                   4491:     <p>Switch the <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-afterbody" title="insertion mode: after body">after body</a>".</p>
                   4492: 
                   4493:    </dd>
                   4494: 
                   4495:    <dt>An end tag whose tag name is "html"</dt>
                   4496:    <dd>
                   4497: 
                   4498:     <p>Act as if an end tag with tag name "body" had been seen,
                   4499:     then, if that token wasn't ignored, reprocess the current
                   4500:     token.</p>
                   4501: 
                   4502:     <p class="note">The fake end tag token here can only be
                   4503:     ignored in the <a href="#fragment-case">fragment case</a>.</p>
                   4504: 
                   4505:    </dd>
                   4506: 
                   4507:    <!-- start tags for non-phrasing flow content elements -->
                   4508: 
                   4509:    <!-- the normal ones -->
                   4510:    <dt>A start tag whose tag name is one of: "address", "article",
1.86      mike     4511:    "aside", "blockquote", "center", <!--v2DATAGRID-->"datagrid",
                   4512:    "details", "dialog", "dir", "div", "dl", "fieldset", "figure",
                   4513:    "footer", "header", "hgroup", "menu", "nav", "ol", "p", "section",
                   4514:    "ul"</dt>
1.1       mike     4515:    <dd>
                   4516: 
                   4517:     <!-- As of May 2008 this doesn't match any browser exactly, but is
                   4518:     as close to what IE does as I can get without doing the non-tree
                   4519:     DOM nonsense, and thus should actually afford better compatibility
                   4520:     when implemented by the other browsers. -->
                   4521: 
                   4522:     <p>If the <a href="#stack-of-open-elements">stack of open elements</a> <a href="#has-an-element-in-scope" title="has
                   4523:     an element in scope">has a <code>p</code> element in
                   4524:     scope</a>, then act as if an end tag with the tag name
                   4525:     "p" had been seen.</p>
                   4526: 
                   4527:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
                   4528: 
                   4529:    </dd>
                   4530: 
                   4531:    <!-- as normal, but close h1-h6 if it's the current node -->
                   4532:    <dt>A start tag whose tag name is one of: "h1", "h2", "h3", "h4",
                   4533:    "h5", "h6"</dt>
                   4534:    <dd>
                   4535: 
                   4536:     <p>If the <a href="#stack-of-open-elements">stack of open elements</a> <a href="#has-an-element-in-scope" title="has
                   4537:     an element in scope">has a <code>p</code> element in
                   4538:     scope</a>, then act as if an end tag with the tag name
                   4539:     "p" had been seen.</p>
                   4540: 
                   4541:     <p>If the <a href="#current-node">current node</a> is an element whose tag name
                   4542:     is one of "h1", "h2", "h3", "h4", "h5", or "h6", then this is a
                   4543:     <a href="#parse-error">parse error</a>; pop the <a href="#current-node">current node</a> off
                   4544:     the <a href="#stack-of-open-elements">stack of open elements</a>.</p>
                   4545:     <!-- See https://bugs.webkit.org/show_bug.cgi?id=12646 -->
                   4546: 
                   4547:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
                   4548: 
                   4549:    </dd>
                   4550: 
                   4551:    <!-- as normal, but drops leading newline -->
                   4552:    <dt>A start tag whose tag name is one of: "pre", "listing"</dt>
                   4553:    <dd>
                   4554: 
                   4555:     <p>If the <a href="#stack-of-open-elements">stack of open elements</a> <a href="#has-an-element-in-scope" title="has
                   4556:     an element in scope">has a <code>p</code> element in
                   4557:     scope</a>, then act as if an end tag with the tag name
                   4558:     "p" had been seen.</p>
                   4559: 
                   4560:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
                   4561: 
                   4562:     <p>If the next token is a U+000A LINE FEED (LF) character
                   4563:     token, then ignore that token and move on to the next
                   4564:     one. (Newlines at the start of <code><a href="semantics.html#the-pre-element">pre</a></code> blocks are
                   4565:     ignored as an authoring convenience.)</p>
                   4566: 
                   4567:     <p>Set the <a href="#frameset-ok-flag">frameset-ok flag</a> to "not ok".</p>
                   4568: 
                   4569:    </dd>
                   4570: 
                   4571:    <!-- as normal, but interacts with the form element pointer -->
                   4572:    <dt>A start tag whose tag name is "form"</dt>
                   4573:    <dd>
                   4574: 
                   4575:     <p>If the <a href="#form-element-pointer"><code title="form">form</code> element
                   4576:     pointer</a> is not null, then this is a <a href="#parse-error">parse
                   4577:     error</a>; ignore the token.</p>
                   4578: 
                   4579:     <p>Otherwise:</p>
                   4580: 
                   4581:     <p>If the <a href="#stack-of-open-elements">stack of open elements</a> <a href="#has-an-element-in-scope" title="has
                   4582:     an element in scope">has a <code>p</code> element in
                   4583:     scope</a>, then act as if an end tag with the tag name
                   4584:     "p" had been seen.</p>
                   4585: 
                   4586:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token, and set the
                   4587:     <a href="#form-element-pointer"><code title="form">form</code> element pointer</a> to
                   4588:     point to the element created.</p>
                   4589: 
                   4590:    </dd>
                   4591: 
                   4592:    <!-- as normal, but imply </li> when there's another <li> open in weird cases -->
                   4593:    <dt>A start tag whose tag name is "li"</dt>
                   4594:    <dd>
                   4595: 
                   4596:     <p>Run the following algorithm:</p>
                   4597: 
                   4598:     <ol><li><p>Set the <a href="#frameset-ok-flag">frameset-ok flag</a> to "not ok".</p></li>
                   4599: 
                   4600:      <li><p>Initialize <var title="">node</var> to be the <a href="#current-node">current
                   4601:      node</a> (the bottommost node of the stack).</p></li>
                   4602: 
                   4603:      <li><p>If <var title="">node</var> is an <code><a href="semantics.html#the-li-element">li</a></code> element,
                   4604:      then act as if an end tag with the tag name "li" had
                   4605:      been seen, then jump to the last step.</p></li>
                   4606: 
                   4607:      <li><p><i>Loop</i>: If <var title="">node</var> is not in the
                   4608:      <a href="#formatting">formatting</a> category, and is not in the
                   4609:      <a href="#phrasing">phrasing</a> category, and is not an
                   4610:      <code><a href="semantics.html#the-address-element">address</a></code>, <code><a href="interactive-elements.html#the-div-element">div</a></code>, or <code><a href="semantics.html#the-p-element">p</a></code>
                   4611:      element, then jump to the last step.</p></li> <!-- an element
                   4612:      <foo> is in this list if the following markup:
                   4613: 
                   4614:          <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><body><ol><li><foo><li>
                   4615: 
                   4616:      ...results in the second <li> not being (in any way) a descendant
                   4617:      of the first <li>, or if <foo> is a formatting element that gets
                   4618:      reopened later. -->
                   4619: 
                   4620:      <li><p>Otherwise, set <var title="">node</var> to the previous
                   4621:      entry in the <a href="#stack-of-open-elements">stack of open elements</a> and return to
                   4622:      the step labeled <i>loop</i>.</p></li>
                   4623: 
                   4624:      <li>
                   4625: 
                   4626:       <p>This is the last step.</p>
                   4627: 
                   4628:       <p>If the <a href="#stack-of-open-elements">stack of open elements</a> <a href="#has-an-element-in-scope" title="has
                   4629:       an element in scope">has a <code>p</code> element in
                   4630:       scope</a>, then act as if an end tag with the tag name
                   4631:       "p" had been seen.</p>
                   4632: 
                   4633:       <p>Finally, <a href="#insert-an-html-element">insert an HTML element</a> for the
                   4634:       token.</p>
                   4635: 
                   4636:      </li>
                   4637: 
                   4638:     </ol></dd>
                   4639: 
                   4640:    <!-- as normal, but imply </dt> or </dd> when there's another <dt> or <dd> open in weird cases  -->
                   4641:    <dt>A start tag whose tag name is one of: "dd", "dt"</dt>
                   4642:    <dd>
                   4643: 
                   4644:     <p>Run the following algorithm:</p>
                   4645: 
                   4646:     <ol><li><p>Set the <a href="#frameset-ok-flag">frameset-ok flag</a> to "not ok".</p></li>
                   4647: 
                   4648:      <li><p>Initialize <var title="">node</var> to be the <a href="#current-node">current
                   4649:      node</a> (the bottommost node of the stack).</p></li>
                   4650: 
                   4651:      <li><p><i>Loop</i>: If <var title="">node</var> is a
                   4652:      <code><a href="semantics.html#the-dd-element">dd</a></code> or <code><a href="semantics.html#the-dt-element">dt</a></code> element, then act as if an end
                   4653:      tag with the same tag name as <var title="">node</var> had been
                   4654:      seen, then jump to the last step.</p></li>
                   4655: 
                   4656:      <li><p>If <var title="">node</var> is not in the
                   4657:      <a href="#formatting">formatting</a> category, and is not in the
                   4658:      <a href="#phrasing">phrasing</a> category, and is not an
                   4659:      <code><a href="semantics.html#the-address-element">address</a></code>, <code><a href="interactive-elements.html#the-div-element">div</a></code>, or <code><a href="semantics.html#the-p-element">p</a></code>
                   4660:      element, then jump to the last step.</p></li> <!-- an element
                   4661:      <foo> is in this list if the following markup:
                   4662: 
                   4663:          <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><body><dl><dt><foo><dt>
                   4664: 
                   4665:      ...results in the second <dt> not being (in any way) a descendant
                   4666:      of the first <dt>, or if <foo> is a formatting element that gets
                   4667:      reopened later. -->
                   4668: 
                   4669:      <li><p>Otherwise, set <var title="">node</var> to the previous
                   4670:      entry in the <a href="#stack-of-open-elements">stack of open elements</a> and return to
                   4671:      the step labeled <i>loop</i>.</p></li>
                   4672: 
                   4673:      <li>
                   4674: 
                   4675:       <p>This is the last step.</p>
                   4676: 
                   4677:       <p>If the <a href="#stack-of-open-elements">stack of open elements</a> <a href="#has-an-element-in-scope" title="has
                   4678:       an element in scope">has a <code>p</code> element in
                   4679:       scope</a>, then act as if an end tag with the tag name
                   4680:       "p" had been seen.</p>
                   4681: 
                   4682:       <p>Finally, <a href="#insert-an-html-element">insert an HTML element</a> for the
                   4683:       token.</p>
                   4684: 
                   4685:      </li>
                   4686: 
                   4687:     </ol></dd>
                   4688: 
                   4689:    <!-- same as normal, but effectively ends parsing -->
                   4690:    <dt>A start tag whose tag name is "plaintext"</dt>
                   4691:    <dd>
                   4692: 
                   4693:     <p>If the <a href="#stack-of-open-elements">stack of open elements</a> <a href="#has-an-element-in-scope" title="has
                   4694:     an element in scope">has a <code>p</code> element in
                   4695:     scope</a>, then act as if an end tag with the tag name
                   4696:     "p" had been seen.</p>
                   4697: 
                   4698:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
                   4699: 
                   4700:     <p>Switch the <a href="#content-model-flag">content model flag</a> to the PLAINTEXT
                   4701:     state.</p>
                   4702: 
                   4703:     <p class="note">Once a start tag with the tag name "plaintext"
                   4704:     has been seen, that will be the last token ever seen other
                   4705:     than character tokens (and the end-of-file token), because
                   4706:     there is no way to switch the <a href="#content-model-flag">content model flag</a>
                   4707:     out of the PLAINTEXT state.</p>
                   4708: 
                   4709:    </dd>
                   4710: 
                   4711:    <!-- end tags for non-phrasing flow content elements -->
                   4712: 
                   4713:    <!-- the normal ones -->
                   4714:    <dt>An end tag whose tag name is one of: "address", "article",
1.86      mike     4715:    "aside", "blockquote", "center", <!--v2DATAGRID-->"datagrid",
                   4716:    "details", "dialog", "dir", "div", "dl", "fieldset", "figure",
                   4717:    "footer", "header", "hgroup", "listing", "menu", "nav", "ol",
                   4718:    "pre", "section", "ul"</dt>
1.1       mike     4719:    <dd>
                   4720: 
                   4721:     <p>If the <a href="#stack-of-open-elements">stack of open elements</a> does not <a href="#has-an-element-in-scope" title="has an element in scope">have an element in scope</a>
                   4722:     with the same tag name as that of the token, then this is a
                   4723:     <a href="#parse-error">parse error</a>; ignore the token.</p>
                   4724: 
                   4725:     <p>Otherwise, run these steps:</p>
                   4726: 
                   4727:     <ol><li><p><a href="#generate-implied-end-tags">Generate implied end tags</a>.</p></li>
                   4728: 
                   4729:      <li><p>If the <a href="#current-node">current node</a> is not an element with
                   4730:      the same tag name as that of the token, then this is a
                   4731:      <a href="#parse-error">parse error</a>.</p></li>
                   4732: 
                   4733:      <li><p>Pop elements from the <a href="#stack-of-open-elements">stack of open elements</a>
                   4734:      until an element with the same tag name as the token has been
                   4735:      popped from the stack.</p></li>
                   4736: 
                   4737:     </ol></dd>
                   4738: 
                   4739:    <!-- removes the form element pointer instead of the matching node -->
                   4740:    <dt>An end tag whose tag name is "form"</dt>
                   4741:    <dd>
                   4742: 
                   4743:     <p>Let <var title="">node</var> be the element that the
                   4744:     <a href="#form-element-pointer"><code title="">form</code> element pointer</a> is set
                   4745:     to.</p>
                   4746: 
                   4747:     <p>Set the <a href="#form-element-pointer"><code title="">form</code> element pointer</a>
                   4748:     to null.</p>
                   4749: 
                   4750:     <p>If <var title="">node</var> is null or the <a href="#stack-of-open-elements">stack of open
                   4751:     elements</a> does not <a href="#has-an-element-in-scope" title="has an element in
                   4752:     scope">have <var title="">node</var> in scope</a>, then this is
                   4753:     a <a href="#parse-error">parse error</a>; ignore the token.</p>
                   4754: 
                   4755:     <p>Otherwise, run these steps:</p>
                   4756: 
                   4757:     <ol><li><p><a href="#generate-implied-end-tags">Generate implied end tags</a>.</p></li>
                   4758: 
                   4759:      <li><p>If the <a href="#current-node">current node</a> is not <var title="">node</var>, then this is a <a href="#parse-error">parse
                   4760:      error</a>.</p></li>
                   4761: 
                   4762:      <li><p>Remove <var title="">node</var> from the <a href="#stack-of-open-elements">stack of
                   4763:      open elements</a>.</p></li>
                   4764: 
                   4765:     </ol></dd>
                   4766: 
                   4767:    <!-- as normal, except </p> implies <p> if there's no <p> in scope, and needs care as the elements have optional tags -->
                   4768:    <dt>An end tag whose tag name is "p"</dt>
                   4769:    <dd>
                   4770: 
                   4771:     <p>If the <a href="#stack-of-open-elements">stack of open elements</a> does not <a href="#has-an-element-in-scope" title="has an element in scope">have an element in scope</a>
                   4772:     with the same tag name as that of the token, then this is a
                   4773:     <a href="#parse-error">parse error</a>; act as if a start tag with the tag name
                   4774:     "p" had been seen, then reprocess the current token.</p>
                   4775: 
                   4776:     <p>Otherwise, run these steps:</p>
                   4777: 
                   4778:     <ol><li><p><a href="#generate-implied-end-tags">Generate implied end tags</a>, except
                   4779:      for elements with the same tag name as the token.</p></li>
                   4780: 
                   4781:      <li><p>If the <a href="#current-node">current node</a> is not an element with
                   4782:      the same tag name as that of the token, then this is a
                   4783:      <a href="#parse-error">parse error</a>.</p></li>
                   4784: 
                   4785:      <li><p>Pop elements from the <a href="#stack-of-open-elements">stack of open elements</a>
                   4786:      until an element with the same tag name as the token has been
                   4787:      popped from the stack.</p></li>
                   4788: 
                   4789:     </ol></dd>
                   4790: 
                   4791:    <!-- as normal, but needs care as the elements have optional tags -->
                   4792:    <dt>An end tag whose tag name is one of: "dd", "dt", "li"</dt>
                   4793:    <dd>
                   4794: 
                   4795:     <p>If the <a href="#stack-of-open-elements">stack of open elements</a> does not <a href="#has-an-element-in-scope" title="has an element in scope">have an element in scope</a>
                   4796:     with the same tag name as that of the token, then this is a
                   4797:     <a href="#parse-error">parse error</a>; ignore the token.</p>
                   4798: 
                   4799:     <p>Otherwise, run these steps:</p>
                   4800: 
                   4801:     <ol><li><p><a href="#generate-implied-end-tags">Generate implied end tags</a>, except
                   4802:      for elements with the same tag name as the token.</p></li>
                   4803: 
                   4804:      <li><p>If the <a href="#current-node">current node</a> is not an element with
                   4805:      the same tag name as that of the token, then this is a
                   4806:      <a href="#parse-error">parse error</a>.</p></li>
                   4807: 
                   4808:      <li><p>Pop elements from the <a href="#stack-of-open-elements">stack of open elements</a>
                   4809:      until an element with the same tag name as the token has been
                   4810:      popped from the stack.</p></li>
                   4811: 
                   4812:     </ol></dd>
                   4813: 
                   4814:    <!-- as normal, except acts as a closer for any of the h1-h6 elements -->
                   4815:    <dt>An end tag whose tag name is one of: "h1", "h2", "h3", "h4", "h5", "h6"</dt>
                   4816:    <dd>
                   4817: 
                   4818:     <p>If the <a href="#stack-of-open-elements">stack of open elements</a> does not <a href="#has-an-element-in-scope" title="has an element in scope">have an element in scope</a>
                   4819:     whose tag name is one of "h1", "h2", "h3", "h4", "h5", or "h6",
                   4820:     then this is a <a href="#parse-error">parse error</a>; ignore the token.</p>
                   4821: 
                   4822:     <p>Otherwise, run these steps:</p>
                   4823: 
                   4824:     <ol><li><p><a href="#generate-implied-end-tags">Generate implied end tags</a>.</p></li>
                   4825: 
                   4826:      <li><p>If the <a href="#current-node">current node</a> is not an element with
                   4827:      the same tag name as that of the token, then this is a
                   4828:      <a href="#parse-error">parse error</a>.</p></li>
                   4829: 
                   4830:      <li><p>Pop elements from the <a href="#stack-of-open-elements">stack of open elements</a>
                   4831:      until an element whose tag name is one of "h1", "h2", "h3", "h4",
                   4832:      "h5", or "h6" has been popped from the stack.</p></li>
                   4833: 
                   4834:     </ol></dd>
                   4835: 
                   4836:    <dt>An end tag whose tag name is "sarcasm"</dt>
                   4837:    <dd>
                   4838:     <p>Take a deep breath, then act as described in the "any other end
                   4839:     tag" entry below.</p>
                   4840:    </dd>
                   4841: 
                   4842:    <!-- ADOPTION AGENCY ELEMENTS
                   4843:         Mozilla-only: bdo blink del ins sub sup q
                   4844:         Safari-only: code dfn kbd nobr samp var wbr
                   4845:         Both: a b big em font i s small strike strong tt u -->
                   4846: 
                   4847:    <dt>A start tag whose tag name is "a"</dt>
                   4848:    <dd>
                   4849: 
                   4850:     <p>If the <a href="#list-of-active-formatting-elements">list of active formatting elements</a>
                   4851:     contains an element whose tag name is "a" between the end of
                   4852:     the list and the last marker on the list (or the start of the
                   4853:     list if there is no marker on the list), then this is a
                   4854:     <a href="#parse-error">parse error</a>; act as if an end tag with the tag
                   4855:     name "a" had been seen, then remove that element from the
                   4856:     <a href="#list-of-active-formatting-elements">list of active formatting elements</a> and the
                   4857:     <a href="#stack-of-open-elements">stack of open elements</a> if the end tag didn't
                   4858:     already remove it (it might not have if the element is not
                   4859:     <a href="#has-an-element-in-table-scope" title="has an element in table scope">in table
                   4860:     scope</a>).</p>
                   4861: 
                   4862:     <p class="example">In the non-conforming stream
                   4863:     <code>&lt;a&#160;href="a"&gt;a&lt;table&gt;&lt;a&#160;href="b"&gt;b&lt;/table&gt;x</code>,
                   4864:     the first <code><a href="text-level-semantics.html#the-a-element">a</a></code> element would be closed upon seeing
                   4865:     the second one, and the "x" character would be inside a link
                   4866:     to "b", not to "a". This is despite the fact that the outer
                   4867:     <code><a href="text-level-semantics.html#the-a-element">a</a></code> element is not in table scope (meaning that a
                   4868:     regular <code>&lt;/a&gt;</code> end tag at the start of the table
                   4869:     wouldn't close the outer <code><a href="text-level-semantics.html#the-a-element">a</a></code> element).</p>
                   4870: 
                   4871:     <p><a href="#reconstruct-the-active-formatting-elements">Reconstruct the active formatting elements</a>, if
                   4872:     any.</p>
                   4873: 
                   4874:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token. Add that
                   4875:     element to the <a href="#list-of-active-formatting-elements">list of active formatting
                   4876:     elements</a>.</p>
                   4877: 
                   4878:    </dd>
                   4879: 
                   4880:    <dt>A start tag whose tag name is one of: "b", "big", "code", "em",
                   4881:    "font", "i", "s", "small", "strike", "strong", "tt", "u"</dt>
                   4882:    <dd>
                   4883: 
                   4884:     <p><a href="#reconstruct-the-active-formatting-elements">Reconstruct the active formatting elements</a>, if
                   4885:     any.</p>
                   4886: 
                   4887:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token. Add that
                   4888:     element to the <a href="#list-of-active-formatting-elements">list of active formatting
                   4889:     elements</a>.</p>
                   4890: 
                   4891:    </dd>
                   4892: 
                   4893:    <dt>A start tag whose tag name is "nobr"</dt>
                   4894:    <dd>
                   4895: 
                   4896:     <p><a href="#reconstruct-the-active-formatting-elements">Reconstruct the active formatting elements</a>, if
                   4897:     any.</p>
                   4898: 
                   4899:     <p>If the <a href="#stack-of-open-elements">stack of open elements</a> <a href="#has-an-element-in-scope" title="has an
                   4900:     element in scope">has a <code>nobr</code> element in scope</a>,
                   4901:     then this is a <a href="#parse-error">parse error</a>; act as if an end tag with
                   4902:     the tag name "nobr" had been seen, then once again
                   4903:     <a href="#reconstruct-the-active-formatting-elements">reconstruct the active formatting elements</a>, if
                   4904:     any.</p>
                   4905: 
                   4906:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token. Add that
                   4907:     element to the <a href="#list-of-active-formatting-elements">list of active formatting
                   4908:     elements</a>.</p>
                   4909: 
                   4910:    </dd>
                   4911: 
                   4912:    <dt id="adoptionAgency">An end tag whose tag name is one of: "a",
                   4913:    "b", "big", "code", "em", "font", "i", "nobr", "s", "small",
                   4914:    "strike", "strong", "tt", "u"</dt>
                   4915:    <dd>
                   4916: 
                   4917:     <p>Follow these steps:</p>
                   4918: 
                   4919:     <ol><li>
                   4920: 
                   4921:       <p>Let the <var title="">formatting element</var> be the
                   4922:       last element in the <a href="#list-of-active-formatting-elements">list of active formatting
                   4923:       elements</a> that:</p>
                   4924: 
                   4925:       <ul><li>is between the end of the list and the last scope
                   4926:        marker in the list, if any, or the start of the list
                   4927:        otherwise, and</li>
                   4928: 
                   4929:        <li>has the same tag name as the token.</li>
                   4930: 
                   4931:       </ul><p>If there is no such node, or, if that node is also in the
                   4932:       <a href="#stack-of-open-elements">stack of open elements</a> but the element is not <a href="#has-an-element-in-scope" title="has an element in scope">in scope</a>, then this is a
                   4933:       <a href="#parse-error">parse error</a>; ignore the token, and abort these
                   4934:       steps.</p>
                   4935: 
                   4936:       <p>Otherwise, if there is such a node, but that node is not
                   4937:       in the <a href="#stack-of-open-elements">stack of open elements</a>, then this is a
                   4938:       <a href="#parse-error">parse error</a>; remove the element from the list,
                   4939:       and abort these steps.</p>
                   4940: 
                   4941:       <p>Otherwise, there is a <var title="">formatting
                   4942:       element</var> and that element is in <a href="#stack-of-open-elements" title="stack of
                   4943:       open elements">the stack</a> and is <a href="#has-an-element-in-scope" title="has an
                   4944:       element in scope">in scope</a>. If the element is not the
                   4945:       <a href="#current-node">current node</a>, this is a <a href="#parse-error">parse
                   4946:       error</a>. In any case, proceed with the algorithm as
                   4947:       written in the following steps.</p>
                   4948: 
                   4949:      </li>
                   4950: 
                   4951:      <li><p>Let the <var title="">furthest block</var> be the
                   4952:      topmost node in the <a href="#stack-of-open-elements">stack of open elements</a> that
                   4953:      is lower in the stack than the <var title="">formatting
                   4954:      element</var>, and is not an element in the
                   4955:      <a href="#phrasing">phrasing</a> or <a href="#formatting">formatting</a>
                   4956:      categories. There might not be one.</p></li>
                   4957: 
                   4958:      <li><p>If there is no <var title="">furthest block</var>,
                   4959:      then the UA must skip the subsequent steps and instead just
                   4960:      pop all the nodes from the bottom of the <a href="#stack-of-open-elements">stack of open
                   4961:      elements</a>, from the <a href="#current-node">current node</a> up to and
                   4962:      including the <var title="">formatting element</var>, and
                   4963:      remove the <var title="">formatting element</var> from the
                   4964:      <a href="#list-of-active-formatting-elements">list of active formatting elements</a>.</p></li>
                   4965: 
                   4966:      <li><p>Let the <var title="">common ancestor</var> be the element
                   4967:      immediately above the <var title="">formatting element</var> in the
                   4968:      <a href="#stack-of-open-elements">stack of open elements</a>.</p></li>
                   4969: 
                   4970:      <li><p>Let a bookmark note the position of the <var title="">formatting element</var> in the <a href="#list-of-active-formatting-elements">list of active
                   4971:      formatting elements</a> relative to the elements on either
                   4972:      side of it in the list.</p></li>
                   4973: 
                   4974:      <li>
                   4975: 
                   4976:       <p>Let <var title="">node</var> and <var title="">last node</var> be the
                   4977:       <var title="">furthest block</var>. Follow these steps:</p>
                   4978: 
                   4979:       <ol><li>Let <var title="">node</var> be the element immediately
                   4980:        above <var title="">node</var> in the <a href="#stack-of-open-elements">stack of open
                   4981:        elements</a>.</li>
                   4982: 
                   4983:        <li>If <var title="">node</var> is not in the <a href="#list-of-active-formatting-elements">list of
                   4984:        active formatting elements</a>, then remove <var title="">node</var> from the <a href="#stack-of-open-elements">stack of open
                   4985:        elements</a> and then go back to step 1.</li>
                   4986: 
                   4987:        <li>Otherwise, if <var title="">node</var> is the <var title="">formatting element</var>, then go to the next step
                   4988:        in the overall algorithm.</li>
                   4989: 
                   4990:        <li>Otherwise, if <var title="">last node</var> is the <var title="">furthest block</var>, then move the aforementioned
                   4991:        bookmark to be immediately after the <var title="">node</var> in the <a href="#list-of-active-formatting-elements">list of active formatting
                   4992:        elements</a>.</li>
                   4993: 
                   4994:        <li><a href="#create-an-element-for-the-token">Create an element for the token</a> for which the
                   4995:        element <var title="">node</var> was created, replace the entry
                   4996:        for <var title="">node</var> in the <a href="#list-of-active-formatting-elements">list of active
                   4997:        formatting elements</a> with an entry for the new element,
                   4998:        replace the entry for <var title="">node</var> in the
                   4999:        <a href="#stack-of-open-elements">stack of open elements</a> with an entry for the new
                   5000:        element, and let <var title="">node</var> be the new
                   5001:        element.</li>
                   5002: 
                   5003:        <li>Insert <var title="">last node</var> into <var title="">node</var>, first removing it from its previous
                   5004:        parent node if any.</li>
                   5005: 
                   5006:        <li>Let <var title="">last node</var> be <var title="">node</var>.</li>
                   5007: 
                   5008:        <li>Return to step 1 of this inner set of steps.</li>
                   5009: 
                   5010:       </ol></li>
                   5011: 
                   5012:      <li>
                   5013: 
                   5014:       <p>If the <var title="">common ancestor</var> node is a
                   5015:       <code><a href="tabular-data.html#the-table-element">table</a></code>, <code><a href="tabular-data.html#the-tbody-element">tbody</a></code>, <code><a href="tabular-data.html#the-tfoot-element">tfoot</a></code>,
                   5016:       <code><a href="tabular-data.html#the-thead-element">thead</a></code>, or <code><a href="tabular-data.html#the-tr-element">tr</a></code> element, then,
                   5017:       <a href="#foster-parent">foster parent</a> whatever <var title="">last
                   5018:       node</var> ended up being in the previous step, first removing
                   5019:       it from its previous parent node if any.</p>
                   5020: 
                   5021:       <p>Otherwise, append whatever <var title="">last node</var>
                   5022:       ended up being in the previous step to the <var title="">common
                   5023:       ancestor</var> node, first removing it from its previous parent
                   5024:       node if any.</p>
                   5025: 
                   5026:      </li>
                   5027: 
                   5028:      <li><p><a href="#create-an-element-for-the-token">Create an element for the token</a> for which the
                   5029:      <var title="">formatting element</var> was created.</p></li>
                   5030: 
                   5031:      <li><p>Take all of the child nodes of the <var title="">furthest
                   5032:      block</var> and append them to the element created in the last
                   5033:      step.</p></li>
                   5034: 
                   5035:      <li><p>Append that new element to the <var title="">furthest
                   5036:      block</var>.</p></li>
                   5037: 
                   5038:      <li><p>Remove the <var title="">formatting element</var> from the
                   5039:      <a href="#list-of-active-formatting-elements">list of active formatting elements</a>, and insert the
                   5040:      new element into the <a href="#list-of-active-formatting-elements">list of active formatting
                   5041:      elements</a> at the position of the aforementioned
                   5042:      bookmark.</p></li>
                   5043: 
                   5044:      <li><p>Remove the <var title="">formatting element</var> from the
                   5045:      <a href="#stack-of-open-elements">stack of open elements</a>, and insert the new element
                   5046:      into the <a href="#stack-of-open-elements">stack of open elements</a> immediately below
                   5047:      the position of the <var title="">furthest block</var> in that
                   5048:      stack.</p></li>
                   5049: 
                   5050:      <li><p>Jump back to step 1 in this series of steps.</p></li>
                   5051: 
                   5052:     </ol><!--XXX
                   5053:     <div class="example">
                   5054:      <p class="XXX">Need an example.</p>
                   5055:     </div>
                   5056: --><p class="note">Because of the way this algorithm causes elements to
                   5057:     change parents, it has been dubbed the "adoption agency algorithm"
                   5058:     (in contrast with other possibly algorithms for dealing with
                   5059:     misnested content, which included the "incest algorithm", the
                   5060:     "secret affair algorithm", and the "Heisenberg algorithm").</p>
                   5061: 
                   5062:    </dd>
                   5063: 
                   5064:    <dt>A start tag whose tag name is "button"</dt>
                   5065:    <dd>
                   5066: 
                   5067:     <p>If the <a href="#stack-of-open-elements">stack of open elements</a> <a href="#has-an-element-in-scope" title="has
                   5068:     an element in scope">has a <code>button</code> element in
                   5069:     scope</a>, then this is a <a href="#parse-error">parse error</a>;
                   5070:     act as if an end tag with the tag name "button" had been seen,
                   5071:     then reprocess the token.</p>
                   5072: 
                   5073:     <p>Otherwise:</p>
                   5074: 
                   5075:     <p><a href="#reconstruct-the-active-formatting-elements">Reconstruct the active formatting elements</a>, if
                   5076:     any.</p>
                   5077: 
                   5078:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
                   5079: 
                   5080:     <p>Insert a marker at the end of the <a href="#list-of-active-formatting-elements">list of active
                   5081:     formatting elements</a>.</p>
                   5082: 
                   5083:     <p>Set the <a href="#frameset-ok-flag">frameset-ok flag</a> to "not ok".</p>
                   5084: 
                   5085:    </dd>
                   5086: 
                   5087:    <dt>A start tag token whose tag name is one of: "applet",
                   5088:    "marquee", "object"</dt>
                   5089:    <dd>
                   5090: 
                   5091:     <p><a href="#reconstruct-the-active-formatting-elements">Reconstruct the active formatting elements</a>, if
                   5092:     any.</p>
                   5093: 
                   5094:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
                   5095: 
                   5096:     <p>Insert a marker at the end of the <a href="#list-of-active-formatting-elements">list of active
                   5097:     formatting elements</a>.</p>
                   5098: 
                   5099:     <p>Set the <a href="#frameset-ok-flag">frameset-ok flag</a> to "not ok".</p>
                   5100: 
                   5101:    </dd>
                   5102: 
                   5103:    <dt>An end tag token whose tag name is one of: "applet", "button",
                   5104:    "marquee", "object"</dt>
                   5105:    <dd>
                   5106: 
                   5107:     <p>If the <a href="#stack-of-open-elements">stack of open elements</a> does not <a href="#has-an-element-in-scope" title="has an element in scope">have an element in scope</a>
                   5108:     with the same tag name as that of the token, then this is a
                   5109:     <a href="#parse-error">parse error</a>; ignore the token.</p>
                   5110: 
                   5111:     <p>Otherwise, run these steps:</p>
                   5112: 
                   5113:     <ol><li><p><a href="#generate-implied-end-tags">Generate implied end tags</a>.</p></li>
                   5114: 
                   5115:      <li><p>If the <a href="#current-node">current node</a> is not an element with
                   5116:      the same tag name as that of the token, then this is a
                   5117:      <a href="#parse-error">parse error</a>.</p></li>
                   5118: 
                   5119:      <li><p>Pop elements from the <a href="#stack-of-open-elements">stack of open elements</a>
                   5120:      until an element with the same tag name as the token has been
                   5121:      popped from the stack.</p></li>
                   5122: 
                   5123:      <li><a href="#clear-the-list-of-active-formatting-elements-up-to-the-last-marker">Clear the list of active formatting elements up to the
                   5124:      last marker</a>.</li>
                   5125: 
                   5126:     </ol></dd>
                   5127: 
                   5128:    <dt>A start tag whose tag name is "table"</dt>
                   5129:    <dd>
                   5130: 
                   5131:     <p>If the <code>Document</code> is <em>not</em> set to
                   5132:     <a href="dom.html#quirks-mode">quirks mode</a>, and the <a href="#stack-of-open-elements">stack of open
                   5133:     elements</a> <a href="#has-an-element-in-scope" title="has an element in scope">has a
                   5134:     <code>p</code> element in scope</a>, then act as if an end tag
                   5135:     with the tag name "p" had been seen.</p> <!-- i hate myself (this
                   5136:     quirk was basically caused by acid2; if i'd realised we could
                   5137:     change the specs when i wrote acid2, we could have avoided having
                   5138:     any parsing-mode quirks) -Hixie -->
                   5139: 
                   5140:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
                   5141: 
                   5142:     <p>Set the <a href="#frameset-ok-flag">frameset-ok flag</a> to "not ok".</p>
                   5143: 
                   5144:     <p>Switch the <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-intable" title="insertion mode: in table">in table</a>".</p>
                   5145: 
                   5146:    </dd>
                   5147: 
                   5148:    <dt>A start tag whose tag name is one of: "area", "basefont",
                   5149:    "bgsound", "br", "embed", "img", "input", "keygen", "spacer",
                   5150:    "wbr"</dt>
                   5151:    <dd>
                   5152: 
                   5153:     <p><a href="#reconstruct-the-active-formatting-elements">Reconstruct the active formatting elements</a>, if
                   5154:     any.</p>
                   5155: 
                   5156:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token. Immediately
                   5157:     pop the <a href="#current-node">current node</a> off the <a href="#stack-of-open-elements">stack of open
                   5158:     elements</a>.</p>
                   5159: 
                   5160:     <p><a href="#acknowledge-self-closing-flag" title="acknowledge self-closing flag">Acknowledge the
                   5161:     token's <i>self-closing flag</i></a>, if it is set.</p>
                   5162: 
                   5163:     <p>Set the <a href="#frameset-ok-flag">frameset-ok flag</a> to "not ok".</p> <!--
                   5164:     shouldn't really do it for <area>, <basefont>, <bgsound>, and
                   5165:     <spacer> -->
                   5166: 
                   5167:    </dd>
                   5168: 
                   5169:    <dt>A start tag whose tag name is one of: "param", "source"</dt>
                   5170:    <dd>
                   5171: 
                   5172:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token. Immediately
                   5173:     pop the <a href="#current-node">current node</a> off the <a href="#stack-of-open-elements">stack of open
                   5174:     elements</a>.</p>
                   5175: 
                   5176:     <p><a href="#acknowledge-self-closing-flag" title="acknowledge self-closing flag">Acknowledge the
                   5177:     token's <i>self-closing flag</i></a>, if it is set.</p>
                   5178: 
                   5179:    </dd>
                   5180: 
                   5181:    <dt>A start tag whose tag name is "hr"</dt>
                   5182:    <dd>
                   5183: 
                   5184:     <p>If the <a href="#stack-of-open-elements">stack of open elements</a> <a href="#has-an-element-in-scope" title="has
                   5185:     an element in scope">has a <code>p</code> element in
                   5186:     scope</a>, then act as if an end tag with the tag name
                   5187:     "p" had been seen.</p>
                   5188: 
                   5189:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token. Immediately
                   5190:     pop the <a href="#current-node">current node</a> off the <a href="#stack-of-open-elements">stack of open
                   5191:     elements</a>.</p>
                   5192: 
                   5193:     <p><a href="#acknowledge-self-closing-flag" title="acknowledge self-closing flag">Acknowledge the
                   5194:     token's <i>self-closing flag</i></a>, if it is set.</p>
                   5195: 
                   5196:     <p>Set the <a href="#frameset-ok-flag">frameset-ok flag</a> to "not ok".</p>
                   5197: 
                   5198:    </dd>
                   5199: 
                   5200:    <dt>A start tag whose tag name is "image"</dt>
                   5201:    <dd>
                   5202:     <p><a href="#parse-error">Parse error</a>. Change the token's tag name
                   5203:     to "img" and reprocess it. (Don't ask.)</p> <!-- As of
                   5204:     2005-12, studies showed that around 0.2% of pages used the
                   5205:     <image> element. -->
                   5206:    </dd>
                   5207: 
                   5208:    <dt id="isindex">A start tag whose tag name is "isindex"</dt>
                   5209:    <dd>
                   5210: 
                   5211:     <p><a href="#parse-error">Parse error</a>.</p>
                   5212: 
                   5213:     <p>If the <a href="#form-element-pointer"><code title="">form</code> element
                   5214:     pointer</a> is not null, then ignore the token.</p>
                   5215: 
                   5216:     <p>Otherwise:</p>
                   5217: 
                   5218:     <p><a href="#acknowledge-self-closing-flag" title="acknowledge self-closing flag">Acknowledge the
                   5219:     token's <i>self-closing flag</i></a>, if it is set.</p> <!--
                   5220:     purely to reduce the number of errors (we don't care if they
                   5221:     included the /, they're not supposed to be including the tag at
                   5222:     all! -->
                   5223: 
                   5224:     <p>Act as if a start tag token with the tag name "form" had been seen.</p>
                   5225: 
                   5226:     <p>If the token has an attribute called "action", set the
                   5227:     <code title="attr-form-action">action</code> attribute on the
                   5228:     resulting <code><a href="forms.html#the-form-element">form</a></code> element to the value of the
                   5229:     "action" attribute of the token.</p>
                   5230: 
                   5231:     <p>Act as if a start tag token with the tag name "hr" had been
                   5232:     seen.</p>
                   5233: 
                   5234:     <p>Act as if a start tag token with the tag name "label" had been
                   5235:     seen.</p>
                   5236: 
                   5237:     <p>Act as if a stream of character tokens had been seen (see below
                   5238:     for what they should say).</p>
                   5239: 
                   5240:     <p>Act as if a start tag token with the tag name "input" had been
                   5241:     seen, with all the attributes from the "isindex" token except
                   5242:     "name", "action", and "prompt". Set the <code title="attr-fe-name"><a href="forms.html#attr-fe-name">name</a></code> attribute of the resulting
                   5243:     <code><a href="forms.html#the-input-element">input</a></code> element to the value "<code title="">isindex</code>".</p>
                   5244: 
                   5245:     <p>Act as if a stream of character tokens had been seen (see
                   5246:     below for what they should say).</p>
                   5247: 
                   5248:     <p>Act as if an end tag token with the tag name "label" had been
                   5249:     seen.</p>
                   5250: 
                   5251:     <p>Act as if a start tag token with the tag name "hr" had been
                   5252:     seen.</p>
                   5253: 
                   5254:     <p>Act as if an end tag token with the tag name "form" had been
                   5255:     seen.</p>
                   5256: 
                   5257:     <p>If the token has an attribute with the name "prompt", then the
                   5258:     first stream of characters must be the same string as given in
                   5259:     that attribute, and the second stream of characters must be
                   5260:     empty. Otherwise, the two streams of character tokens together
                   5261:     should, together with the <code><a href="forms.html#the-input-element">input</a></code> element, express the
                   5262:     equivalent of "This is a searchable index. Insert your search
                   5263:     keywords here: (input field)" in the user's preferred
                   5264:     language.</p>
                   5265: 
                   5266:    </dd>
                   5267: 
                   5268:    <dt>A start tag whose tag name is "textarea"</dt>
                   5269:    <dd>
                   5270: 
                   5271:     <ol><li><p><a href="#insert-an-html-element">Insert an HTML element</a> for the
                   5272:      token.</p></li>
                   5273: 
                   5274:      <li><p>If the next token is a U+000A LINE FEED (LF) character
                   5275:      token, then ignore that token and move on to the next
                   5276:      one. (Newlines at the start of <code><a href="forms.html#the-textarea-element">textarea</a></code> elements are
                   5277:      ignored as an authoring convenience.)</p></li>
                   5278: 
                   5279:      <li><p>Switch the tokenizer's <a href="#content-model-flag">content model flag</a> to
                   5280:      the RCDATA state.</p></li>
                   5281: 
                   5282:      <li><p>Let the <a href="#original-insertion-mode">original insertion mode</a> be the
                   5283:      current <a href="#insertion-mode">insertion mode</a>.</p>
                   5284: 
                   5285:      </li><li><p>Set the <a href="#frameset-ok-flag">frameset-ok flag</a> to "not
                   5286:      ok".</p></li>
                   5287: 
1.91      mike     5288:      <li><p>Switch the <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-incdata" title="insertion mode: in RAWTEXT/RCDATA">in
                   5289:      RAWTEXT/RCDATA</a>".</p></li>
1.1       mike     5290: 
                   5291:     </ol></dd>
                   5292: 
                   5293:    <dt>A start tag whose tag name is "xmp"</dt>
                   5294:    <dd>
                   5295: 
                   5296:     <p><a href="#reconstruct-the-active-formatting-elements">Reconstruct the active formatting elements</a>, if
                   5297:     any.</p>
                   5298: 
                   5299:     <p>Set the <a href="#frameset-ok-flag">frameset-ok flag</a> to "not ok".</p>
                   5300: 
1.91      mike     5301:     <p>Follow the <a href="#generic-raw-text-element-parsing-algorithm">generic raw text element parsing algorithm</a>.</p>
1.1       mike     5302: 
                   5303:    </dd>
                   5304: 
                   5305:    <dt>A start tag whose tag name is "iframe"</dt>
                   5306:    <dd>
                   5307: 
                   5308:     <p>Set the <a href="#frameset-ok-flag">frameset-ok flag</a> to "not ok".</p>
                   5309: 
1.91      mike     5310:     <p>Follow the <a href="#generic-raw-text-element-parsing-algorithm">generic raw text element parsing algorithm</a>.</p>
1.1       mike     5311: 
                   5312:    </dd>
                   5313: 
                   5314:    <dt>A start tag whose tag name is "noembed"</dt>
                   5315:    <dt>A start tag whose tag name is "noscript", if the <a href="#scripting-flag">scripting flag</a> is enabled</dt>
                   5316:    <dd>
                   5317: 
1.91      mike     5318:     <p>Follow the <a href="#generic-raw-text-element-parsing-algorithm">generic raw text element parsing algorithm</a>.</p>
1.1       mike     5319: 
                   5320:    </dd>
                   5321: 
                   5322:    <dt>A start tag whose tag name is "select"</dt>
                   5323:    <dd>
                   5324: 
                   5325:     <p><a href="#reconstruct-the-active-formatting-elements">Reconstruct the active formatting elements</a>, if
                   5326:     any.</p>
                   5327: 
                   5328:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
                   5329: 
                   5330:     <p>Set the <a href="#frameset-ok-flag">frameset-ok flag</a> to "not ok".</p>
                   5331: 
                   5332:     <p>If the <a href="#insertion-mode">insertion mode</a> is one of <a href="#parsing-main-intable" title="insertion mode: in table">in table</a>", "<a href="#parsing-main-incaption" title="insertion mode: in caption">in caption</a>", "<a href="#parsing-main-incolgroup" title="insertion mode: in column group">in column group</a>",
                   5333:     "<a href="#parsing-main-intbody" title="insertion mode: in table body">in table
                   5334:     body</a>", "<a href="#parsing-main-intr" title="insertion mode: in row">in
                   5335:     row</a>", or "<a href="#parsing-main-intd" title="insertion mode: in cell">in
                   5336:     cell</a>", then switch the <a href="#insertion-mode">insertion mode</a> to
                   5337:     "<a href="#parsing-main-inselectintable" title="insertion mode: in select in table">in select in
                   5338:     table</a>". Otherwise, switch the <a href="#insertion-mode">insertion mode</a>
                   5339:     to "<a href="#parsing-main-inselect" title="insertion mode: in select">in select</a>".</p>
                   5340: 
                   5341:    </dd>
                   5342: 
                   5343:    <dt>A start tag whose tag name is one of: "optgroup", "option"</dt>
                   5344:    <dd>
                   5345: 
                   5346:     <p>If the <a href="#stack-of-open-elements">stack of open elements</a> <a href="#has-an-element-in-scope" title="has an
                   5347:     element in scope">has an <code>option</code> element in
                   5348:     scope</a>, then act as if an end tag with the tag name "option"
                   5349:     had been seen.</p>
                   5350: 
                   5351:     <p><a href="#reconstruct-the-active-formatting-elements">Reconstruct the active formatting elements</a>, if
                   5352:     any.</p>
                   5353: 
                   5354:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
                   5355: 
                   5356:    </dd>
                   5357: 
                   5358:    <dt>A start tag whose tag name is one of: "rp", "rt"</dt>
                   5359:    <dd>
                   5360: 
                   5361:     <!-- the parsing rules for ruby really don't match IE much at all,
                   5362:          but in practice the markup used is very simple and so strict
                   5363:          compatibility with IE isn't required. For example, as defined
                   5364:          here we get very, very different behaviour than IE for
                   5365:          pathological cases like:
                   5366: 
                   5367:            <ruby><ol><li><p>a<rt>b
                   5368:            <ruby>a<rt>b<p>c
                   5369: 
                   5370:          But in practice most ruby markup falls into these cases:
                   5371: 
                   5372:            <ruby>a<rt>b</ruby>
                   5373:            <ruby>a<rp>b<rt>c<rp>d</ruby>
                   5374:            <ruby>a<rt>b</rt></ruby>
                   5375:            <ruby>a<rp>b</rp><rt>c</rt><rp>d</rp></ruby>
                   5376: 
                   5377:     -->
                   5378: 
                   5379:     <p>If the <a href="#stack-of-open-elements">stack of open elements</a> <a href="#has-an-element-in-scope" title="has an
                   5380:     element in scope">has a <code>ruby</code> element in scope</a>,
                   5381:     then <a href="#generate-implied-end-tags">generate implied end tags</a>. If the <a href="#current-node">current
                   5382:     node</a> is not then a <code><a href="text-level-semantics.html#the-ruby-element">ruby</a></code> element, this is a
                   5383:     <a href="#parse-error">parse error</a>; pop all the nodes from the <a href="#current-node">current
                   5384:     node</a> up to the node immediately before the bottommost
                   5385:     <code><a href="text-level-semantics.html#the-ruby-element">ruby</a></code> element on the <a href="#stack-of-open-elements">stack of open
                   5386:     elements</a>.</p>
                   5387: 
                   5388:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
                   5389: 
                   5390:    </dd>
                   5391: 
                   5392:    <dt>An end tag whose tag name is "br"</dt>
                   5393:    <dd>
                   5394:     <p><a href="#parse-error">Parse error</a>. Act as if a start tag token with
                   5395:     the tag name "br" had been seen. Ignore the end tag token.</p>
                   5396:    </dd>
                   5397: 
                   5398:    <dt>A start tag whose tag name is "math"</dt>
                   5399:    <dd>
                   5400: 
                   5401:     <p><a href="#reconstruct-the-active-formatting-elements">Reconstruct the active formatting elements</a>, if
                   5402:     any.</p>
                   5403: 
                   5404:     <p><a href="#adjust-mathml-attributes">Adjust MathML attributes</a> for the token. (This
                   5405:     fixes the case of MathML attributes that are not all
                   5406:     lowercase.)</p>
                   5407: 
                   5408:     <p><a href="#adjust-foreign-attributes">Adjust foreign attributes</a> for the token. (This
                   5409:     fixes the use of namespaced attributes, in particular XLink.)</p>
                   5410: 
                   5411:     <p><a href="#insert-a-foreign-element">Insert a foreign element</a> for the token, in the
                   5412:     <a href="#mathml-namespace">MathML namespace</a>.</p>
                   5413: 
                   5414:     <!-- If we ever change the frameset-ok flag to an insertion mode,
                   5415:     the following change would be implied, except we'd have to do it
                   5416:     even in the face of a self-closed tag:
                   5417:     <p>Set the <span>frameset-ok flag</span> to "not ok".</p>
                   5418:     -->
                   5419: 
                   5420:     <p>If the token has its <i>self-closing flag</i> set, pop the
                   5421:     <a href="#current-node">current node</a> off the <a href="#stack-of-open-elements">stack of open
                   5422:     elements</a> and <a href="#acknowledge-self-closing-flag" title="acknowledge self-closing
                   5423:     flag">acknowledge the token's <i>self-closing flag</i></a>.</p>
                   5424: 
                   5425:     <p>Otherwise, if the <a href="#insertion-mode">insertion mode</a> is not already
                   5426:     "<a href="#parsing-main-inforeign" title="insertion mode: in foreign content">in foreign
                   5427:     content</a>", let the <a href="#secondary-insertion-mode">secondary insertion mode</a> be
                   5428:     the current <a href="#insertion-mode">insertion mode</a>, and then switch the
                   5429:     <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-inforeign" title="insertion mode: in
                   5430:     foreign content">in foreign content</a>".</p>
                   5431: 
                   5432:    </dd>
                   5433: 
                   5434:    <dt>A start tag whose tag name is "svg"</dt>
                   5435:    <dd>
                   5436: 
                   5437:     <p><a href="#reconstruct-the-active-formatting-elements">Reconstruct the active formatting elements</a>, if
                   5438:     any.</p>
                   5439: 
                   5440:     <p><a href="#adjust-svg-attributes">Adjust SVG attributes</a> for the token. (This fixes
                   5441:     the case of SVG attributes that are not all lowercase.)</p>
                   5442: 
                   5443:     <p><a href="#adjust-foreign-attributes">Adjust foreign attributes</a> for the token. (This
                   5444:     fixes the use of namespaced attributes, in particular XLink in
                   5445:     SVG.)</p>
                   5446: 
                   5447:     <p><a href="#insert-a-foreign-element">Insert a foreign element</a> for the token, in the
                   5448:     <a href="#svg-namespace">SVG namespace</a>.</p>
                   5449: 
                   5450:     <!-- If we ever change the frameset-ok flag to an insertion mode,
                   5451:     the following change would be implied, except we'd have to do it
                   5452:     even in the face of a self-closed tag:
                   5453:     <p>Set the <span>frameset-ok flag</span> to "not ok".</p>
                   5454:     -->
                   5455: 
                   5456:     <p>If the token has its <i>self-closing flag</i> set, pop the
                   5457:     <a href="#current-node">current node</a> off the <a href="#stack-of-open-elements">stack of open
                   5458:     elements</a> and <a href="#acknowledge-self-closing-flag" title="acknowledge self-closing
                   5459:     flag">acknowledge the token's <i>self-closing flag</i></a>.</p>
                   5460: 
                   5461:     <p>Otherwise, if the <a href="#insertion-mode">insertion mode</a> is not already
                   5462:     "<a href="#parsing-main-inforeign" title="insertion mode: in foreign content">in foreign
                   5463:     content</a>", let the <a href="#secondary-insertion-mode">secondary insertion mode</a> be
                   5464:     the current <a href="#insertion-mode">insertion mode</a>, and then switch the
                   5465:     <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-inforeign" title="insertion mode: in
                   5466:     foreign content">in foreign content</a>".</p>
                   5467: 
                   5468:    </dd>
                   5469: 
                   5470:    <dt>A start <!--or end--> tag whose tag name is one of: "caption",
                   5471:    "col", "colgroup", "frame", "head", "tbody", "td", "tfoot", "th",
                   5472:    "thead", "tr"</dt>
                   5473:    <!--<dt>An end tag whose tag name is one of: "area", "base",
                   5474:    "basefont", "bgsound", "command", "embed", "hr", "iframe", "image",
                   5475:    "img", "input", "isindex", "keygen", "link", "meta", "noembed",
                   5476:    "noframes", "param", "script", "select", "source", "spacer",
                   5477:    "style", "table", "textarea", "title", "wbr"</dt>-->
                   5478:    <!--<dt>An end tag whose tag name is "noscript", if the
                   5479:    <span>scripting flag</span> is enabled</dt>-->
                   5480:    <dd>
                   5481:     <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
                   5482:     <!-- end tags are commented out because since they can never end
                   5483:     up on the stack anyway, the default end tag clause will
                   5484:     automatically handle them. we don't want to have text in the spec
                   5485:     that is just an optimisation, as that detracts from the spec
                   5486:     itself -->
                   5487:    </dd>
                   5488: 
                   5489:    <dt>Any other start tag</dt>
                   5490:    <dd>
                   5491: 
                   5492:     <p><a href="#reconstruct-the-active-formatting-elements">Reconstruct the active formatting elements</a>, if
                   5493:     any.</p>
                   5494: 
                   5495:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
                   5496: 
                   5497:     <p class="note">This element will be a <a href="#phrasing">phrasing</a>
                   5498:     element.</p>
                   5499: 
                   5500:    </dd>
                   5501: 
                   5502:    <dt>Any other end tag</dt>
                   5503:    <dd>
                   5504: 
                   5505:     <p>Run the following steps:</p>
                   5506: 
                   5507:     <ol><li><p>Initialize <var title="">node</var> to be the <a href="#current-node">current
                   5508:      node</a> (the bottommost node of the stack).</p></li>
                   5509: 
                   5510:      <li><p>If <var title="">node</var> has the same tag name as
                   5511:      the end tag token, then:</p>
                   5512: 
                   5513:       <ol><li><p><a href="#generate-implied-end-tags">Generate implied end tags</a>.</p></li>
                   5514: 
                   5515:        <li><p>If the tag name of the end tag token does not match
                   5516:        the tag name of the <a href="#current-node">current node</a>, this is a
                   5517:        <a href="#parse-error">parse error</a>.</p></li>
                   5518: 
                   5519:        <li><p>Pop all the nodes from the <a href="#current-node">current node</a> up
                   5520:        to <var title="">node</var>, including <var title="">node</var>, then stop these steps.</p></li>
                   5521: 
                   5522:       </ol></li>
                   5523: 
                   5524:      <li><p>Otherwise, if <var title="">node</var> is in neither the
                   5525:      <a href="#formatting">formatting</a> category nor the <a href="#phrasing">phrasing</a>
                   5526:      category, then this is a <a href="#parse-error">parse error</a>; ignore the
                   5527:      token, and abort these steps.</p></li>
                   5528: 
                   5529:      <li><p>Set <var title="">node</var> to the previous entry in the
                   5530:      <a href="#stack-of-open-elements">stack of open elements</a>.</p></li>
                   5531: 
                   5532:      <li><p>Return to step 2.</p></li>
                   5533: 
                   5534:     </ol></dd>
                   5535: 
1.91      mike     5536:   </dl><h5 id="parsing-main-incdata"><span class="secno">9.2.5.11 </span>The "<dfn title="insertion mode: in RAWTEXT/RCDATA">in RAWTEXT/RCDATA</dfn>" insertion mode</h5>
1.1       mike     5537: 
                   5538:   <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-incdata" title="insertion
1.91      mike     5539:   mode: in RAWTEXT/RCDATA">in RAWTEXT/RCDATA</a>", tokens must be
1.1       mike     5540:   handled as follows:</p>
                   5541: 
                   5542:   <dl class="switch"><dt>A character token</dt>
                   5543:    <dd>
                   5544: 
                   5545:     <p><a href="#insert-a-character" title="insert a character">Insert the token's
                   5546:     character</a> into the <a href="#current-node">current node</a>.</p>
                   5547: 
                   5548:    </dd>
                   5549: 
                   5550:    <dt>An end-of-file token</dt>
                   5551:    <dd>
                   5552: 
                   5553:     <!-- can't be the fragment case -->
                   5554:     <p><a href="#parse-error">Parse error</a>.</p>
                   5555: 
                   5556:     <p>If the <a href="#current-node">current node</a> is a <code><a href="semantics.html#script">script</a></code>
                   5557:     element, mark the <code><a href="semantics.html#script">script</a></code> element as <a href="semantics.html#already-executed">"already
                   5558:     executed"</a>.</p>
                   5559: 
                   5560:     <p>Pop the <a href="#current-node">current node</a> off the <a href="#stack-of-open-elements">stack of open
                   5561:     elements</a>.</p>
                   5562: 
                   5563:     <p>Switch the <a href="#insertion-mode">insertion mode</a> to the <a href="#original-insertion-mode">original
                   5564:     insertion mode</a> and reprocess the current token.</p>
                   5565: 
                   5566:    </dd>
                   5567: 
                   5568:    <dt>An end tag whose tag name is "script"</dt>
                   5569:    <dd>
                   5570: 
                   5571:     <p>Let <var title="">script</var> be the <a href="#current-node">current node</a>
                   5572:     (which will be a <code><a href="semantics.html#script">script</a></code> element).</p>
                   5573: 
                   5574:     <p>Pop the <a href="#current-node">current node</a> off the <a href="#stack-of-open-elements">stack of open
                   5575:     elements</a>.</p>
                   5576: 
                   5577:     <p>Switch the <a href="#insertion-mode">insertion mode</a> to the <a href="#original-insertion-mode">original
                   5578:     insertion mode</a>.</p>
                   5579: 
                   5580:     <p>Let the <var title="">old insertion point</var> have the
                   5581:     same value as the current <a href="#insertion-point">insertion point</a>. Let
                   5582:     the <a href="#insertion-point">insertion point</a> be just before the <a href="#next-input-character">next
                   5583:     input character</a>.</p>
                   5584: 
                   5585:     <p>Increment the parser's <a href="#script-nesting-level">script nesting level</a> by
                   5586:     one.</p>
                   5587: 
                   5588:     <p><a href="semantics.html#running-a-script" title="running a script">Run</a> the <var title="">script</var>. This might cause some script to execute,
                   5589:     which might cause <a href="dom.html#dom-document-write" title="dom-document-write">new characters
                   5590:     to be inserted into the tokenizer</a>, and might cause the
                   5591:     tokenizer to output more tokens, resulting in a <a href="#nestedParsing">reentrant invocation of the parser</a>.</p>
                   5592: 
                   5593:     <p>Decrement the parser's <a href="#script-nesting-level">script nesting level</a> by
                   5594:     one. If the parser's <a href="#script-nesting-level">script nesting level</a> is zero,
                   5595:     then set the <a href="#parser-pause-flag">parser pause flag</a> to false.</p>
                   5596: 
                   5597:     <p>Let the <a href="#insertion-point">insertion point</a> have the value of the <var title="">old insertion point</var>. (In other words, restore the
                   5598:     <a href="#insertion-point">insertion point</a> to its previous value. This value
                   5599:     might be the "undefined" value.)</p>
                   5600: 
                   5601:     <p id="scriptTagParserResumes">At this stage, if there is a
                   5602:     <a href="semantics.html#pending-external-script">pending external script</a>, then:</p>
                   5603: 
                   5604:     <dl class="switch"><dt>If the <a href="#script-nesting-level">script nesting level</a> is not zero:</dt>
                   5605: 
                   5606:      <dd>
                   5607: 
                   5608:       <p>Set the <a href="#parser-pause-flag">parser pause flag</a> to true, and abort the
                   5609:       processing of any nested invocations of the tokenizer, yielding
                   5610:       control back to the caller. (Tokenization will resume when the
                   5611:       caller returns to the "outer" tree construction stage.)</p>
                   5612: 
                   5613:       <p class="note">The tree construction stage of this particular
                   5614:       parser is <a href="#nestedParsing">being called reentrantly</a>,
                   5615:       say from a call to <code title="dom-document-write"><a href="dom.html#dom-document-write">document.write()</a></code>.</p>
                   5616: 
                   5617:      </dd>
                   5618: 
                   5619: 
                   5620:      <dt>Otherwise:</dt>
                   5621: 
                   5622:      <dd>
                   5623: 
                   5624:       <p>Follow these steps:</p>
                   5625: 
                   5626:       <ol><li><p>Let <var title="">the script</var> be the <a href="semantics.html#pending-external-script">pending
                   5627:        external script</a>. There is no longer a <a href="semantics.html#pending-external-script">pending
                   5628:        external script</a>.</p></li>
                   5629: 
                   5630:        <li><p><a href="browsers.html#pause">Pause</a> until the script has <a href="semantics.html#completed-loading">completed
                   5631:        loading</a>.</p></li>
                   5632: 
                   5633:        <li><p>Let the <a href="#insertion-point">insertion point</a> be just before the
                   5634:        <a href="#next-input-character">next input character</a>.</p></li>
                   5635: 
                   5636:        <li><p>Increment the parser's <a href="#script-nesting-level">script nesting level</a>
                   5637:        by one (it should be zero before this step, so this sets it to
                   5638:        one).</p></li>
                   5639: 
                   5640:        <li><p><a href="semantics.html#executing-a-script-block" title="executing a script block">Execute the
                   5641:        script</a>.</p></li>
                   5642: 
                   5643:        <li><p>Decrement the parser's <a href="#script-nesting-level">script nesting level</a>
                   5644:        by one. If the parser's <a href="#script-nesting-level">script nesting level</a> is
                   5645:        zero (which it always should be at this point), then set the
                   5646:        <a href="#parser-pause-flag">parser pause flag</a> to false.</p>
                   5647: 
                   5648:        </li><li><p>Let the <a href="#insertion-point">insertion point</a> be undefined
                   5649:        again.</p></li>
                   5650: 
                   5651:        <li><p>If there is once again a <a href="semantics.html#pending-external-script">pending external
                   5652:        script</a>, then repeat these steps from step 1.</p></li>
                   5653: 
                   5654:       </ol></dd>
                   5655: 
                   5656:     </dl></dd>
                   5657: 
                   5658:    <dt>Any other end tag</dt>
                   5659:    <dd>
                   5660: 
                   5661:     <p>Pop the <a href="#current-node">current node</a> off the <a href="#stack-of-open-elements">stack of open
                   5662:     elements</a>.</p>
                   5663: 
                   5664:     <p>Switch the <a href="#insertion-mode">insertion mode</a> to the <a href="#original-insertion-mode">original
                   5665:     insertion mode</a>.</p>
                   5666: 
                   5667:    </dd>
                   5668: 
                   5669:   </dl><h5 id="parsing-main-intable"><span class="secno">9.2.5.12 </span>The "<dfn title="insertion mode: in table">in table</dfn>" insertion mode</h5>
                   5670: 
                   5671:   <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-intable" title="insertion
                   5672:   mode: in table">in table</a>", tokens must be handled as follows:</p>
                   5673: 
                   5674:   <dl class="switch"><dt>A character token</dt>
                   5675:    <dd>
                   5676: 
                   5677:      <p>Let the <dfn id="pending-table-character-tokens"><var>pending table character tokens</var></dfn>
                   5678:      be an empty list of tokens.</p>
                   5679: 
                   5680:      <p>Let the <a href="#original-insertion-mode">original insertion mode</a> be the current
                   5681:      <a href="#insertion-mode">insertion mode</a>.</p>
                   5682: 
                   5683:      <p>Switch the <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-intabletext" title="insertion mode: in table text">in table text</a>" and
                   5684:      reprocess the token.</p>
                   5685: 
                   5686:    </dd>
                   5687: 
                   5688:    <dt>A comment token</dt>
                   5689:    <dd>
                   5690:     <p>Append a <code>Comment</code> node to the <a href="#current-node">current
                   5691:     node</a> with the <code title="">data</code> attribute set to
                   5692:     the data given in the comment token.</p>
                   5693:    </dd>
                   5694: 
                   5695:    <dt>A DOCTYPE token</dt>
                   5696:    <dd>
                   5697:     <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
                   5698:    </dd>
                   5699: 
                   5700:    <dt>A start tag whose tag name is "caption"</dt>
                   5701:    <dd>
                   5702: 
                   5703:     <p><a href="#clear-the-stack-back-to-a-table-context">Clear the stack back to a table context</a>. (See
                   5704:     below.)</p>
                   5705: 
                   5706:     <p>Insert a marker at the end of the <a href="#list-of-active-formatting-elements">list of active
                   5707:     formatting elements</a>.</p>
                   5708: 
                   5709:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token, then
                   5710:     switch the <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-incaption" title="insertion mode: in caption">in caption</a>".</p>
                   5711: 
                   5712:    </dd>
                   5713: 
                   5714:    <dt>A start tag whose tag name is "colgroup"</dt>
                   5715:    <dd>
                   5716: 
                   5717:     <p><a href="#clear-the-stack-back-to-a-table-context">Clear the stack back to a table context</a>. (See
                   5718:     below.)</p>
                   5719: 
                   5720:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token, then
                   5721:     switch the <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-incolgroup" title="insertion mode: in column group">in column
                   5722:     group</a>".</p>
                   5723: 
                   5724:    </dd>
                   5725: 
                   5726:    <dt>A start tag whose tag name is "col"</dt>
                   5727:    <dd>
                   5728:     <p>Act as if a start tag token with the tag name "colgroup"
                   5729:     had been seen, then reprocess the current token.</p>
                   5730:    </dd>
                   5731: 
                   5732:    <dt>A start tag whose tag name is one of: "tbody", "tfoot", "thead"</dt>
                   5733:    <dd>
                   5734: 
                   5735:     <p><a href="#clear-the-stack-back-to-a-table-context">Clear the stack back to a table context</a>. (See
                   5736:     below.)</p>
                   5737: 
                   5738:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token, then
                   5739:     switch the <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-intbody" title="insertion mode: in table body">in table
                   5740:     body</a>".</p>
                   5741: 
                   5742:    </dd>
                   5743: 
                   5744:    <dt>A start tag whose tag name is one of: "td", "th", "tr"</dt>
                   5745:    <dd>
                   5746:     <p>Act as if a start tag token with the tag name "tbody" had
                   5747:     been seen, then reprocess the current token.</p>
                   5748:    </dd>
                   5749: 
                   5750:    <dt>A start tag whose tag name is "table"</dt>
                   5751:    <dd>
                   5752: 
                   5753:     <p><a href="#parse-error">Parse error</a>. Act as if an end tag token with
                   5754:     the tag name "table" had been seen, then, if that token wasn't
                   5755:     ignored, reprocess the current token.</p>
                   5756: 
                   5757:     <p class="note">The fake end tag token here can only be
                   5758:     ignored in the <a href="#fragment-case">fragment case</a>.</p>
                   5759: 
                   5760:    </dd>
                   5761: 
                   5762:    <dt>An end tag whose tag name is "table"</dt>
                   5763:    <dd>
                   5764: 
                   5765:     <p>If the <a href="#stack-of-open-elements">stack of open elements</a> does not <a href="#has-an-element-in-table-scope" title="has an element in table scope">have an element in table
                   5766:     scope</a> with the same tag name as the token, this is a
                   5767:     <a href="#parse-error">parse error</a>. Ignore the token. (<a href="#fragment-case">fragment
                   5768:     case</a>)</p>
                   5769: 
                   5770:     <p>Otherwise:</p>
                   5771: 
                   5772:     <p>Pop elements from this stack until a <code><a href="tabular-data.html#the-table-element">table</a></code>
                   5773:     element has been popped from the stack.</p>
                   5774: 
                   5775:     <p><a href="#reset-the-insertion-mode-appropriately">Reset the insertion mode appropriately</a>.</p>
                   5776: 
                   5777:    </dd>
                   5778: 
                   5779:    <dt>An end tag whose tag name is one of: "body", "caption",
                   5780:    "col", "colgroup", "html", "tbody", "td", "tfoot", "th",
                   5781:    "thead", "tr"</dt>
                   5782:    <dd>
                   5783:     <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
                   5784:    </dd>
                   5785: 
                   5786:    <dt>A start tag whose tag name is one of: "style", "script"</dt>
                   5787:    <dd>
                   5788: 
                   5789:     <p>Process the token <a href="#using-the-rules-for">using the rules for</a> the "<a href="#parsing-main-inhead" title="insertion mode: in head">in head</a>" <a href="#insertion-mode">insertion
                   5790:     mode</a>.</p>
                   5791: 
                   5792:    </dd>
                   5793: 
                   5794:    <dt>A start tag whose tag name is "input"</dt>
                   5795:    <dd>
                   5796: 
                   5797:     <p>If the token does not have an attribute with the name "type",
                   5798:     or if it does, but that attribute's value is not an <a href="infrastructure.html#ascii-case-insensitive">ASCII
                   5799:     case-insensitive</a> match for the string "<code title="">hidden</code>", then: act as described in the "anything
                   5800:     else" entry below.</p>
                   5801: 
                   5802:     <p>Otherwise:</p>
                   5803: 
                   5804:     <p><a href="#parse-error">Parse error</a>.</p>
                   5805: 
                   5806:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
                   5807: 
                   5808:     <p>Pop that <code><a href="forms.html#the-input-element">input</a></code> element off the <a href="#stack-of-open-elements">stack of
                   5809:     open elements</a>.</p>
                   5810: 
                   5811:    </dd>
                   5812: 
                   5813:    <dt>An end-of-file token</dt>
                   5814:    <dd>
                   5815: 
                   5816:     <p>If the <a href="#current-node">current node</a> is not the root
                   5817:     <code><a href="semantics.html#the-html-element">html</a></code> element, then this is a <a href="#parse-error">parse
                   5818:     error</a>.</p>
                   5819: 
                   5820:     <p class="note">It can only be the <a href="#current-node">current node</a> in
                   5821:     the <a href="#fragment-case">fragment case</a>.</p>
                   5822: 
                   5823:     <p><a href="#stop-parsing">Stop parsing</a>.</p>
                   5824: 
                   5825:    </dd>
                   5826: 
                   5827:    <dt>Anything else</dt>
                   5828:    <dd>
                   5829: 
                   5830:     <p><a href="#parse-error">Parse error</a>. Process the token <a href="#using-the-rules-for">using the
                   5831:     rules for</a> the "<a href="#parsing-main-inbody" title="insertion mode: in body">in
                   5832:     body</a>" <a href="#insertion-mode">insertion mode</a>, except that if the
                   5833:     <a href="#current-node">current node</a> is a <code><a href="tabular-data.html#the-table-element">table</a></code>,
                   5834:     <code><a href="tabular-data.html#the-tbody-element">tbody</a></code>, <code><a href="tabular-data.html#the-tfoot-element">tfoot</a></code>, <code><a href="tabular-data.html#the-thead-element">thead</a></code>, or
                   5835:     <code><a href="tabular-data.html#the-tr-element">tr</a></code> element, then, whenever a node would be inserted
                   5836:     into the <a href="#current-node">current node</a>, it must instead be <a href="#foster-parent" title="foster parent">foster parented</a>.</p>
                   5837: 
                   5838:    </dd>
                   5839: 
                   5840:   </dl><p>When the steps above require the UA to <dfn id="clear-the-stack-back-to-a-table-context">clear the stack
                   5841:   back to a table context</dfn>, it means that the UA must, while
                   5842:   the <a href="#current-node">current node</a> is not a <code><a href="tabular-data.html#the-table-element">table</a></code>
                   5843:   element or an <code><a href="semantics.html#the-html-element">html</a></code> element, pop elements from the
                   5844:   <a href="#stack-of-open-elements">stack of open elements</a>.</p>
                   5845: 
                   5846:   <p class="note">The <a href="#current-node">current node</a> being an
                   5847:   <code><a href="semantics.html#the-html-element">html</a></code> element after this process is a <a href="#fragment-case">fragment
                   5848:   case</a>.</p>
                   5849: 
                   5850: 
                   5851: 
                   5852:   <h5 id="parsing-main-intabletext"><span class="secno">9.2.5.13 </span>The "<dfn title="insertion mode: in table text">in table text</dfn>" insertion mode</h5>
                   5853: 
                   5854:   <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-intabletext" title="insertion
                   5855:   mode: in table text">in table text</a>", tokens must be handled
                   5856:   as follows:</p>
                   5857: 
                   5858:   <dl class="switch"><dt>A character token</dt>
                   5859:    <dd>
                   5860: 
                   5861:     <p>Append the character token to the <var><a href="#pending-table-character-tokens">pending table character
                   5862:     tokens</a></var> list.</p>
                   5863: 
                   5864:    </dd>
                   5865: 
                   5866: 
                   5867:    <dt>Anything else</dt>
                   5868:    <dd>
                   5869: 
                   5870:     <p>If any of the tokens in the <var><a href="#pending-table-character-tokens">pending table character
                   5871:     tokens</a></var> list are character tokens that are not one of U+0009
                   5872:     CHARACTER TABULATION, U+000A LINE FEED (LF), U+000C FORM FEED
                   5873:     (FF), <!--U+000D CARRIAGE RETURN (CR),--> or U+0020 SPACE, then
                   5874:     reprocess those character tokens using the rules given in the
                   5875:     "anything else" entry in the <a href="#parsing-main-intable" title="insertion mode: in
                   5876:     table">in table</a>" insertion mode.</p>
                   5877: 
                   5878:     <p>Otherwise, <a href="#insert-a-character" title="insert a character">insert the
                   5879:     characters</a> given by the <var><a href="#pending-table-character-tokens">pending table character
                   5880:     tokens</a></var> list into the <a href="#current-node">current node</a>.</p>
                   5881: 
                   5882:     <p>Switch the <a href="#insertion-mode">insertion mode</a> to the <a href="#original-insertion-mode">original
                   5883:     insertion mode</a> and reprocess the token.</p>
                   5884: 
                   5885:    </dd>
                   5886: 
                   5887:   </dl><h5 id="parsing-main-incaption"><span class="secno">9.2.5.14 </span>The "<dfn title="insertion mode: in caption">in caption</dfn>" insertion mode</h5>
                   5888: 
                   5889:   <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-incaption" title="insertion
                   5890:   mode: in caption">in caption</a>", tokens must be handled as follows:</p>
                   5891: 
                   5892:   <dl class="switch"><dt>An end tag whose tag name is "caption"</dt>
                   5893:    <dd>
                   5894: 
                   5895:     <p>If the <a href="#stack-of-open-elements">stack of open elements</a> does not <a href="#has-an-element-in-table-scope" title="has an element in table scope">have an element in table
                   5896:     scope</a> with the same tag name as the token, this is a
                   5897:     <a href="#parse-error">parse error</a>. Ignore the token. (<a href="#fragment-case">fragment
                   5898:     case</a>)</p>
                   5899: 
                   5900:     <p>Otherwise:</p>
                   5901: 
                   5902:     <p><a href="#generate-implied-end-tags">Generate implied end tags</a>.</p>
                   5903: 
                   5904:     <p>Now, if the <a href="#current-node">current node</a> is not a
                   5905:     <code><a href="tabular-data.html#the-caption-element">caption</a></code> element, then this is a <a href="#parse-error">parse
                   5906:     error</a>.</p>
                   5907: 
                   5908:     <p>Pop elements from this stack until a <code><a href="tabular-data.html#the-caption-element">caption</a></code>
                   5909:     element has been popped from the stack.</p>
                   5910: 
                   5911:     <p><a href="#clear-the-list-of-active-formatting-elements-up-to-the-last-marker">Clear the list of active formatting elements up to
                   5912:     the last marker</a>.</p>
                   5913: 
                   5914:     <p>Switch the <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-intable" title="insertion mode: in table">in table</a>".</p>
                   5915: 
                   5916:    </dd>
                   5917: 
                   5918:    <dt>A start tag whose tag name is one of: "caption", "col",
                   5919:    "colgroup", "tbody", "td", "tfoot", "th", "thead", "tr"</dt>
                   5920:    <dt>An end tag whose tag name is "table"</dt>
                   5921:    <dd>
                   5922: 
                   5923:     <p><a href="#parse-error">Parse error</a>. Act as if an end tag with the tag
                   5924:     name "caption" had been seen, then, if that token wasn't
                   5925:     ignored, reprocess the current token.</p>
                   5926: 
                   5927:     <p class="note">The fake end tag token here can only be
                   5928:     ignored in the <a href="#fragment-case">fragment case</a>.</p>
                   5929: 
                   5930:    </dd>
                   5931: 
                   5932:    <dt>An end tag whose tag name is one of: "body", "col",
                   5933:    "colgroup", "html", "tbody", "td", "tfoot", "th", "thead",
                   5934:    "tr"</dt>
                   5935:    <dd>
                   5936:     <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
                   5937:    </dd>
                   5938: 
                   5939:    <dt>Anything else</dt>
                   5940:    <dd>
                   5941:     <p>Process the token <a href="#using-the-rules-for">using the rules for</a> the "<a href="#parsing-main-inbody" title="insertion mode: in body">in body</a>" <a href="#insertion-mode">insertion
                   5942:     mode</a>.</p>
                   5943:    </dd>
                   5944: 
                   5945:   </dl><h5 id="parsing-main-incolgroup"><span class="secno">9.2.5.15 </span>The "<dfn title="insertion mode: in column group">in column group</dfn>" insertion mode</h5>
                   5946: 
                   5947:   <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-incolgroup" title="insertion
                   5948:   mode: in column group">in column group</a>", tokens must be handled as follows:</p>
                   5949: 
                   5950:   <dl class="switch"><dt>A character token that is one of U+0009 CHARACTER
                   5951:    TABULATION, U+000A LINE FEED (LF), U+000C FORM FEED (FF),
                   5952:    <!--U+000D CARRIAGE RETURN (CR),--> or U+0020 SPACE</dt>
                   5953:    <dd>
                   5954:     <p><a href="#insert-a-character" title="insert a character">Insert the character</a> into
                   5955:     the <a href="#current-node">current node</a>.</p>
                   5956:    </dd>
                   5957: 
                   5958:    <dt>A comment token</dt>
                   5959:    <dd>
                   5960:     <p>Append a <code>Comment</code> node to the <a href="#current-node">current
                   5961:     node</a> with the <code title="">data</code> attribute set to
                   5962:     the data given in the comment token.</p>
                   5963:    </dd>
                   5964: 
                   5965:    <dt>A DOCTYPE token</dt>
                   5966:    <dd>
                   5967:     <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
                   5968:    </dd>
                   5969: 
                   5970:    <dt>A start tag whose tag name is "html"</dt>
                   5971:    <dd>
                   5972:     <p>Process the token <a href="#using-the-rules-for">using the rules for</a> the "<a href="#parsing-main-inbody" title="insertion mode: in body">in body</a>" <a href="#insertion-mode">insertion
                   5973:     mode</a>.</p>
                   5974:    </dd>
                   5975: 
                   5976:    <dt>A start tag whose tag name is "col"</dt>
                   5977:    <dd>
                   5978: 
                   5979:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token. Immediately
                   5980:     pop the <a href="#current-node">current node</a> off the <a href="#stack-of-open-elements">stack of open
                   5981:     elements</a>.</p>
                   5982: 
                   5983:     <p><a href="#acknowledge-self-closing-flag" title="acknowledge self-closing flag">Acknowledge the
                   5984:     token's <i>self-closing flag</i></a>, if it is set.</p>
                   5985: 
                   5986:    </dd>
                   5987: 
                   5988:    <dt>An end tag whose tag name is "colgroup"</dt>
                   5989:    <dd>
                   5990: 
                   5991:     <p>If the <a href="#current-node">current node</a> is the root
                   5992:     <code><a href="semantics.html#the-html-element">html</a></code> element, then this is a <a href="#parse-error">parse
                   5993:     error</a>; ignore the token. (<a href="#fragment-case">fragment
                   5994:     case</a>)</p>
                   5995: 
                   5996:     <p>Otherwise, pop the <a href="#current-node">current node</a> (which will be
                   5997:     a <code><a href="tabular-data.html#the-colgroup-element">colgroup</a></code> element) from the <a href="#stack-of-open-elements">stack of open
                   5998:     elements</a>. Switch the <a href="#insertion-mode">insertion mode</a> to
                   5999:     "<a href="#parsing-main-intable" title="insertion mode: in table">in table</a>".</p>
                   6000: 
                   6001:    </dd>
                   6002: 
                   6003:    <dt>An end tag whose tag name is "col"</dt>
                   6004:    <dd>
                   6005:     <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
                   6006:    </dd>
                   6007: 
                   6008:    <dt>An end-of-file token</dt>
                   6009:    <dd>
                   6010: 
                   6011:     <p>If the <a href="#current-node">current node</a> is the root <code><a href="semantics.html#the-html-element">html</a></code>
                   6012:     element, then <a href="#stop-parsing">stop parsing</a>. (<a href="#fragment-case">fragment
                   6013:     case</a>)</p>
                   6014: 
                   6015:     <p>Otherwise, act as described in the "anything else" entry
                   6016:     below.</p>
                   6017: 
                   6018:    </dd>
                   6019: 
                   6020:    <dt>Anything else</dt>
                   6021:    <dd>
                   6022: 
                   6023:     <p>Act as if an end tag with the tag name "colgroup" had been
                   6024:     seen, and then, if that token wasn't ignored, reprocess the
                   6025:     current token.</p>
                   6026: 
                   6027:     <p class="note">The fake end tag token here can only be
                   6028:     ignored in the <a href="#fragment-case">fragment case</a>.</p>
                   6029: 
                   6030:    </dd>
                   6031: 
                   6032:   </dl><h5 id="parsing-main-intbody"><span class="secno">9.2.5.16 </span>The "<dfn title="insertion mode: in table body">in table body</dfn>" insertion mode</h5>
                   6033: 
                   6034:   <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-intbody" title="insertion
                   6035:   mode: in table body">in table body</a>", tokens must be handled as follows:</p>
                   6036: 
                   6037:   <dl class="switch"><dt>A start tag whose tag name is "tr"</dt>
                   6038:    <dd>
                   6039: 
                   6040:     <p><a href="#clear-the-stack-back-to-a-table-body-context">Clear the stack back to a table body
                   6041:     context</a>. (See below.)</p>
                   6042: 
                   6043:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token, then switch
                   6044:     the <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-intr" title="insertion mode:
                   6045:     in row">in row</a>".</p>
                   6046: 
                   6047:    </dd>
                   6048: 
                   6049:    <dt>A start tag whose tag name is one of: "th", "td"</dt>
                   6050:    <dd>
                   6051:     <p><a href="#parse-error">Parse error</a>. Act as if a start tag with
                   6052:     the tag name "tr" had been seen, then reprocess the current
                   6053:     token.</p>
                   6054:    </dd>
                   6055: 
                   6056:    <dt>An end tag whose tag name is one of: "tbody", "tfoot",
                   6057:    "thead"</dt>
                   6058:    <dd>
                   6059: 
                   6060:     <p>If the <a href="#stack-of-open-elements">stack of open elements</a> does not <a href="#has-an-element-in-table-scope" title="has an element in table scope">have an element in table
                   6061:     scope</a> with the same tag name as the token, this is a
                   6062:     <a href="#parse-error">parse error</a>. Ignore the token.</p>
                   6063: 
                   6064:     <p>Otherwise:</p>
                   6065: 
                   6066:     <p><a href="#clear-the-stack-back-to-a-table-body-context">Clear the stack back to a table body
                   6067:     context</a>. (See below.)</p>
                   6068: 
                   6069:     <p>Pop the <a href="#current-node">current node</a> from the <a href="#stack-of-open-elements">stack of
                   6070:     open elements</a>. Switch the <a href="#insertion-mode">insertion mode</a>
                   6071:     to "<a href="#parsing-main-intable" title="insertion mode: in table">in table</a>".</p>
                   6072: 
                   6073:    </dd>
                   6074: 
                   6075:    <dt>A start tag whose tag name is one of: "caption", "col",
                   6076:    "colgroup", "tbody", "tfoot", "thead"</dt>
                   6077:    <dt>An end tag whose tag name is "table"</dt>
                   6078:    <dd>
                   6079: 
                   6080:     <p>If the <a href="#stack-of-open-elements">stack of open elements</a> does not <a href="#has-an-element-in-table-scope" title="has an element in table scope">have a
                   6081:     <code>tbody</code>, <code>thead</code>, or <code>tfoot</code>
                   6082:     element in table scope</a>, this is a <a href="#parse-error">parse
                   6083:     error</a>. Ignore the token. (<a href="#fragment-case">fragment
                   6084:     case</a>)</p>
                   6085: 
                   6086:     <p>Otherwise:</p>
                   6087: 
                   6088:     <p><a href="#clear-the-stack-back-to-a-table-body-context">Clear the stack back to a table body
                   6089:     context</a>. (See below.)</p>
                   6090: 
                   6091:     <p>Act as if an end tag with the same tag name as the
                   6092:     <a href="#current-node">current node</a> ("tbody", "tfoot", or "thead") had
                   6093:     been seen, then reprocess the current token.</p>
                   6094: 
                   6095:    </dd>
                   6096: 
                   6097:    <dt>An end tag whose tag name is one of: "body", "caption",
                   6098:    "col", "colgroup", "html", "td", "th", "tr"</dt>
                   6099:    <dd>
                   6100:     <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
                   6101:    </dd>
                   6102: 
                   6103:    <dt>Anything else</dt>
                   6104:    <dd>
                   6105:     <p>Process the token <a href="#using-the-rules-for">using the rules for</a> the "<a href="#parsing-main-intable" title="insertion mode: in table">in table</a>" <a href="#insertion-mode">insertion
                   6106:     mode</a>.</p>
                   6107:    </dd>
                   6108: 
                   6109:   </dl><p>When the steps above require the UA to <dfn id="clear-the-stack-back-to-a-table-body-context">clear the stack
                   6110:   back to a table body context</dfn>, it means that the UA must,
                   6111:   while the <a href="#current-node">current node</a> is not a <code><a href="tabular-data.html#the-tbody-element">tbody</a></code>,
                   6112:   <code><a href="tabular-data.html#the-tfoot-element">tfoot</a></code>, <code><a href="tabular-data.html#the-thead-element">thead</a></code>, or <code><a href="semantics.html#the-html-element">html</a></code>
                   6113:   element, pop elements from the <a href="#stack-of-open-elements">stack of open
                   6114:   elements</a>.</p>
                   6115: 
                   6116:   <p class="note">The <a href="#current-node">current node</a> being an
                   6117:   <code><a href="semantics.html#the-html-element">html</a></code> element after this process is a <a href="#fragment-case">fragment
                   6118:   case</a>.</p>
                   6119: 
                   6120: 
                   6121:   <h5 id="parsing-main-intr"><span class="secno">9.2.5.17 </span>The "<dfn title="insertion mode: in row">in row</dfn>" insertion mode</h5>
                   6122: 
                   6123:   <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-intr" title="insertion
                   6124:   mode: in row">in row</a>", tokens must be handled as follows:</p>
                   6125: 
                   6126:   <dl class="switch"><dt>A start tag whose tag name is one of: "th", "td"</dt>
                   6127:    <dd>
                   6128: 
                   6129:     <p><a href="#clear-the-stack-back-to-a-table-row-context">Clear the stack back to a table row
                   6130:     context</a>. (See below.)</p>
                   6131: 
                   6132:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token, then switch
                   6133:     the <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-intd" title="insertion mode:
                   6134:     in cell">in cell</a>".</p>
                   6135: 
                   6136:     <p>Insert a marker at the end of the <a href="#list-of-active-formatting-elements">list of active
                   6137:     formatting elements</a>.</p>
                   6138: 
                   6139:    </dd>
                   6140: 
                   6141:    <dt>An end tag whose tag name is "tr"</dt>
                   6142:    <dd>
                   6143: 
                   6144:     <p>If the <a href="#stack-of-open-elements">stack of open elements</a> does not <a href="#has-an-element-in-table-scope" title="has an element in table scope">have an element in table
                   6145:     scope</a> with the same tag name as the token, this is a
                   6146:     <a href="#parse-error">parse error</a>. Ignore the token. (<a href="#fragment-case">fragment
                   6147:     case</a>)</p>
                   6148: 
                   6149:     <p>Otherwise:</p>
                   6150: 
                   6151:     <p><a href="#clear-the-stack-back-to-a-table-row-context">Clear the stack back to a table row
                   6152:     context</a>. (See below.)</p>
                   6153: 
                   6154:     <p>Pop the <a href="#current-node">current node</a> (which will be a
                   6155:     <code><a href="tabular-data.html#the-tr-element">tr</a></code> element) from the <a href="#stack-of-open-elements">stack of open
                   6156:     elements</a>. Switch the <a href="#insertion-mode">insertion mode</a> to
                   6157:     "<a href="#parsing-main-intbody" title="insertion mode: in table body">in table
                   6158:     body</a>".</p>
                   6159: 
                   6160:    </dd>
                   6161: 
                   6162:    <dt>A start tag whose tag name is one of: "caption", "col",
                   6163:    "colgroup", "tbody", "tfoot", "thead", "tr"</dt>
                   6164:    <dt>An end tag whose tag name is "table"</dt>
                   6165:    <dd>
                   6166: 
                   6167:     <p>Act as if an end tag with the tag name "tr" had been seen,
                   6168:     then, if that token wasn't ignored, reprocess the current
                   6169:     token.</p>
                   6170: 
                   6171:     <p class="note">The fake end tag token here can only be
                   6172:     ignored in the <a href="#fragment-case">fragment case</a>.</p>
                   6173: 
                   6174:    </dd>
                   6175: 
                   6176:    <dt>An end tag whose tag name is one of: "tbody", "tfoot",
                   6177:    "thead"</dt>
                   6178:    <dd>
                   6179: 
                   6180:     <p>If the <a href="#stack-of-open-elements">stack of open elements</a> does not <a href="#has-an-element-in-table-scope" title="has an element in table scope">have an element in table
                   6181:     scope</a> with the same tag name as the token, this is a
                   6182:     <a href="#parse-error">parse error</a>. Ignore the token.</p>
                   6183: 
                   6184:     <p>Otherwise, act as if an end tag with the tag name "tr" had
                   6185:     been seen, then reprocess the current token.</p>
                   6186: 
                   6187:    </dd>
                   6188: 
                   6189:    <dt>An end tag whose tag name is one of: "body", "caption",
                   6190:    "col", "colgroup", "html", "td", "th"</dt>
                   6191:    <dd>
                   6192:     <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
                   6193:    </dd>
                   6194: 
                   6195:    <dt>Anything else</dt>
                   6196:    <dd>
                   6197:     <p>Process the token <a href="#using-the-rules-for">using the rules for</a> the "<a href="#parsing-main-intable" title="insertion mode: in table">in table</a>" <a href="#insertion-mode">insertion
                   6198:     mode</a>.</p>
                   6199:    </dd>
                   6200: 
                   6201:   </dl><p>When the steps above require the UA to <dfn id="clear-the-stack-back-to-a-table-row-context">clear the stack
                   6202:   back to a table row context</dfn>, it means that the UA must,
                   6203:   while the <a href="#current-node">current node</a> is not a <code><a href="tabular-data.html#the-tr-element">tr</a></code>
                   6204:   element or an <code><a href="semantics.html#the-html-element">html</a></code> element, pop elements from the
                   6205:   <a href="#stack-of-open-elements">stack of open elements</a>.</p>
                   6206: 
                   6207:   <p class="note">The <a href="#current-node">current node</a> being an
                   6208:   <code><a href="semantics.html#the-html-element">html</a></code> element after this process is a <a href="#fragment-case">fragment
                   6209:   case</a>.</p>
                   6210: 
                   6211: 
                   6212:   <h5 id="parsing-main-intd"><span class="secno">9.2.5.18 </span>The "<dfn title="insertion mode: in cell">in cell</dfn>" insertion mode</h5>
                   6213: 
                   6214:   <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-intd" title="insertion
                   6215:   mode: in cell">in cell</a>", tokens must be handled as follows:</p>
                   6216: 
                   6217:   <dl class="switch"><dt>An end tag whose tag name is one of: "td", "th"</dt>
                   6218:    <dd>
                   6219: 
                   6220:     <p>If the <a href="#stack-of-open-elements">stack of open elements</a> does not <a href="#has-an-element-in-table-scope" title="has an element in table scope">have an element in table
                   6221:     scope</a> with the same tag name as that of the token, then
                   6222:     this is a <a href="#parse-error">parse error</a> and the token must be
                   6223:     ignored.</p>
                   6224: 
                   6225:     <p>Otherwise:</p>
                   6226: 
                   6227:     <p><a href="#generate-implied-end-tags">Generate implied end tags</a>.</p>
                   6228: 
                   6229:     <p>Now, if the <a href="#current-node">current node</a> is not an element
                   6230:     with the same tag name as the token, then this is a
                   6231:     <a href="#parse-error">parse error</a>.</p>
                   6232: 
                   6233:     <p>Pop elements from this stack until an element with the same
                   6234:     tag name as the token has been popped from the stack.</p>
                   6235: 
                   6236:     <p><a href="#clear-the-list-of-active-formatting-elements-up-to-the-last-marker">Clear the list of active formatting elements up to
                   6237:     the last marker</a>.</p>
                   6238: 
                   6239:     <p>Switch the <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-intr" title="insertion mode: in row">in row</a>". (The
                   6240:     <a href="#current-node">current node</a> will be a <code><a href="tabular-data.html#the-tr-element">tr</a></code> element at
                   6241:     this point.)</p>
                   6242: 
                   6243:    </dd>
                   6244: 
                   6245:    <dt>A start tag whose tag name is one of: "caption", "col",
                   6246:    "colgroup", "tbody", "td", "tfoot", "th", "thead", "tr"</dt>
                   6247:    <dd>
                   6248: 
                   6249:     <p>If the <a href="#stack-of-open-elements">stack of open elements</a> does
                   6250:     <em>not</em> <a href="#has-an-element-in-table-scope" title="has an element in table scope">have
                   6251:     a <code>td</code> or <code>th</code> element in table
                   6252:     scope</a>, then this is a <a href="#parse-error">parse error</a>; ignore
                   6253:     the token. (<a href="#fragment-case">fragment case</a>)</p>
                   6254: 
                   6255:     <p>Otherwise, <a href="#close-the-cell">close the cell</a> (see below) and
                   6256:     reprocess the current token.</p>
                   6257: 
                   6258:    </dd>
                   6259: 
                   6260:    <dt>An end tag whose tag name is one of: "body", "caption",
                   6261:    "col", "colgroup", "html"</dt>
                   6262:    <dd>
                   6263:     <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
                   6264:    </dd>
                   6265: 
                   6266:    <dt>An end tag whose tag name is one of: "table", "tbody",
                   6267:    "tfoot", "thead", "tr"</dt>
                   6268:    <dd>
                   6269: 
                   6270:     <p>If the <a href="#stack-of-open-elements">stack of open elements</a> does not <a href="#has-an-element-in-table-scope" title="has an element in table scope">have an element in table
                   6271:     scope</a> with the same tag name as that of the token
                   6272:     (which can only happen for "tbody", "tfoot" and "thead", or,
                   6273:     in the <a href="#fragment-case">fragment case</a>), then this is a <a href="#parse-error">parse
                   6274:     error</a> and the token must be ignored.</p>
                   6275: 
                   6276:     <p>Otherwise, <a href="#close-the-cell">close the cell</a> (see below) and
                   6277:     reprocess the current token.</p>
                   6278: 
                   6279:    </dd>
                   6280: 
                   6281:    <dt>Anything else</dt>
                   6282:    <dd>
                   6283:     <p>Process the token <a href="#using-the-rules-for">using the rules for</a> the "<a href="#parsing-main-inbody" title="insertion mode: in body">in body</a>" <a href="#insertion-mode">insertion
                   6284:     mode</a>.</p>
                   6285:    </dd>
                   6286: 
                   6287:   </dl><p>Where the steps above say to <dfn id="close-the-cell">close the cell</dfn>, they
                   6288:   mean to run the following algorithm:</p>
                   6289: 
                   6290:   <ol><li><p>If the <a href="#stack-of-open-elements">stack of open elements</a> <a href="#has-an-element-in-table-scope" title="has an element in table scope">has a <code>td</code>
                   6291:    element in table scope</a>, then act as if an end tag token
                   6292:    with the tag name "td" had been seen.</p></li>
                   6293: 
                   6294:    <li><p>Otherwise, the <a href="#stack-of-open-elements">stack of open elements</a> will
                   6295:    <a href="#has-an-element-in-table-scope" title="has an element in table scope">have a
                   6296:    <code>th</code> element in table scope</a>; act as if an end
                   6297:    tag token with the tag name "th" had been seen.</p></li>
                   6298: 
                   6299:   </ol><p class="note">The <a href="#stack-of-open-elements">stack of open elements</a> cannot
                   6300:   have both a <code><a href="tabular-data.html#the-td-element">td</a></code> and a <code><a href="tabular-data.html#the-th-element">th</a></code> element <a href="#has-an-element-in-table-scope" title="has an element in table scope">in table scope</a> at
                   6301:   the same time, nor can it have neither when the <a href="#insertion-mode">insertion
                   6302:   mode</a> is "<a href="#parsing-main-intd" title="insertion mode: in cell">in
                   6303:   cell</a>".</p>
                   6304: 
                   6305: 
                   6306:   <h5 id="parsing-main-inselect"><span class="secno">9.2.5.19 </span>The "<dfn title="insertion mode: in select">in select</dfn>" insertion mode</h5>
                   6307: 
                   6308:   <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-inselect" title="insertion
                   6309:   mode: in select">in select</a>", tokens must be handled as follows:</p>
                   6310: 
                   6311:   <dl class="switch"><dt>A character token</dt>
                   6312:    <dd>
                   6313:     <p><a href="#insert-a-character" title="insert a character">Insert the token's
                   6314:     character</a> into the <a href="#current-node">current node</a>.</p>
                   6315:    </dd>
                   6316: 
                   6317:    <dt>A comment token</dt>
                   6318:    <dd>
                   6319:     <p>Append a <code>Comment</code> node to the <a href="#current-node">current
                   6320:     node</a> with the <code title="">data</code> attribute set to
                   6321:     the data given in the comment token.</p>
                   6322:    </dd>
                   6323: 
                   6324:    <dt>A DOCTYPE token</dt>
                   6325:    <dd>
                   6326:     <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
                   6327:    </dd>
                   6328: 
                   6329:    <dt>A start tag whose tag name is "html"</dt>
                   6330:    <dd>
                   6331:     <p>Process the token <a href="#using-the-rules-for">using the rules for</a> the "<a href="#parsing-main-inbody" title="insertion mode: in body">in body</a>" <a href="#insertion-mode">insertion
                   6332:     mode</a>.</p>
                   6333:    </dd>
                   6334: 
                   6335:    <dt>A start tag whose tag name is "option"</dt>
                   6336:    <dd>
                   6337: 
                   6338:     <p>If the <a href="#current-node">current node</a> is an <code><a href="forms.html#the-option-element">option</a></code>
                   6339:     element, act as if an end tag with the tag name "option" had
                   6340:     been seen.</p>
                   6341: 
                   6342:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
                   6343: 
                   6344:    </dd>
                   6345: 
                   6346:    <dt>A start tag whose tag name is "optgroup"</dt>
                   6347:    <dd>
                   6348: 
                   6349:     <p>If the <a href="#current-node">current node</a> is an <code><a href="forms.html#the-option-element">option</a></code>
                   6350:     element, act as if an end tag with the tag name "option" had
                   6351:     been seen.</p>
                   6352: 
                   6353:     <p>If the <a href="#current-node">current node</a> is an
                   6354:     <code><a href="forms.html#the-optgroup-element">optgroup</a></code> element, act as if an end tag with the
                   6355:     tag name "optgroup" had been seen.</p>
                   6356: 
                   6357:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
                   6358: 
                   6359:    </dd>
                   6360: 
                   6361:    <dt>An end tag whose tag name is "optgroup"</dt>
                   6362:    <dd>
                   6363: 
                   6364:     <p>First, if the <a href="#current-node">current node</a> is an
                   6365:     <code><a href="forms.html#the-option-element">option</a></code> element, and the node immediately before
                   6366:     it in the <a href="#stack-of-open-elements">stack of open elements</a> is an
                   6367:     <code><a href="forms.html#the-optgroup-element">optgroup</a></code> element, then act as if an end tag with
                   6368:     the tag name "option" had been seen.</p>
                   6369: 
                   6370:     <p>If the <a href="#current-node">current node</a> is an
                   6371:     <code><a href="forms.html#the-optgroup-element">optgroup</a></code> element, then pop that node from the
                   6372:     <a href="#stack-of-open-elements">stack of open elements</a>. Otherwise, this is a
                   6373:     <a href="#parse-error">parse error</a>; ignore the token.</p>
                   6374: 
                   6375:    </dd>
                   6376: 
                   6377:    <dt>An end tag whose tag name is "option"</dt>
                   6378:    <dd>
                   6379: 
                   6380:     <p>If the <a href="#current-node">current node</a> is an <code><a href="forms.html#the-option-element">option</a></code>
                   6381:     element, then pop that node from the <a href="#stack-of-open-elements">stack of open
                   6382:     elements</a>. Otherwise, this is a <a href="#parse-error">parse
                   6383:     error</a>; ignore the token.</p>
                   6384: 
                   6385:    </dd>
                   6386: 
                   6387:    <dt>An end tag whose tag name is "select"</dt>
                   6388:    <dd>
                   6389: 
                   6390:     <p>If the <a href="#stack-of-open-elements">stack of open elements</a> does not <a href="#has-an-element-in-table-scope" title="has an element in table scope">have an element in table
                   6391:     scope</a> with the same tag name as the token, this is a
                   6392:     <a href="#parse-error">parse error</a>. Ignore the token. (<a href="#fragment-case">fragment
                   6393:     case</a>)</p>
                   6394: 
                   6395:     <p>Otherwise:</p>
                   6396: 
                   6397:     <p>Pop elements from the <a href="#stack-of-open-elements">stack of open elements</a>
                   6398:     until a <code><a href="forms.html#the-select-element">select</a></code> element has been popped from the
                   6399:     stack.</p>
                   6400: 
                   6401:     <p><a href="#reset-the-insertion-mode-appropriately">Reset the insertion mode appropriately</a>.</p>
                   6402: 
                   6403:    </dd>
                   6404: 
                   6405:    <dt>A start tag whose tag name is "select"</dt>
                   6406:    <dd>
                   6407: 
                   6408:     <p><a href="#parse-error">Parse error</a>. Act as if the token had been
                   6409:     an end tag with the tag name "select" instead.</p>
                   6410: 
                   6411:    </dd>
                   6412: 
                   6413:    <dt>A start tag whose tag name is one of: "input", "keygen", "textarea"</dt>
                   6414:    <dd>
1.73      mike     6415: 
                   6416:     <p><a href="#parse-error">Parse error</a>.</p>
                   6417: 
                   6418:     <p>If the <a href="#stack-of-open-elements">stack of open elements</a> does not <a href="#has-an-element-in-table-scope" title="has an element in table scope">have an element in table
                   6419:     scope</a> with the same tag name as the token, ignore the
                   6420:     token. (<a href="#fragment-case">fragment case</a>)</p>
                   6421: 
                   6422:     <p>Otherwise, act as if an end tag with the tag name "select" had
                   6423:     been seen, and reprocess the token.</p>
                   6424: 
1.1       mike     6425:    </dd>
                   6426: 
                   6427:    <dt>A start tag token whose tag name is "script"</dt>
                   6428:    <dd>
                   6429:     <p>Process the token <a href="#using-the-rules-for">using the rules for</a> the "<a href="#parsing-main-inhead" title="insertion mode: in head">in head</a>" <a href="#insertion-mode">insertion
                   6430:     mode</a>.</p>
                   6431:    </dd>
                   6432: 
                   6433:    <dt>An end-of-file token</dt>
                   6434:    <dd>
                   6435: 
                   6436:     <p>If the <a href="#current-node">current node</a> is not the root
                   6437:     <code><a href="semantics.html#the-html-element">html</a></code> element, then this is a <a href="#parse-error">parse
                   6438:     error</a>.</p>
                   6439: 
                   6440:     <p class="note">It can only be the <a href="#current-node">current node</a> in
                   6441:     the <a href="#fragment-case">fragment case</a>.</p>
                   6442: 
                   6443:     <p><a href="#stop-parsing">Stop parsing</a>.</p>
                   6444: 
                   6445:    </dd>
                   6446: 
                   6447:    <dt>Anything else</dt>
                   6448:    <dd>
                   6449:     <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
                   6450:    </dd>
                   6451: 
                   6452:   </dl><h5 id="parsing-main-inselectintable"><span class="secno">9.2.5.20 </span>The "<dfn title="insertion mode: in select in table">in select in table</dfn>" insertion mode</h5>
                   6453: 
                   6454:   <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-inselectintable" title="insertion
                   6455:   mode: in select in table">in select in table</a>", tokens must be handled as follows:</p>
                   6456: 
                   6457:   <dl class="switch"><dt>A start tag whose tag name is one of: "caption", "table",
                   6458:    "tbody", "tfoot", "thead", "tr", "td", "th"</dt>
                   6459:    <dd>
                   6460:     <p><a href="#parse-error">Parse error</a>. Act as if an end tag with the tag
                   6461:     name "select" had been seen, and reprocess the token.</p>
                   6462:    </dd>
                   6463: 
                   6464:    <dt>An end tag whose tag name is one of: "caption", "table",
                   6465:    "tbody", "tfoot", "thead", "tr", "td", "th"</dt>
                   6466:    <dd>
                   6467: 
                   6468:     <p><a href="#parse-error">Parse error</a>.</p>
                   6469: 
                   6470:     <p>If the <a href="#stack-of-open-elements">stack of open elements</a> <a href="#has-an-element-in-table-scope">has an
                   6471:     element in table scope</a> with the same tag name as that
                   6472:     of the token, then act as if an end tag with the tag name
                   6473:     "select" had been seen, and reprocess the token. Otherwise,
                   6474:     ignore the token.</p>
                   6475: 
                   6476:    </dd>
                   6477: 
                   6478:    <dt>Anything else</dt>
                   6479:    <dd>
                   6480:     <p>Process the token <a href="#using-the-rules-for">using the rules for</a> the "<a href="#parsing-main-inselect" title="insertion mode: in select">in select</a>" <a href="#insertion-mode">insertion
                   6481:     mode</a>.</p>
                   6482:    </dd>
                   6483: 
                   6484:   </dl><h5 id="parsing-main-inforeign"><span class="secno">9.2.5.21 </span>The "<dfn title="insertion mode: in foreign content">in foreign content</dfn>" insertion mode</h5>
                   6485: 
                   6486:   <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-inforeign" title="insertion
                   6487:   mode: in foreign content">in foreign content</a>", tokens must be
                   6488:   handled as follows:</p>
                   6489: 
                   6490:   <dl class="switch"><dt>A character token</dt>
                   6491:    <dd>
                   6492: 
                   6493:     <p><a href="#insert-a-character" title="insert a character">Insert the token's
                   6494:     character</a> into the <a href="#current-node">current node</a>.</p>
                   6495: 
                   6496:     <p>If the token is not one of U+0009 CHARACTER TABULATION, U+000A
                   6497:     LINE FEED (LF), U+000C FORM FEED (FF), <!--U+000D CARRIAGE RETURN
                   6498:     (CR),--> or U+0020 SPACE, then set the <a href="#frameset-ok-flag">frameset-ok
                   6499:     flag</a> to "not ok".</p>
                   6500: 
                   6501:    </dd>
                   6502: 
                   6503:    <dt>A comment token</dt>
                   6504:    <dd>
                   6505:     <p>Append a <code>Comment</code> node to the <a href="#current-node">current
                   6506:     node</a> with the <code title="">data</code> attribute set to
                   6507:     the data given in the comment token.</p>
                   6508:    </dd>
                   6509: 
                   6510:    <dt>A DOCTYPE token</dt>
                   6511:    <dd>
                   6512:     <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
                   6513:    </dd>
                   6514: 
                   6515:    <dt>An end tag whose tag name is "script", if the <a href="#current-node">current node</a> is a <code title="">script</code> element in the <a href="#svg-namespace">SVG namespace</a>.</dt>
                   6516:    <dd>
                   6517: 
                   6518:     <p>Pop the <a href="#current-node">current node</a> off the <a href="#stack-of-open-elements">stack of open
                   6519:     elements</a>.</p>
                   6520: 
                   6521:     <p>Let the <var title="">old insertion point</var> have the
                   6522:     same value as the current <a href="#insertion-point">insertion point</a>. Let
                   6523:     the <a href="#insertion-point">insertion point</a> be just before the <a href="#next-input-character">next
                   6524:     input character</a>.</p>
                   6525: 
                   6526:     <p>Increment the parser's <a href="#script-nesting-level">script nesting level</a> by
                   6527:     one. Set the <a href="#parser-pause-flag">parser pause flag</a> to true.</p>
                   6528: 
                   6529:     <p><a href="http://www.w3.org/TR/SVGMobile12/script.html#ScriptContentProcessing">Process
                   6530:     the <code title="">script</code> element</a> according to the SVG
1.104     mike     6531:     rules. <a href="references.html#refsSVG">[SVG]</a></p>
1.1       mike     6532: 
                   6533:     <p class="note">Even if this causes <a href="dom.html#dom-document-write" title="dom-document-write">new characters to be inserted into the
                   6534:     tokenizer</a>, the parser will not be executed reentrantly,
                   6535:     since the <a href="#parser-pause-flag">parser pause flag</a> is true.</p>
                   6536: 
                   6537:     <p>Decrement the parser's <a href="#script-nesting-level">script nesting level</a> by
                   6538:     one. If the parser's <a href="#script-nesting-level">script nesting level</a> is zero,
                   6539:     then set the <a href="#parser-pause-flag">parser pause flag</a> to false.</p>
                   6540: 
                   6541:     <p>Let the <a href="#insertion-point">insertion point</a> have the value of the <var title="">old insertion point</var>. (In other words, restore the
                   6542:     <a href="#insertion-point">insertion point</a> to its previous value. This value
                   6543:     might be the "undefined" value.)</p>
                   6544: 
                   6545:    </dd>
                   6546: 
                   6547:    <dt>A start tag whose tag name is neither "mglyph" nor "malignmark", if the <a href="#current-node">current node</a> is an <code title="">mi</code> element in the <a href="#mathml-namespace">MathML namespace</a>.</dt>
                   6548:    <dt>A start tag whose tag name is neither "mglyph" nor "malignmark", if the <a href="#current-node">current node</a> is an <code title="">mo</code> element in the <a href="#mathml-namespace">MathML namespace</a>.</dt>
                   6549:    <dt>A start tag whose tag name is neither "mglyph" nor "malignmark", if the <a href="#current-node">current node</a> is an <code title="">mn</code> element in the <a href="#mathml-namespace">MathML namespace</a>.</dt>
                   6550:    <dt>A start tag whose tag name is neither "mglyph" nor "malignmark", if the <a href="#current-node">current node</a> is an <code title="">ms</code> element in the <a href="#mathml-namespace">MathML namespace</a>.</dt>
                   6551:    <dt>A start tag whose tag name is neither "mglyph" nor "malignmark", if the <a href="#current-node">current node</a> is an <code title="">mtext</code> element in the <a href="#mathml-namespace">MathML namespace</a>.</dt>
                   6552:    <dt>A start tag whose tag name is "svg", if the <a href="#current-node">current node</a> is an <code title="">annotation-xml</code> element in the <a href="#mathml-namespace">MathML namespace</a>.</dt>
                   6553:    <dt>A start tag, if the <a href="#current-node">current node</a> is a <code title="">foreignObject</code> element in the <a href="#svg-namespace">SVG namespace</a>.</dt>
                   6554:    <dt>A start tag, if the <a href="#current-node">current node</a> is a <code title="">desc</code> element in the <a href="#svg-namespace">SVG namespace</a>.</dt>
                   6555:    <dt>A start tag, if the <a href="#current-node">current node</a> is a <code title="">title</code> element in the <a href="#svg-namespace">SVG namespace</a>.</dt>
                   6556:    <dt>A start tag, if the <a href="#current-node">current node</a> is an element in the <a href="#html-namespace-0">HTML namespace</a>.</dt>
                   6557:    <dt>An end tag</dt>
                   6558:    <dd>
                   6559: 
                   6560:     <p>Process the token <a href="#using-the-rules-for">using the rules for</a> the
                   6561:     <a href="#secondary-insertion-mode">secondary insertion mode</a>.</p>
                   6562: 
                   6563:     <p>If, after doing so, the <a href="#insertion-mode">insertion mode</a> is still
                   6564:     "<a href="#parsing-main-inforeign" title="insertion mode: in foreign content">in foreign
                   6565:     content</a>", but there is no element in scope that has a
                   6566:     namespace other than the <a href="#html-namespace-0">HTML namespace</a><!-- XXX this
                   6567:     isn't well-defined; it means check to see if the bottom-most HTML
                   6568:     element on the stack is in scope -->, switch the <a href="#insertion-mode">insertion
                   6569:     mode</a> to the <a href="#secondary-insertion-mode">secondary insertion mode</a>.</p>
                   6570: 
                   6571:    </dd>
                   6572: 
                   6573:    <dt>A start tag whose tag name is one of: <!--"a",--> "b", "big",
                   6574:    "blockquote", "body"<!--by inspection-->, "br", "center", "code",
                   6575:    "dd", "div", "dl", "dt"<!-- so that dd and dt can be handled
                   6576:    uniformly throughout the parser -->, "em", "embed", "h1", "h2",
                   6577:    "h3", "h4"<!--for completeness-->, "h5", "h6"<!--for
                   6578:    completeness-->, "head"<!--by inspection-->, "hr", "i", "img",
                   6579:    "li", "listing"<!-- so that pre and listing can be handled
                   6580:    uniformly throughout the parser -->, "menu", "meta", "nobr",
                   6581:    "ol"<!-- so that dl, ul, and ol can be handled uniformly throughout
                   6582:    the parser -->, "p", "pre", "ruby", "s", <!--"script",--> "small",
                   6583:    "span", "strong", "strike"<!-- so that s and strike can be handled
                   6584:    uniformly throughout the parser -->, <!--"style",--> "sub", "sup",
                   6585:    "table"<!--by inspection-->, "tt", "u", "ul", "var"</dt>
                   6586:    <!-- this list was determined empirically by studying over
                   6587:    6,000,000,000 pages that were specifically not XML pages -->
                   6588:    <dt>A start tag whose tag name is "font", if the token has
                   6589:    any attributes named "color", "face", or "size"</dt>
                   6590:    <!-- the attributes here are required so that SVG <font> will go
                   6591:    through as SVG but legacy <font>s won't -->
                   6592:    <dt>An end-of-file token</dt>
                   6593:    <dd>
                   6594: 
                   6595:     <p><a href="#parse-error">Parse error</a>.</p>
                   6596: 
                   6597:     <p>Pop elements from the <a href="#stack-of-open-elements">stack of open elements</a> until
                   6598:     the <a href="#current-node">current node</a> is in the <a href="#html-namespace-0">HTML
                   6599:     namespace</a>.</p>
                   6600: 
                   6601:     <p>Switch the <a href="#insertion-mode">insertion mode</a> to the <a href="#secondary-insertion-mode">secondary
                   6602:     insertion mode</a>, and reprocess the token.</p>
                   6603: 
                   6604:    </dd>
                   6605: 
                   6606:    <dt>Any other start tag</dt>
                   6607:    <dd>
                   6608: 
                   6609:     <p>If the <a href="#current-node">current node</a> is an element in the
                   6610:     <a href="#mathml-namespace">MathML namespace</a>, <a href="#adjust-mathml-attributes">adjust MathML
                   6611:     attributes</a> for the token. (This fixes the case of MathML
                   6612:     attributes that are not all lowercase.)</p>
                   6613: 
                   6614:     <p>If the <a href="#current-node">current node</a> is an element in the <a href="#svg-namespace">SVG
                   6615:     namespace</a>, and the token's tag name is one of the ones in
                   6616:     the first column of the following table, change the tag name to
                   6617:     the name given in the corresponding cell in the second
                   6618:     column. (This fixes the case of SVG elements that are not all
                   6619:     lowercase.)</p>
                   6620: 
                   6621:     <table><thead><tr><th> Tag name </th><th> Element name
                   6622:      </th></tr></thead><tbody><tr><td> <code title="">altglyph</code> </td><td> <code title="">altGlyph</code>
                   6623:       </td></tr><tr><td> <code title="">altglyphdef</code> </td><td> <code title="">altGlyphDef</code>
                   6624:       </td></tr><tr><td> <code title="">altglyphitem</code> </td><td> <code title="">altGlyphItem</code>
                   6625:       </td></tr><tr><td> <code title="">animatecolor</code> </td><td> <code title="">animateColor</code>
                   6626:       </td></tr><tr><td> <code title="">animatemotion</code> </td><td> <code title="">animateMotion</code>
                   6627:       </td></tr><tr><td> <code title="">animatetransform</code> </td><td> <code title="">animateTransform</code>
                   6628:       </td></tr><tr><td> <code title="">clippath</code> </td><td> <code title="">clipPath</code>
                   6629:       </td></tr><tr><td> <code title="">feblend</code> </td><td> <code title="">feBlend</code>
                   6630:       </td></tr><tr><td> <code title="">fecolormatrix</code> </td><td> <code title="">feColorMatrix</code>
                   6631:       </td></tr><tr><td> <code title="">fecomponenttransfer</code> </td><td> <code title="">feComponentTransfer</code>
                   6632:       </td></tr><tr><td> <code title="">fecomposite</code> </td><td> <code title="">feComposite</code>
                   6633:       </td></tr><tr><td> <code title="">feconvolvematrix</code> </td><td> <code title="">feConvolveMatrix</code>
                   6634:       </td></tr><tr><td> <code title="">fediffuselighting</code> </td><td> <code title="">feDiffuseLighting</code>
                   6635:       </td></tr><tr><td> <code title="">fedisplacementmap</code> </td><td> <code title="">feDisplacementMap</code>
                   6636:       </td></tr><tr><td> <code title="">fedistantlight</code> </td><td> <code title="">feDistantLight</code>
                   6637:       </td></tr><tr><td> <code title="">feflood</code> </td><td> <code title="">feFlood</code>
                   6638:       </td></tr><tr><td> <code title="">fefunca</code> </td><td> <code title="">feFuncA</code>
                   6639:       </td></tr><tr><td> <code title="">fefuncb</code> </td><td> <code title="">feFuncB</code>
                   6640:       </td></tr><tr><td> <code title="">fefuncg</code> </td><td> <code title="">feFuncG</code>
                   6641:       </td></tr><tr><td> <code title="">fefuncr</code> </td><td> <code title="">feFuncR</code>
                   6642:       </td></tr><tr><td> <code title="">fegaussianblur</code> </td><td> <code title="">feGaussianBlur</code>
                   6643:       </td></tr><tr><td> <code title="">feimage</code> </td><td> <code title="">feImage</code>
                   6644:       </td></tr><tr><td> <code title="">femerge</code> </td><td> <code title="">feMerge</code>
                   6645:       </td></tr><tr><td> <code title="">femergenode</code> </td><td> <code title="">feMergeNode</code>
                   6646:       </td></tr><tr><td> <code title="">femorphology</code> </td><td> <code title="">feMorphology</code>
                   6647:       </td></tr><tr><td> <code title="">feoffset</code> </td><td> <code title="">feOffset</code>
                   6648:       </td></tr><tr><td> <code title="">fepointlight</code> </td><td> <code title="">fePointLight</code>
                   6649:       </td></tr><tr><td> <code title="">fespecularlighting</code> </td><td> <code title="">feSpecularLighting</code>
                   6650:       </td></tr><tr><td> <code title="">fespotlight</code> </td><td> <code title="">feSpotLight</code>
                   6651:       </td></tr><tr><td> <code title="">fetile</code> </td><td> <code title="">feTile</code>
                   6652:       </td></tr><tr><td> <code title="">feturbulence</code> </td><td> <code title="">feTurbulence</code>
                   6653:       </td></tr><tr><td> <code title="">foreignobject</code> </td><td> <code title="">foreignObject</code>
                   6654:       </td></tr><tr><td> <code title="">glyphref</code> </td><td> <code title="">glyphRef</code>
                   6655:       </td></tr><tr><td> <code title="">lineargradient</code> </td><td> <code title="">linearGradient</code>
                   6656:       </td></tr><tr><td> <code title="">radialgradient</code> </td><td> <code title="">radialGradient</code>
                   6657:       <!--<tr> <td> <code title="">solidcolor</code> <td> <code title="">solidColor</code> (SVG 1.2)-->
                   6658:       </td></tr><tr><td> <code title="">textpath</code> </td><td> <code title="">textPath</code>
                   6659:     </td></tr></tbody></table><p>If the <a href="#current-node">current node</a> is an element in the <a href="#svg-namespace">SVG
                   6660:     namespace</a>, <a href="#adjust-svg-attributes">adjust SVG attributes</a> for the
                   6661:     token. (This fixes the case of SVG attributes that are not all
                   6662:     lowercase.)</p>
                   6663: 
                   6664:     <p><a href="#adjust-foreign-attributes">Adjust foreign attributes</a> for the token. (This
                   6665:     fixes the use of namespaced attributes, in particular XLink in
                   6666:     SVG.)</p>
                   6667: 
                   6668:     <p><a href="#insert-a-foreign-element">Insert a foreign element</a> for the token, in the
                   6669:     same namespace as the <a href="#current-node">current node</a>.</p>
                   6670: 
                   6671:     <p>If the token has its <i>self-closing flag</i> set, pop the
                   6672:     <a href="#current-node">current node</a> off the <a href="#stack-of-open-elements">stack of open
                   6673:     elements</a> and <a href="#acknowledge-self-closing-flag" title="acknowledge self-closing
                   6674:     flag">acknowledge the token's <i>self-closing flag</i></a>.</p>
                   6675: 
                   6676:    </dd>
                   6677: 
                   6678:   </dl><h5 id="parsing-main-afterbody"><span class="secno">9.2.5.22 </span>The "<dfn title="insertion mode: after body">after body</dfn>" insertion mode</h5>
                   6679: 
                   6680:   <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-afterbody" title="insertion
                   6681:   mode: after body">after body</a>", tokens must be handled as follows:</p>
                   6682: 
                   6683:   <dl class="switch"><dt>A character token that is one of U+0009 CHARACTER
                   6684:    TABULATION, U+000A LINE FEED (LF), U+000C FORM FEED (FF),
                   6685:    <!--U+000D CARRIAGE RETURN (CR),--> or U+0020 SPACE</dt>
                   6686:    <dd>
                   6687:     <p>Process the token <a href="#using-the-rules-for">using the rules for</a> the "<a href="#parsing-main-inbody" title="insertion mode: in body">in body</a>" <a href="#insertion-mode">insertion
                   6688:     mode</a>.</p>
                   6689:    </dd>
                   6690: 
                   6691:    <dt>A comment token</dt>
                   6692:    <dd>
                   6693:     <p>Append a <code>Comment</code> node to the first element in
                   6694:     the <a href="#stack-of-open-elements">stack of open elements</a> (the <code><a href="semantics.html#the-html-element">html</a></code>
                   6695:     element), with the <code title="">data</code> attribute set to
                   6696:     the data given in the comment token.</p>
                   6697:    </dd>
                   6698: 
                   6699:    <dt>A DOCTYPE token</dt>
                   6700:    <dd>
                   6701:     <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
                   6702:    </dd>
                   6703: 
                   6704:    <dt>A start tag whose tag name is "html"</dt>
                   6705:    <dd>
                   6706:     <p>Process the token <a href="#using-the-rules-for">using the rules for</a> the "<a href="#parsing-main-inbody" title="insertion mode: in body">in body</a>" <a href="#insertion-mode">insertion
                   6707:     mode</a>.</p>
                   6708:    </dd>
                   6709: 
                   6710:    <dt>An end tag whose tag name is "html"</dt>
                   6711:    <dd>
                   6712: 
                   6713:     <p>If the parser was originally created as part of the <a href="#html-fragment-parsing-algorithm">HTML
                   6714:     fragment parsing algorithm</a>, this is a <a href="#parse-error">parse
                   6715:     error</a>; ignore the token. (<a href="#fragment-case">fragment case</a>)</p>
                   6716: 
                   6717:     <p>Otherwise, switch the <a href="#insertion-mode">insertion mode</a> to "<a href="#the-after-after-body-insertion-mode" title="insertion mode: after after body">after after
                   6718:     body</a>".</p>
                   6719: 
                   6720:    </dd>
                   6721: 
                   6722:    <dt>An end-of-file token</dt>
                   6723:    <dd>
                   6724:     <p><a href="#stop-parsing">Stop parsing</a>.</p>
                   6725:    </dd>
                   6726: 
                   6727:    <dt>Anything else</dt>
                   6728:    <dd>
                   6729: 
                   6730:     <p><a href="#parse-error">Parse error</a>. Switch the <a href="#insertion-mode">insertion
                   6731:     mode</a> to "<a href="#parsing-main-inbody" title="insertion mode: in body">in
                   6732:     body</a>" and reprocess the token.</p>
                   6733: 
                   6734:    </dd>
                   6735: 
                   6736:   </dl><h5 id="parsing-main-inframeset"><span class="secno">9.2.5.23 </span>The "<dfn title="insertion mode: in frameset">in frameset</dfn>" insertion mode</h5>
                   6737: 
                   6738:   <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-inframeset" title="insertion
                   6739:   mode: in frameset">in frameset</a>", tokens must be handled as follows:</p>
                   6740: 
                   6741:   <dl class="switch"><dt>A character token that is one of U+0009 CHARACTER
                   6742:    TABULATION, U+000A LINE FEED (LF), U+000C FORM FEED (FF),
                   6743:    <!--U+000D CARRIAGE RETURN (CR),--> or U+0020 SPACE</dt>
                   6744:    <dd>
                   6745:     <p><a href="#insert-a-character" title="insert a character">Insert the character</a> into
                   6746:     the <a href="#current-node">current node</a>.</p>
                   6747:    </dd>
                   6748: 
                   6749:    <dt>A comment token</dt>
                   6750:    <dd>
                   6751:     <p>Append a <code>Comment</code> node to the <a href="#current-node">current
                   6752:     node</a> with the <code title="">data</code> attribute set to
                   6753:     the data given in the comment token.</p>
                   6754:    </dd>
                   6755: 
                   6756:    <dt>A DOCTYPE token</dt>
                   6757:    <dd>
                   6758:     <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
                   6759:    </dd>
                   6760: 
                   6761:    <dt>A start tag whose tag name is "html"</dt>
                   6762:    <dd>
                   6763:     <p>Process the token <a href="#using-the-rules-for">using the rules for</a> the "<a href="#parsing-main-inbody" title="insertion mode: in body">in body</a>" <a href="#insertion-mode">insertion
                   6764:     mode</a>.</p>
                   6765:    </dd>
                   6766: 
                   6767:    <dt>A start tag whose tag name is "frameset"</dt>
                   6768:    <dd>
                   6769:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.</p>
                   6770:    </dd>
                   6771: 
                   6772:    <dt>An end tag whose tag name is "frameset"</dt>
                   6773:    <dd>
                   6774: 
                   6775:     <p>If the <a href="#current-node">current node</a> is the root
                   6776:     <code><a href="semantics.html#the-html-element">html</a></code> element, then this is a <a href="#parse-error">parse
                   6777:     error</a>; ignore the token. (<a href="#fragment-case">fragment
                   6778:     case</a>)</p>
                   6779: 
                   6780:     <p>Otherwise, pop the <a href="#current-node">current node</a> from the
                   6781:     <a href="#stack-of-open-elements">stack of open elements</a>.</p>
                   6782: 
                   6783:     <p>If the parser was <em>not</em> originally created as part
                   6784:     of the <a href="#html-fragment-parsing-algorithm">HTML fragment parsing algorithm</a>
                   6785:     (<a href="#fragment-case">fragment case</a>), and the <a href="#current-node">current
1.5       mike     6786:     node</a> is no longer a <code><a href="obsolete.html#frameset">frameset</a></code> element, then
1.1       mike     6787:     switch the <a href="#insertion-mode">insertion mode</a> to "<a href="#parsing-main-afterframeset" title="insertion mode: after frameset">after
                   6788:     frameset</a>".</p>
                   6789: 
                   6790:    </dd>
                   6791: 
                   6792:    <dt>A start tag whose tag name is "frame"</dt>
                   6793:    <dd>
                   6794: 
                   6795:     <p><a href="#insert-an-html-element">Insert an HTML element</a> for the token.
                   6796:     Immediately pop the <a href="#current-node">current node</a> off the
                   6797:     <a href="#stack-of-open-elements">stack of open elements</a>.</p>
                   6798: 
                   6799:     <p><a href="#acknowledge-self-closing-flag" title="acknowledge self-closing flag">Acknowledge the
                   6800:     token's <i>self-closing flag</i></a>, if it is set.</p>
                   6801: 
                   6802:    </dd>
                   6803: 
                   6804:    <dt>A start tag whose tag name is "noframes"</dt>
                   6805:    <dd>
                   6806:     <p>Process the token <a href="#using-the-rules-for">using the rules for</a> the "<a href="#parsing-main-inhead" title="insertion mode: in head">in head</a>" <a href="#insertion-mode">insertion
                   6807:     mode</a>.</p>
                   6808:    </dd>
                   6809: 
                   6810:    <dt>An end-of-file token</dt>
                   6811:    <dd>
                   6812: 
                   6813:     <p>If the <a href="#current-node">current node</a> is not the root
                   6814:     <code><a href="semantics.html#the-html-element">html</a></code> element, then this is a <a href="#parse-error">parse
                   6815:     error</a>.</p>
                   6816: 
                   6817:     <p class="note">It can only be the <a href="#current-node">current node</a> in
                   6818:     the <a href="#fragment-case">fragment case</a>.</p>
                   6819: 
                   6820:     <p><a href="#stop-parsing">Stop parsing</a>.</p>
                   6821: 
                   6822:    </dd>
                   6823: 
                   6824:    <dt>Anything else</dt>
                   6825:    <dd>
                   6826:     <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
                   6827:    </dd>
                   6828: 
                   6829:   </dl><h5 id="parsing-main-afterframeset"><span class="secno">9.2.5.24 </span>The "<dfn title="insertion mode: after frameset">after frameset</dfn>" insertion mode</h5>
                   6830: 
                   6831:   <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-afterframeset" title="insertion
                   6832:   mode: after frameset">after frameset</a>", tokens must be handled as follows:</p>
                   6833: 
                   6834:   <!-- due to rules in the "in frameset" mode, this can't be entered in the fragment case -->
                   6835:   <dl class="switch"><dt>A character token that is one of U+0009 CHARACTER
                   6836:    TABULATION, U+000A LINE FEED (LF), U+000C FORM FEED (FF),
                   6837:    <!--U+000D CARRIAGE RETURN (CR),--> or U+0020 SPACE</dt>
                   6838:    <dd>
                   6839:     <p><a href="#insert-a-character" title="insert a character">Insert the character</a> into
                   6840:     the <a href="#current-node">current node</a>.</p>
                   6841:    </dd>
                   6842: 
                   6843:    <dt>A comment token</dt>
                   6844:    <dd>
                   6845:     <p>Append a <code>Comment</code> node to the <a href="#current-node">current
                   6846:     node</a> with the <code title="">data</code> attribute set to
                   6847:     the data given in the comment token.</p>
                   6848:    </dd>
                   6849: 
                   6850:    <dt>A DOCTYPE token</dt>
                   6851:    <dd>
                   6852:     <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
                   6853:    </dd>
                   6854: 
                   6855:    <dt>A start tag whose tag name is "html"</dt>
                   6856:    <dd>
                   6857:     <p>Process the token <a href="#using-the-rules-for">using the rules for</a> the "<a href="#parsing-main-inbody" title="insertion mode: in body">in body</a>" <a href="#insertion-mode">insertion
                   6858:     mode</a>.</p>
                   6859:    </dd>
                   6860: 
                   6861:    <dt>An end tag whose tag name is "html"</dt>
                   6862:    <dd>
                   6863:     <p>Switch the <a href="#insertion-mode">insertion mode</a> to "<a href="#the-after-after-frameset-insertion-mode" title="insertion mode: after after frameset">after after
                   6864:     frameset</a>".</p>
                   6865:    </dd>
                   6866: 
                   6867:    <dt>A start tag whose tag name is "noframes"</dt>
                   6868:    <dd>
                   6869:     <p>Process the token <a href="#using-the-rules-for">using the rules for</a> the "<a href="#parsing-main-inhead" title="insertion mode: in head">in head</a>" <a href="#insertion-mode">insertion
                   6870:     mode</a>.</p>
                   6871:    </dd>
                   6872: 
                   6873:    <dt>An end-of-file token</dt>
                   6874:    <dd>
                   6875:     <p><a href="#stop-parsing">Stop parsing</a>.</p>
                   6876:    </dd>
                   6877: 
                   6878:    <dt>Anything else</dt>
                   6879:    <dd>
                   6880:     <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
                   6881:    </dd>
                   6882: 
                   6883:   </dl><p class="XXX">This doesn't handle UAs that don't support
                   6884:   frames, or that do support frames but want to show the NOFRAMES
                   6885:   content. Supporting the former is easy; supporting the latter is
                   6886:   harder.</p>
                   6887: 
                   6888: 
                   6889:   <h5 id="the-after-after-body-insertion-mode"><span class="secno">9.2.5.25 </span>The "<dfn title="insertion mode: after after body">after after body</dfn>" insertion mode</h5>
                   6890: 
                   6891:   <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#the-after-after-body-insertion-mode" title="insertion
                   6892:   mode: after after body">after after body</a>", tokens must be handled as follows:</p>
                   6893: 
                   6894:   <dl class="switch"><dt>A comment token</dt>
                   6895:    <dd>
                   6896:     <p>Append a <code>Comment</code> node to the <code>Document</code>
                   6897:     object with the <code title="">data</code> attribute set to the
                   6898:     data given in the comment token.</p>
                   6899:    </dd>
                   6900: 
                   6901:    <dt>A DOCTYPE token</dt>
                   6902:    <dt>A character token that is one of U+0009 CHARACTER
                   6903:    TABULATION, U+000A LINE FEED (LF), U+000C FORM FEED (FF),
                   6904:    <!--U+000D CARRIAGE RETURN (CR),--> or U+0020 SPACE</dt>
                   6905:    <dt>A start tag whose tag name is "html"</dt>
                   6906:    <dd>
                   6907:     <p>Process the token <a href="#using-the-rules-for">using the rules for</a> the "<a href="#parsing-main-inbody" title="insertion mode: in body">in body</a>" <a href="#insertion-mode">insertion
                   6908:     mode</a>.</p>
                   6909:    </dd>
                   6910: 
                   6911:    <dt>An end-of-file token</dt>
                   6912:    <dd>
                   6913:     <p><a href="#stop-parsing">Stop parsing</a>.</p>
                   6914:    </dd>
                   6915: 
                   6916:    <dt>Anything else</dt>
                   6917:    <dd>
                   6918:     <p><a href="#parse-error">Parse error</a>. Switch the <a href="#insertion-mode">insertion mode</a>
                   6919:     to "<a href="#parsing-main-inbody" title="insertion mode: in body">in body</a>" and
                   6920:     reprocess the token.</p>
                   6921:    </dd>
                   6922: 
                   6923:   </dl><h5 id="the-after-after-frameset-insertion-mode"><span class="secno">9.2.5.26 </span>The "<dfn title="insertion mode: after after frameset">after after frameset</dfn>" insertion mode</h5>
                   6924: 
                   6925:   <p>When the <a href="#insertion-mode">insertion mode</a> is "<a href="#the-after-after-frameset-insertion-mode" title="insertion
                   6926:   mode: after after frameset">after after frameset</a>", tokens must be handled as follows:</p>
                   6927: 
                   6928:   <dl class="switch"><dt>A comment token</dt>
                   6929:    <dd>
                   6930:     <p>Append a <code>Comment</code> node to the <code>Document</code>
                   6931:     object with the <code title="">data</code> attribute set to the
                   6932:     data given in the comment token.</p>
                   6933:    </dd>
                   6934: 
                   6935:    <dt>A DOCTYPE token</dt>
                   6936:    <dt>A character token that is one of U+0009 CHARACTER
                   6937:    TABULATION, U+000A LINE FEED (LF), U+000C FORM FEED (FF),
                   6938:    <!--U+000D CARRIAGE RETURN (CR),--> or U+0020 SPACE</dt>
                   6939:    <dt>A start tag whose tag name is "html"</dt>
                   6940:    <dd>
                   6941:     <p>Process the token <a href="#using-the-rules-for">using the rules for</a> the "<a href="#parsing-main-inbody" title="insertion mode: in body">in body</a>" <a href="#insertion-mode">insertion
                   6942:     mode</a>.</p>
                   6943:    </dd>
                   6944: 
                   6945:    <dt>An end-of-file token</dt>
                   6946:    <dd>
                   6947:     <p><a href="#stop-parsing">Stop parsing</a>.</p>
                   6948:    </dd>
                   6949: 
                   6950:    <dt>A start tag whose tag name is "noframes"</dt>
                   6951:    <dd>
                   6952:     <p>Process the token <a href="#using-the-rules-for">using the rules for</a> the "<a href="#parsing-main-inhead" title="insertion mode: in head">in head</a>" <a href="#insertion-mode">insertion
                   6953:     mode</a>.</p>
                   6954:    </dd>
                   6955: 
                   6956:    <dt>Anything else</dt>
                   6957:    <dd>
                   6958:     <p><a href="#parse-error">Parse error</a>. Ignore the token.</p>
                   6959:    </dd>
                   6960: 
                   6961:   </dl><h4 id="the-end"><span class="secno">9.2.6 </span>The end</h4>
                   6962: 
                   6963:   <p>Once the user agent <dfn id="stop-parsing" title="stop parsing">stops parsing</dfn>
                   6964:   the document, the user agent must follow the steps in this
                   6965:   section.</p>
                   6966: 
1.10      mike     6967:   <!-- this happens as part of one of the tasks that runs the parser -->
1.1       mike     6968: 
1.10      mike     6969:   <p>First, the user agent must set the <a href="dom.html#current-document-readiness">current document
                   6970:   readiness</a> to "interactive" and the <a href="#insertion-point">insertion
                   6971:   point</a> to undefined.</p>
                   6972: 
                   6973:   <p>Then, the user agent must then make a list of all the scripts
                   6974:   that are in the <a href="semantics.html#list-of-scripts-that-will-execute-when-the-document-has-finished-parsing">list of scripts that will execute when the
                   6975:   document has finished parsing</a>, the <a href="semantics.html#list-of-scripts-that-will-execute-asynchronously">list of scripts that
                   6976:   will execute asynchronously</a>, and the <a href="semantics.html#list-of-scripts-that-will-execute-as-soon-as-possible">list of scripts
                   6977:   that will execute as soon as possible</a>. This is the <dfn id="list-of-scripts-pending-after-the-parser-stopped">list
                   6978:   of scripts pending after the parser stopped</dfn>.</p>
                   6979: 
                   6980:   <p>The rules for <a href="semantics.html#when-a-script-completes-loading">when a script completes loading</a> start
                   6981:   applying (script execution is no longer managed by the parser).</p>
1.1       mike     6982: 
                   6983:   <p>If any of the scripts in the <a href="semantics.html#list-of-scripts-that-will-execute-as-soon-as-possible">list of scripts that will
                   6984:   execute as soon as possible</a> have <a href="semantics.html#completed-loading">completed
                   6985:   loading</a>, or if the <a href="semantics.html#list-of-scripts-that-will-execute-asynchronously">list of scripts that will execute
                   6986:   asynchronously</a> is not empty and the first script in that list
                   6987:   has <a href="semantics.html#completed-loading">completed loading</a>, then the user agent must act as
                   6988:   if those scripts just completed loading, following the rules given
                   6989:   for that in the <code><a href="semantics.html#script">script</a></code> element definition.</p>
                   6990: 
1.10      mike     6991:   <p>If the <a href="semantics.html#list-of-scripts-that-will-execute-when-the-document-has-finished-parsing">list of scripts that will execute when the document
                   6992:   has finished parsing</a> is not empty, and the first item in this
                   6993:   list has already <a href="semantics.html#completed-loading">completed loading</a>, then the user agent
                   6994:   must act as if that script just finished loading.</p>
                   6995: 
                   6996:   <p class="note">By this point, there will be no scripts that have
                   6997:   loaded but have not yet been executed.</p>
                   6998: 
                   6999:   <hr><!-- async --><p>Once all the scripts on the <a href="#list-of-scripts-pending-after-the-parser-stopped">list of scripts pending after
                   7000:   the parser stopped</a> have <a href="semantics.html#completed-loading">completed loading</a> and
                   7001:   been <a href="semantics.html#executing-a-script-block" title="executing a script block">executed</a>, the
                   7002:   user agent must <a href="browsers.html#queue-a-task">queue a task</a> to <a href="browsers.html#fire-a-simple-event">fire a simple
                   7003:   event</a> called <code title="event-DOMContentLoaded">DOMContentLoaded</code> at the
                   7004:   <code>Document</code>. (If the list is empty, this happens
                   7005:   immediately.)</p>
1.1       mike     7006: 
1.10      mike     7007:   <hr><!-- async --><p>Once everything that <dfn id="delay-the-load-event" title="delay the load event">delays the
1.1       mike     7008:   load event</dfn> of the document has completed, the user agent must
                   7009:   run the following steps:</p>
                   7010: 
                   7011:   <ol><li><a href="browsers.html#queue-a-task">Queue a task</a> to set the <a href="dom.html#current-document-readiness">current document
                   7012:    readiness</a> to "complete".</li>
                   7013: 
                   7014:    <li>If the <code>Document</code> is in a <a href="browsers.html#browsing-context">browsing
                   7015:    context</a>, then <a href="browsers.html#queue-a-task">queue a task</a> to <a href="browsers.html#fire-a-simple-event">fire a
                   7016:    simple event</a> called <code title="event-load"><a href="video.html#event-load">load</a></code> at
                   7017:    the <code>Document</code>'s <code><a href="browsers.html#window">Window</a></code> object, but with
                   7018:    its <code title="dom-event-target">target</code> set to the
                   7019:    <code>Document</code> object (and the <code title="dom-event-currentTarget">currentTarget</code> set to the
                   7020:    <code><a href="browsers.html#window">Window</a></code> object).</li>
                   7021: 
                   7022:    <li>If the <code>Document</code> has a <a href="history.html#pending-state-object">pending state
                   7023:    object</a>, then <a href="browsers.html#queue-a-task">queue a task</a> to fire a <code title="event-popstate"><a href="history.html#event-popstate">popstate</a></code> event in no namespace on the
                   7024:    <code>Document</code>'s <code><a href="browsers.html#window">Window</a></code> object using the
                   7025:    <code><a href="history.html#popstateevent">PopStateEvent</a></code> interface, with the <code title="dom-PopStateEvent-state"><a href="history.html#dom-popstateevent-state">state</a></code> attribute set to the
                   7026:    current value of the <a href="history.html#pending-state-object">pending state object</a>. This event
                   7027:    must bubble but not be cancelable and has no default action.</li>
                   7028: 
                   7029:   </ol><p>The <a href="browsers.html#task-source">task source</a> for these tasks is the <a href="browsers.html#dom-manipulation-task-source">DOM
                   7030:   manipulation task source</a>.</p>
                   7031: 
                   7032:   <!-- XXX make sure things "delay the load event", e.g. applet and
                   7033:   object element's frame contents -->
                   7034: 
                   7035:   <p class="XXX">delaying the load event for things like image
                   7036:   loads allows for intranet port scans (even without
                   7037:   javascript!). Should we really encode that into the spec?</p>
                   7038: 
                   7039: 
                   7040: <!--XXX need to handle
                   7041: http://lxr.mozilla.org/mozilla/source/parser/htmlparser/src/CNavDTD.cpp#2354
                   7042: 2354           // Don't open transient styles if it makes the stack deep, bug 58917.
                   7043: -->
                   7044: 
                   7045: <!--XXX
                   7046: http://lxr.mozilla.org/mozilla/source/parser/htmlparser/src/nsHTMLTokenizer.cpp#749
                   7047: -->
                   7048: 
                   7049: <!--
                   7050: see also  CTextToken::ConsumeCharacterData()  for CDATA parsing?
                   7051: 
                   7052: 1212                      1  Here's a tricky case from bug 22596:  <h5><li><h5>
                   7053: 1213                         How do we know that the 2nd <h5> should close the <LI> rather than nest inside the <LI>?
                   7054: 1214                         (Afterall, the <h5> is a legal child of the <LI>).
                   7055: 1215
                   7056: 1216                         The way you know is that there is no root between the two, so the <h5> binds more
                   7057: 1217                         tightly to the 1st <h5> than to the <LI>.
                   7058: 1218                      2. Also, bug 6148 shows this case: <SPAN><DIV><SPAN>
                   7059: 1219                         From this case we learned not to execute this logic if the parent is a block.
                   7060: 1220
                   7061: 1221                      3. Fix for 26583
                   7062: 1222                         Ex. <A href=foo.html><B>foo<A href-bar.html>bar</A></B></A>  <- A legal HTML
                   7063: 1223                         In the above example clicking on "foo" or "bar" should link to
                   7064: 1224                         foo.html or bar.html respectively. That is, the inner <A> should be informed
                   7065: 1225                         about the presence of an open <A> above <B>..so that the inner <A> can close out
                   7066: 1226                         the outer <A>. The following code does it for us.
                   7067: 1227
                   7068: 1228                      4. Fix for 27865 [ similer to 22596 ]. Ex: <DL><DD><LI>one<DD><LI>two
                   7069:  - http://lxr.mozilla.org/mozilla/source/parser/htmlparser/src/CNavDTD.cpp#1211
                   7070: 
                   7071: 815             // Here's a problem.  If theTag is legal in here, we don't move it
                   7072: 816             // out.  So if we're moving stuff out of here, the parent of theTag
                   7073: 817             // gets closed at this point.  But some things are legal
                   7074: 818             // _everywhere_ and hence would effectively close out misplaced
                   7075: 819             // content in tables.  This is undesirable, so treat them as
                   7076: 820             // illegal here so they'll be shipped out with their parents and
                   7077: 821             // siblings.  See bug 40855 for an explanation (that bug was for
                   7078: 822             // comments, but the same issues arise with whitespace, newlines,
                   7079: 823             // noscript, etc).  Script is special, though.  Shipping it out
                   7080: 824             // breaks document.write stuff.  See bug 243064.
                   7081:  - http://lxr.mozilla.org/mozilla/source/parser/htmlparser/src/CNavDTD.cpp#825
                   7082: 
                   7083: 
                   7084: 1326     /**************************************************************************************
                   7085: 1327      *
                   7086: 1328      * Now a little code to deal with bug #49687 (crash when layout stack gets too deep)
                   7087: 1329      * I've also opened this up to any container (not just inlines): re bug 55095
                   7088: 1330      * Improved to handle bug 55980 (infinite loop caused when DEPTH is exceeded and
                   7089: 1331      * </P> is encountered by itself (<P>) is continuously produced.
                   7090: 1332      *
                   7091: 1333      **************************************************************************************/
                   7092: 
                   7093: 1912               // Oh boy!! we found a "stray" tag. Nav4.x and IE introduce line break in
                   7094: 1913               // such cases. So, let's simulate that effect for compatibility.
                   7095: 1914               // Ex. <html><body>Hello</P>There</body></html>
                   7096: http://lxr.mozilla.org/mozilla/source/parser/htmlparser/src/CNavDTD.cpp#1912
                   7097: 
                   7098: http://lxr.mozilla.org/seamonkey/search?string=nested
                   7099: /parser/htmlparser/src/CNavDTD.cpp, line 791 - * 2. <CENTER><DL><DT><A><CENTER> allow nested <CENTER>
                   7100: /parser/htmlparser/src/CNavDTD.cpp, line 792 - * 3. <TABLE><TR><TD><TABLE>... allow nested <TABLE>
                   7101: /parser/htmlparser/src/CNavDTD.cpp, line 2562 - // Discard nested forms - bug 72639
                   7102: /parser/htmlparser/src/nsElementTable.cpp, line 1453 - * 2. <CENTER><DL><DT><A><CENTER> allow nested <CENTER>
                   7103: /parser/htmlparser/src/nsElementTable.cpp, line 1454 - * 3. <TABLE><TR><TD><TABLE>... allow nested <TABLE>
                   7104: /parser/htmlparser/src/nsElementTable.cpp, line 1901 - // Ex: <H1><LI><H1><LI>. Inner LI has the potential of getting nested
                   7105: -->
                   7106: 
                   7107: 
                   7108:   <h4 id="coercing-an-html-dom-into-an-infoset"><span class="secno">9.2.7 </span>Coercing an HTML DOM into an infoset</h4>
                   7109: 
                   7110:   <p>When an application uses an <a href="#html-parser">HTML parser</a> in
                   7111:   conjunction with an XML pipeline, it is possible that the
                   7112:   constructed DOM is not compatible with the XML tool chain in certain
                   7113:   subtle ways. For example, an XML toolchain might not be able to
                   7114:   represent attributes with the name <code title="">xmlns</code>,
                   7115:   since they conflict with the Namespaces in XML syntax. There is also
                   7116:   some data that the <a href="#html-parser">HTML parser</a> generates that isn't
                   7117:   included in the DOM itself. This section specifies some rules for
                   7118:   handling these issues.</p>
                   7119: 
                   7120:   <p>If the XML API being used doesn't support DOCTYPEs, the tool may
                   7121:   drop DOCTYPEs altogether.</p>
                   7122: 
                   7123:   <p>If the XML API doesn't support attributes in no namespace that
                   7124:   are named "<code title="">xmlns</code>", attributes whose names
                   7125:   start with "<code title="">xmlns:</code>", or attributes in the
                   7126:   <a href="#xmlns-namespace">XMLNS namespace</a>, then the tool may drop such
                   7127:   attributes.</p>
                   7128: 
                   7129:   <p>The tool may annotate the output with any namespace declarations
                   7130:   required for proper operation.</p>
                   7131: 
                   7132:   <p>If the XML API being used restricts the allowable characters in
                   7133:   the local names of elements and attributes, then the tool may map
                   7134:   all element and attribute local names that the API wouldn't support
                   7135:   to a set of names that <em>are</em> allowed, by replacing any
                   7136:   character that isn't supported with the uppercase letter U and the
                   7137:   six digits of the character's Unicode code point when expressed in
                   7138:   hexadecimal, using digits 0-9 and capital letters A-F as the
                   7139:   symbols, in increasing numeric order.</p>
                   7140: 
                   7141:   <p class="example">For example, the element name <code title="">foo&lt;bar</code>, which can be output by the <a href="#html-parser">HTML
                   7142:   parser</a>, though it is neither a legal HTML element name nor a
                   7143:   well-formed XML element name, would be converted into <code title="">fooU00003Cbar</code>, which <em>is</em> a well-formed XML
                   7144:   element name (though it's still not legal in HTML by any means).</p>
                   7145: 
                   7146:   <p class="example">As another example, consider the attribute
                   7147:   <code>xlink:href</code>. Used on a MathML element, it becomes, after
                   7148:   being <a href="#adjust-foreign-attributes" title="adjust foreign attributes">adjusted</a>, an
                   7149:   attribute with a prefix "<code title="">xlink</code>" and a local
                   7150:   name "<code title="">href</code>". However, used on an HTML element,
                   7151:   it becomes an attribute with no prefix and the local name "<code title="">xlink:href</code>", which is not a valid NCName, and thus
                   7152:   might not be accepted by an XML API. It could thus get converted,
                   7153:   becoming "<code title="">xlinkU00003Ahref</code>".</p>
                   7154: 
                   7155:   <p class="note">The resulting names from this conversion
                   7156:   conveniently can't clash with any attribute generated by the
                   7157:   <a href="#html-parser">HTML parser</a>, since those are all either lowercase or
                   7158:   those listed in the <a href="#adjust-foreign-attributes">adjust foreign attributes</a>
                   7159:   algorithm's table.</p>
                   7160: 
                   7161:   <p>If the XML API restricts comments from having two consecutive
                   7162:   U+002D HYPHEN-MINUS characters (--), the tool may insert a single
                   7163:   U+0020 SPACE character between any such offending characters.</p>
                   7164: 
                   7165:   <p>If the XML API restricts comments from ending in a
                   7166:   U+002D HYPHEN-MINUS character (-), the tool may insert a single
                   7167:   U+0020 SPACE character at the end of such comments.</p>
                   7168: 
                   7169:   <p>If the XML API restricts allowed characters in character data,
                   7170:   the tool may replace any U+000C FORM FEED (FF) character with a
                   7171:   U+0020 SPACE character, and any other literal non-XML character with
                   7172:   a U+FFFD REPLACEMENT CHARACTER.</p>
                   7173: 
                   7174:   <p>If the tool has no way to convey out-of-band information, then
                   7175:   the tool may drop the following information:</p>
                   7176: 
                   7177:   <ul><li>Whether the document is set to <i><a href="dom.html#no-quirks-mode">no quirks mode</a></i>,
                   7178:    <i><a href="dom.html#limited-quirks-mode">limited quirks mode</a></i>, or <i><a href="dom.html#quirks-mode">quirks mode</a></i></li>
                   7179: 
                   7180:    <li>The association between form controls and forms that aren't
                   7181:    their nearest <code><a href="forms.html#the-form-element">form</a></code> element ancestor (use of the
                   7182:    <a href="#form-element-pointer"><code>form</code> element pointer</a> in the parser)</li>
                   7183: 
                   7184:   </ul><p class="note">The mutations allowed by this section apply
                   7185:   <em>after</em> the <a href="#html-parser">HTML parser</a>'s rules have been
                   7186:   applied. For example, a <code title="">&lt;a::&gt;</code> start tag
                   7187:   will be closed by a <code title="">&lt;/a::&gt;</code> end tag, and
                   7188:   never by a <code title="">&lt;/aU00003AU00003A&gt;</code> end tag, even
                   7189:   if the user agent is using the rules above to then generate an
                   7190:   actual element in the DOM with the name <code title="">aU00003AU00003A</code> for that start tag.</p>
                   7191: 
                   7192: 
                   7193: 
1.35      mike     7194:   <h4 id="an-introduction-to-error-handling-and-strange-cases-in-the-parser"><span class="secno">9.2.8 </span>An introduction to error handling and strange cases in the parser</h4>
1.1       mike     7195: 
                   7196:   <p><i>This section is non-normative.</i></p>
                   7197: 
                   7198:   <p>This section examines some erroneous markup and discusses how
                   7199:   the <a href="#html-parser">HTML parser</a> handles these cases.</p>
                   7200: 
                   7201: 
                   7202:   <h5 id="misnested-tags:-b-i-b-i"><span class="secno">9.2.8.1 </span>Misnested tags: &lt;b&gt;&lt;i&gt;&lt;/b&gt;&lt;/i&gt;</h5>
                   7203: 
                   7204:   <p><i>This section is non-normative.</i></p>
                   7205: 
                   7206:   <p>The most-often discussed example of erroneous markup is as
                   7207:   follows:</p>
                   7208: 
                   7209:   <pre>&lt;p&gt;1&lt;b&gt;2&lt;i&gt;3&lt;/b&gt;4&lt;/i&gt;5&lt;/p&gt;</pre>
                   7210: 
                   7211:   <p>The parsing of this markup is straightforward up to the "3". At
                   7212:   this point, the DOM looks like this:</p>
                   7213: 
                   7214:   <ul class="domTree"><li class="t1"><code><a href="semantics.html#the-html-element">html</a></code><ul><li class="t1"><code><a href="semantics.html#the-head-element">head</a></code></li><li class="t1"><code><a href="semantics.html#the-body-element">body</a></code><ul><li class="t1"><code><a href="semantics.html#the-p-element">p</a></code><ul><li class="t3"><code>#text</code>: <span title="">1</span></li><li class="t1"><code><a href="text-level-semantics.html#the-b-element">b</a></code><ul><li class="t3"><code>#text</code>: <span title="">2</span></li><li class="t1"><code><a href="text-level-semantics.html#the-i-element">i</a></code><ul><li class="t3"><code>#text</code>: <span title="">3</span></li></ul></li></ul></li></ul></li></ul></li></ul></li></ul><p>Here, the <a href="#stack-of-open-elements">stack of open elements</a> has five elements
                   7215:   on it: <code><a href="semantics.html#the-html-element">html</a></code>, <code><a href="semantics.html#the-body-element">body</a></code>, <code><a href="semantics.html#the-p-element">p</a></code>,
                   7216:   <code><a href="text-level-semantics.html#the-b-element">b</a></code>, and <code><a href="text-level-semantics.html#the-i-element">i</a></code>. The <a href="#list-of-active-formatting-elements">list of active
                   7217:   formatting elements</a> just has two: <code><a href="text-level-semantics.html#the-b-element">b</a></code> and
                   7218:   <code><a href="text-level-semantics.html#the-i-element">i</a></code>. The <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-inbody" title="insertion mode: in body">in body</a>".</p>
                   7219: 
                   7220:   <p>Upon receiving the end tag token with the tag name "b", the "<a href="#adoptionAgency">adoption agency algorithm</a>" is
                   7221:   invoked. This is a simple case, in that the <var title="">formatting
                   7222:   element</var> is the <code><a href="text-level-semantics.html#the-b-element">b</a></code> element, and there is no
                   7223:   <var title="">furthest block</var>. Thus, the <a href="#stack-of-open-elements">stack of open
                   7224:   elements</a> ends up with just three elements: <code><a href="semantics.html#the-html-element">html</a></code>,
                   7225:   <code><a href="semantics.html#the-body-element">body</a></code>, and <code><a href="semantics.html#the-p-element">p</a></code>, while the <a href="#list-of-active-formatting-elements">list of
                   7226:   active formatting elements</a> has just one: <code><a href="text-level-semantics.html#the-i-element">i</a></code>. The
                   7227:   DOM tree is unmodified at this point.</p>
                   7228: 
                   7229:   <p>The next token is a character ("4"), triggers the <a href="#reconstruct-the-active-formatting-elements" title="reconstruct the active formatting elements">reconstruction of
                   7230:   the active formatting elements</a>, in this case just the
                   7231:   <code><a href="text-level-semantics.html#the-i-element">i</a></code> element. A new <code><a href="text-level-semantics.html#the-i-element">i</a></code> element is thus created
                   7232:   for the "4" text node. After the end tag token for the "i" is also
                   7233:   received, and the "5" text node is inserted, the DOM looks as
                   7234:   follows:</p>
                   7235: 
                   7236:   <ul class="domTree"><li class="t1"><code><a href="semantics.html#the-html-element">html</a></code><ul><li class="t1"><code><a href="semantics.html#the-head-element">head</a></code></li><li class="t1"><code><a href="semantics.html#the-body-element">body</a></code><ul><li class="t1"><code><a href="semantics.html#the-p-element">p</a></code><ul><li class="t3"><code>#text</code>: <span title="">1</span></li><li class="t1"><code><a href="text-level-semantics.html#the-b-element">b</a></code><ul><li class="t3"><code>#text</code>: <span title="">2</span></li><li class="t1"><code><a href="text-level-semantics.html#the-i-element">i</a></code><ul><li class="t3"><code>#text</code>: <span title="">3</span></li></ul></li></ul></li><li class="t1"><code><a href="text-level-semantics.html#the-i-element">i</a></code><ul><li class="t3"><code>#text</code>: <span title="">4</span></li></ul></li><li class="t3"><code>#text</code>: <span title="">5</span></li></ul></li></ul></li></ul></li></ul><h5 id="misnested-tags:-b-p-b-p"><span class="secno">9.2.8.2 </span>Misnested tags: &lt;b&gt;&lt;p&gt;&lt;/b&gt;&lt;/p&gt;</h5>
                   7237: 
                   7238:   <p><i>This section is non-normative.</i></p>
                   7239: 
                   7240:   <p>A case similar to the previous one is the following:</p>
                   7241: 
                   7242:   <pre>&lt;b&gt;1&lt;p&gt;2&lt;/b&gt;3&lt;/p&gt;</pre>
                   7243: 
                   7244:   <p>Up to the "2" the parsing here is straightforward:</p>
                   7245: 
                   7246:   <ul class="domTree"><li class="t1"><code><a href="semantics.html#the-html-element">html</a></code><ul><li class="t1"><code><a href="semantics.html#the-head-element">head</a></code></li><li class="t1"><code><a href="semantics.html#the-body-element">body</a></code><ul><li class="t1"><code><a href="text-level-semantics.html#the-b-element">b</a></code><ul><li class="t3"><code>#text</code>: <span title="">1</span></li><li class="t1"><code><a href="semantics.html#the-p-element">p</a></code><ul><li class="t3"><code>#text</code>: <span title="">2</span></li></ul></li></ul></li></ul></li></ul></li></ul><p>The interesting part is when the end tag token with the tag name
                   7247:   "b" is parsed.</p>
                   7248: 
                   7249:   <p>Before that token is seen, the <a href="#stack-of-open-elements">stack of open
                   7250:   elements</a> has four elements on it: <code><a href="semantics.html#the-html-element">html</a></code>,
                   7251:   <code><a href="semantics.html#the-body-element">body</a></code>, <code><a href="text-level-semantics.html#the-b-element">b</a></code>, and <code><a href="semantics.html#the-p-element">p</a></code>. The
                   7252:   <a href="#list-of-active-formatting-elements">list of active formatting elements</a> just has the one:
                   7253:   <code><a href="text-level-semantics.html#the-b-element">b</a></code>. The <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-inbody" title="insertion mode: in body">in body</a>".</p>
                   7254: 
                   7255:   <p>Upon receiving the end tag token with the tag name "b", the "<a href="#adoptionAgency">adoption agency algorithm</a>" is invoked, as
                   7256:   in the previous example. However, in this case, there <em>is</em> a
                   7257:   <var title="">furthest block</var>, namely the <code><a href="semantics.html#the-p-element">p</a></code> element. Thus,
                   7258:   this time the adoption agency algorithm isn't skipped over.</p>
                   7259: 
                   7260:   <p>The <var title="">common ancestor</var> is the <code><a href="semantics.html#the-body-element">body</a></code>
                   7261:   element. A conceptual "bookmark" marks the position of the
                   7262:   <code><a href="text-level-semantics.html#the-b-element">b</a></code> in the <a href="#list-of-active-formatting-elements">list of active formatting
                   7263:   elements</a>, but since that list has only one element in it,
                   7264:   it won't have much effect.</p>
                   7265: 
                   7266:   <p>As the algorithm progresses, <var title="">node</var> ends up set
                   7267:   to the formatting element (<code><a href="text-level-semantics.html#the-b-element">b</a></code>), and <var title="">last
                   7268:   node</var> ends up set to the <var title="">furthest block</var>
                   7269:   (<code><a href="semantics.html#the-p-element">p</a></code>).</p>
                   7270: 
                   7271:   <p>The <var title="">last node</var> gets appended (moved) to the
                   7272:   <var title="">common ancestor</var>, so that the DOM looks like:</p>
                   7273: 
                   7274:   <ul class="domTree"><li class="t1"><code><a href="semantics.html#the-html-element">html</a></code><ul><li class="t1"><code><a href="semantics.html#the-head-element">head</a></code></li><li class="t1"><code><a href="semantics.html#the-body-element">body</a></code><ul><li class="t1"><code><a href="text-level-semantics.html#the-b-element">b</a></code><ul><li class="t3"><code>#text</code>: <span title="">1</span></li></ul></li><li class="t1"><code><a href="semantics.html#the-p-element">p</a></code><ul><li class="t3"><code>#text</code>: <span title="">2</span></li></ul></li></ul></li></ul></li></ul><p>A new <code><a href="text-level-semantics.html#the-b-element">b</a></code> element is created, and the children of the
                   7275:   <code><a href="semantics.html#the-p-element">p</a></code> element are moved to it:</p>
                   7276: 
                   7277:   <ul class="domTree"><li class="t1"><code><a href="semantics.html#the-html-element">html</a></code><ul><li class="t1"><code><a href="semantics.html#the-head-element">head</a></code></li><li class="t1"><code><a href="semantics.html#the-body-element">body</a></code><ul><li class="t1"><code><a href="text-level-semantics.html#the-b-element">b</a></code><ul><li class="t3"><code>#text</code>: <span title="">1</span></li></ul></li><li class="t1"><code><a href="semantics.html#the-p-element">p</a></code></li></ul></li></ul></li></ul><ul class="domTree"><li class="t1"><code><a href="text-level-semantics.html#the-b-element">b</a></code><ul><li class="t3"><code>#text</code>: <span title="">2</span></li></ul></li></ul><p>Finally, the new <code><a href="text-level-semantics.html#the-b-element">b</a></code> element is appended to the
                   7278:   <code><a href="semantics.html#the-p-element">p</a></code> element, so that the DOM looks like:</p>
                   7279: 
                   7280:   <ul class="domTree"><li class="t1"><code><a href="semantics.html#the-html-element">html</a></code><ul><li class="t1"><code><a href="semantics.html#the-head-element">head</a></code></li><li class="t1"><code><a href="semantics.html#the-body-element">body</a></code><ul><li class="t1"><code><a href="text-level-semantics.html#the-b-element">b</a></code><ul><li class="t3"><code>#text</code>: <span title="">1</span></li></ul></li><li class="t1"><code><a href="semantics.html#the-p-element">p</a></code><ul><li class="t1"><code><a href="text-level-semantics.html#the-b-element">b</a></code><ul><li class="t3"><code>#text</code>: <span title="">2</span></li></ul></li></ul></li></ul></li></ul></li></ul><p>The <code><a href="text-level-semantics.html#the-b-element">b</a></code> element is removed from the <a href="#list-of-active-formatting-elements">list of
                   7281:   active formatting elements</a> and the <a href="#stack-of-open-elements">stack of open
                   7282:   elements</a>, so that when the "3" is parsed, it is appended to
                   7283:   the <code><a href="semantics.html#the-p-element">p</a></code> element:</p>
                   7284: 
                   7285:   <ul class="domTree"><li class="t1"><code><a href="semantics.html#the-html-element">html</a></code><ul><li class="t1"><code><a href="semantics.html#the-head-element">head</a></code></li><li class="t1"><code><a href="semantics.html#the-body-element">body</a></code><ul><li class="t1"><code><a href="text-level-semantics.html#the-b-element">b</a></code><ul><li class="t3"><code>#text</code>: <span title="">1</span></li></ul></li><li class="t1"><code><a href="semantics.html#the-p-element">p</a></code><ul><li class="t1"><code><a href="text-level-semantics.html#the-b-element">b</a></code><ul><li class="t3"><code>#text</code>: <span title="">2</span></li></ul></li><li class="t3"><code>#text</code>: <span title="">3</span></li></ul></li></ul></li></ul></li></ul><h5 id="unexpected-markup-in-tables"><span class="secno">9.2.8.3 </span>Unexpected markup in tables</h5>
                   7286: 
                   7287:   <p><i>This section is non-normative.</i></p>
                   7288: 
                   7289:   <p>Error handling in tables is, for historical reasons, especially
                   7290:   strange. For example, consider the following markup:</p>
                   7291: 
                   7292:   <pre>&lt;table&gt;<strong>&lt;b&gt;</strong>&lt;tr&gt;&lt;td&gt;aaa&lt;/td&gt;&lt;/tr&gt;<strong>bbb</strong>&lt;/table&gt;ccc</pre>
                   7293: 
                   7294:   <p>The highlighted <code><a href="text-level-semantics.html#the-b-element">b</a></code> element start tag is not allowed
                   7295:   directly inside a table like that, and the parser handles this case
                   7296:   by placing the element <em>before</em> the table. (This is called <i title="foster parent"><a href="#foster-parent">foster parenting</a></i>.) This can be seen by
                   7297:   examining the DOM tree as it stands just after the
                   7298:   <code><a href="tabular-data.html#the-table-element">table</a></code> element's start tag has been seen:</p>
                   7299: 
                   7300:   <ul class="domTree"><li class="t1"><code><a href="semantics.html#the-html-element">html</a></code><ul><li class="t1"><code><a href="semantics.html#the-head-element">head</a></code></li><li class="t1"><code><a href="semantics.html#the-body-element">body</a></code><ul><li class="t1"><code><a href="tabular-data.html#the-table-element">table</a></code></li></ul></li></ul></li></ul><p>...and then immediately after the <code><a href="text-level-semantics.html#the-b-element">b</a></code> element start
                   7301:   tag has been seen:</p>
                   7302: 
                   7303:   <ul class="domTree"><li class="t1"><code><a href="semantics.html#the-html-element">html</a></code><ul><li class="t1"><code><a href="semantics.html#the-head-element">head</a></code></li><li class="t1"><code><a href="semantics.html#the-body-element">body</a></code><ul><li class="t1"><code><a href="text-level-semantics.html#the-b-element">b</a></code></li><li class="t1"><code><a href="tabular-data.html#the-table-element">table</a></code></li></ul></li></ul></li></ul><p>At this point, the <a href="#stack-of-open-elements">stack of open elements</a> has on it
                   7304:   the elements <code><a href="semantics.html#the-html-element">html</a></code>, <code><a href="semantics.html#the-body-element">body</a></code>,
                   7305:   <code><a href="tabular-data.html#the-table-element">table</a></code>, and <code><a href="text-level-semantics.html#the-b-element">b</a></code> (in that order, despite the
                   7306:   resulting DOM tree); the <a href="#list-of-active-formatting-elements">list of active formatting
                   7307:   elements</a> just has the <code><a href="text-level-semantics.html#the-b-element">b</a></code> element in it; and the
                   7308:   <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-intable" title="insertion mode: in
                   7309:   table">in table</a>".</p>
                   7310: 
                   7311:   <p>The <code><a href="tabular-data.html#the-tr-element">tr</a></code> start tag causes the <code><a href="text-level-semantics.html#the-b-element">b</a></code> element
                   7312:   to be popped off the stack and a <code><a href="tabular-data.html#the-tbody-element">tbody</a></code> start tag to be
                   7313:   implied; the <code><a href="tabular-data.html#the-tbody-element">tbody</a></code> and <code><a href="tabular-data.html#the-tr-element">tr</a></code> elements are
                   7314:   then handled in a rather straight-forward manner, taking the parser
                   7315:   through the "<a href="#parsing-main-intbody" title="insertion mode: in table body">in table
                   7316:   body</a>" and "<a href="#parsing-main-intr" title="insertion mode: in row">in
                   7317:   row</a>" insertion modes, after which the DOM looks as
                   7318:   follows:</p>
                   7319: 
                   7320:   <ul class="domTree"><li class="t1"><code><a href="semantics.html#the-html-element">html</a></code><ul><li class="t1"><code><a href="semantics.html#the-head-element">head</a></code></li><li class="t1"><code><a href="semantics.html#the-body-element">body</a></code><ul><li class="t1"><code><a href="text-level-semantics.html#the-b-element">b</a></code></li><li class="t1"><code><a href="tabular-data.html#the-table-element">table</a></code><ul><li class="t1"><code><a href="tabular-data.html#the-tbody-element">tbody</a></code><ul><li class="t1"><code><a href="tabular-data.html#the-tr-element">tr</a></code></li></ul></li></ul></li></ul></li></ul></li></ul><p>Here, the <a href="#stack-of-open-elements">stack of open elements</a> has on it the
                   7321:   elements <code><a href="semantics.html#the-html-element">html</a></code>, <code><a href="semantics.html#the-body-element">body</a></code>, <code><a href="tabular-data.html#the-table-element">table</a></code>,
                   7322:   <code><a href="tabular-data.html#the-tbody-element">tbody</a></code>, and <code><a href="tabular-data.html#the-tr-element">tr</a></code>; the <a href="#list-of-active-formatting-elements">list of active
                   7323:   formatting elements</a> still has the <code><a href="text-level-semantics.html#the-b-element">b</a></code> element in
                   7324:   it; and the <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-intr" title="insertion
                   7325:   mode: in row">in row</a>".</p>
                   7326: 
                   7327:   <p>The <code><a href="tabular-data.html#the-td-element">td</a></code> element start tag token, after putting a
                   7328:   <code><a href="tabular-data.html#the-td-element">td</a></code> element on the tree, puts a marker on the <a href="#list-of-active-formatting-elements">list
                   7329:   of active formatting elements</a> (it also switches to the "<a href="#parsing-main-intd" title="insertion mode: in cell">in cell</a>" <a href="#insertion-mode">insertion
                   7330:   mode</a>).</p>
                   7331: 
                   7332:   <ul class="domTree"><li class="t1"><code><a href="semantics.html#the-html-element">html</a></code><ul><li class="t1"><code><a href="semantics.html#the-head-element">head</a></code></li><li class="t1"><code><a href="semantics.html#the-body-element">body</a></code><ul><li class="t1"><code><a href="text-level-semantics.html#the-b-element">b</a></code></li><li class="t1"><code><a href="tabular-data.html#the-table-element">table</a></code><ul><li class="t1"><code><a href="tabular-data.html#the-tbody-element">tbody</a></code><ul><li class="t1"><code><a href="tabular-data.html#the-tr-element">tr</a></code><ul><li class="t1"><code><a href="tabular-data.html#the-td-element">td</a></code></li></ul></li></ul></li></ul></li></ul></li></ul></li></ul><p>The marker means that when the "aaa" character tokens are seen,
                   7333:   no <code><a href="text-level-semantics.html#the-b-element">b</a></code> element is created to hold the resulting text
                   7334:   node:</p>
                   7335: 
                   7336:   <ul class="domTree"><li class="t1"><code><a href="semantics.html#the-html-element">html</a></code><ul><li class="t1"><code><a href="semantics.html#the-head-element">head</a></code></li><li class="t1"><code><a href="semantics.html#the-body-element">body</a></code><ul><li class="t1"><code><a href="text-level-semantics.html#the-b-element">b</a></code></li><li class="t1"><code><a href="tabular-data.html#the-table-element">table</a></code><ul><li class="t1"><code><a href="tabular-data.html#the-tbody-element">tbody</a></code><ul><li class="t1"><code><a href="tabular-data.html#the-tr-element">tr</a></code><ul><li class="t1"><code><a href="tabular-data.html#the-td-element">td</a></code><ul><li class="t3"><code>#text</code>: <span title="">aaa</span></li></ul></li></ul></li></ul></li></ul></li></ul></li></ul></li></ul><p>The end tags are handled in a straight-forward manner; after
                   7337:   handling them, the <a href="#stack-of-open-elements">stack of open elements</a> has on it the
                   7338:   elements <code><a href="semantics.html#the-html-element">html</a></code>, <code><a href="semantics.html#the-body-element">body</a></code>, <code><a href="tabular-data.html#the-table-element">table</a></code>,
                   7339:   and <code><a href="tabular-data.html#the-tbody-element">tbody</a></code>; the <a href="#list-of-active-formatting-elements">list of active formatting
                   7340:   elements</a> still has the <code><a href="text-level-semantics.html#the-b-element">b</a></code> element in it (the
                   7341:   marker having been removed by the "td" end tag token); and the
                   7342:   <a href="#insertion-mode">insertion mode</a> is "<a href="#parsing-main-intbody" title="insertion mode: in
                   7343:   table body">in table body</a>".</p>
                   7344: 
                   7345:   <p>Thus it is that the "bbb" character tokens are found. These
                   7346:   trigger the "<a href="#parsing-main-intabletext" title="insertion mode: in table text">in table
                   7347:   text</a>" insertion mode to be used (with the <a href="#original-insertion-mode">original
                   7348:   insertion mode</a> set to "<a href="#parsing-main-intbody" title="insertion mode: in table
                   7349:   body">in table body</a>"). The character tokens are collected,
                   7350:   and when the next token (the <code><a href="tabular-data.html#the-table-element">table</a></code> element end tag) is
                   7351:   seen, they are processed as a group. Since they are not all spaces,
                   7352:   they are handled as per the "anything else" rules in the "<a href="#parsing-main-intable" title="insertion mode: in table">in table</a>" insertion mode,
                   7353:   which defer to the "<a href="#parsing-main-inbody" title="insertion mode: in body">in
                   7354:   body</a>" insertion mode but with <a href="#foster-parent" title="foster
                   7355:   parent">foster parenting</a>.</p>
                   7356: 
                   7357:   <p>When <a href="#reconstruct-the-active-formatting-elements" title="reconstruct the active formatting elements">the
                   7358:   active formatting elements are reconstructed</a>, a
                   7359:   <code><a href="text-level-semantics.html#the-b-element">b</a></code> element is created and <a href="#foster-parent" title="foster
                   7360:   parent">foster parented</a>, and then the "bbb" text node is
                   7361:   appended to it:</p>
                   7362: 
                   7363:   <ul class="domTree"><li class="t1"><code><a href="semantics.html#the-html-element">html</a></code><ul><li class="t1"><code><a href="semantics.html#the-head-element">head</a></code></li><li class="t1"><code><a href="semantics.html#the-body-element">body</a></code><ul><li class="t1"><code><a href="text-level-semantics.html#the-b-element">b</a></code></li><li class="t1"><code><a href="text-level-semantics.html#the-b-element">b</a></code><ul><li class="t3"><code>#text</code>: <span title="">bbb</span></li></ul></li><li class="t1"><code><a href="tabular-data.html#the-table-element">table</a></code><ul><li class="t1"><code><a href="tabular-data.html#the-tbody-element">tbody</a></code><ul><li class="t1"><code><a href="tabular-data.html#the-tr-element">tr</a></code><ul><li class="t1"><code><a href="tabular-data.html#the-td-element">td</a></code><ul><li class="t3"><code>#text</code>: <span title="">aaa</span></li></ul></li></ul></li></ul></li></ul></li></ul></li></ul></li></ul><p>The <a href="#stack-of-open-elements">stack of open elements</a> has on it the elements
                   7364:   <code><a href="semantics.html#the-html-element">html</a></code>, <code><a href="semantics.html#the-body-element">body</a></code>, <code><a href="tabular-data.html#the-table-element">table</a></code>,
                   7365:   <code><a href="tabular-data.html#the-tbody-element">tbody</a></code>, and the new <code><a href="text-level-semantics.html#the-b-element">b</a></code> (again, note that
                   7366:   this doesn't match the resulting tree!); the <a href="#list-of-active-formatting-elements">list of active
                   7367:   formatting elements</a> has the new <code><a href="text-level-semantics.html#the-b-element">b</a></code> element in it;
                   7368:   and the <a href="#insertion-mode">insertion mode</a> is still "<a href="#parsing-main-intbody" title="insertion
                   7369:   mode: in table body">in table body</a>".</p>
                   7370: 
                   7371:   <p>Had the character tokens been only <a href="infrastructure.html#space-character" title="space
                   7372:   character">space characters</a> instead of "bbb", then those
                   7373:   <a href="infrastructure.html#space-character" title="space character">space characters</a> would just be
                   7374:   appended to the <code><a href="tabular-data.html#the-tbody-element">tbody</a></code> element.</p>
                   7375: 
                   7376:   <p>Finally, the <code><a href="tabular-data.html#the-table-element">table</a></code> is closed by a "table" end
                   7377:   tag. This pops all the nodes from the <a href="#stack-of-open-elements">stack of open
                   7378:   elements</a> up to and including the <code><a href="tabular-data.html#the-table-element">table</a></code> element,
                   7379:   but it doesn't affect the <a href="#list-of-active-formatting-elements">list of active formatting
                   7380:   elements</a>, so the "ccc" character tokens after the table
                   7381:   result in yet another <code><a href="text-level-semantics.html#the-b-element">b</a></code> element being created, this
                   7382:   time after the table:</p>
                   7383: 
                   7384:   <ul class="domTree"><li class="t1"><code><a href="semantics.html#the-html-element">html</a></code><ul><li class="t1"><code><a href="semantics.html#the-head-element">head</a></code></li><li class="t1"><code><a href="semantics.html#the-body-element">body</a></code><ul><li class="t1"><code><a href="text-level-semantics.html#the-b-element">b</a></code></li><li class="t1"><code><a href="text-level-semantics.html#the-b-element">b</a></code><ul><li class="t3"><code>#text</code>: <span title="">bbb</span></li></ul></li><li class="t1"><code><a href="tabular-data.html#the-table-element">table</a></code><ul><li class="t1"><code><a href="tabular-data.html#the-tbody-element">tbody</a></code><ul><li class="t1"><code><a href="tabular-data.html#the-tr-element">tr</a></code><ul><li class="t1"><code><a href="tabular-data.html#the-td-element">td</a></code><ul><li class="t3"><code>#text</code>: <span title="">aaa</span></li></ul></li></ul></li></ul></li></ul></li><li class="t1"><code><a href="text-level-semantics.html#the-b-element">b</a></code><ul><li class="t3"><code>#text</code>: <span title="">ccc</span></li></ul></li></ul></li></ul></li></ul><h5 id="scripts-that-modify-the-page-as-it-is-being-parsed"><span class="secno">9.2.8.4 </span>Scripts that modify the page as it is being parsed</h5>
                   7385: 
                   7386:   <p><i>This section is non-normative.</i></p>
                   7387: 
                   7388:   <p>Consider the following markup, which for this example we will
                   7389:   assume is the document with <a href="infrastructure.html#url">URL</a> <code title="">http://example.com/inner</code>, being rendered as the
                   7390:   content of an <code><a href="embedded-content-0.html#the-iframe-element">iframe</a></code> in another document with the
                   7391:   <a href="infrastructure.html#url">URL</a> <code title="">http://example.com/outer</code>:</p>
                   7392: 
                   7393:   <pre>&lt;div id=a&gt;
                   7394:  &lt;script&gt;
                   7395:   var div = document.getElementById('a');
                   7396:   parent.document.body.appendChild(div);
                   7397:  &lt;/script&gt;
                   7398:  &lt;script&gt;
                   7399:   alert(document.URL);
                   7400:  &lt;/script&gt;
                   7401: &lt;/div&gt;
                   7402: &lt;script&gt;
                   7403:  alert(document.URL);
                   7404: &lt;/script&gt;</pre>
                   7405: 
                   7406:   <p>Up to the first "script" end tag, before the script is parsed,
                   7407:   the result is relatively straightforward:</p>
                   7408: 
                   7409:   <ul class="domTree"><li class="t1"><code><a href="semantics.html#the-html-element">html</a></code><ul><li class="t1"><code><a href="semantics.html#the-head-element">head</a></code></li><li class="t1"><code><a href="semantics.html#the-body-element">body</a></code><ul><li class="t1"><code><a href="interactive-elements.html#the-div-element">div</a></code> <span class="t2" title=""><code class="attribute name">id</code>="<code class="attribute value"><a href="text-level-semantics.html#the-a-element">a</a></code>"</span><ul><li class="t3"><code>#text</code>: <span title="">
                   7410:  </span></li><li class="t1"><code><a href="semantics.html#script">script</a></code><ul><li class="t3"><code>#text</code>: <span title="">var div = document.getElementById('a'); &#9166; parent.document.body.appendChild(div);</span></li></ul></li></ul></li></ul></li></ul></li></ul><p>After the script is parsed, though, the <code><a href="interactive-elements.html#the-div-element">div</a></code> element
                   7411:   and its child <code><a href="semantics.html#script">script</a></code> element are gone:</p>
                   7412: 
                   7413:   <ul class="domTree"><li class="t1"><code><a href="semantics.html#the-html-element">html</a></code><ul><li class="t1"><code><a href="semantics.html#the-head-element">head</a></code></li><li class="t1"><code><a href="semantics.html#the-body-element">body</a></code></li></ul></li></ul><p>They are, at this point, in the <code>Document</code> of the
                   7414:   aforementioned outer <a href="browsers.html#browsing-context">browsing context</a>. However, the
                   7415:   <a href="#stack-of-open-elements">stack of open elements</a> <em>still contains the
                   7416:   <code><a href="interactive-elements.html#the-div-element">div</a></code> element</em>.</p>
                   7417: 
                   7418:   <p>Thus, when the second <code><a href="semantics.html#script">script</a></code> element is parsed, it
                   7419:   is inserted <em>into the outer <code>Document</code>
                   7420:   object</em>.</p>
                   7421: 
                   7422:   <p>This also means that the <a href="browsers.html#script-s-global-object">script's global object</a> is
                   7423:   the outer <a href="browsers.html#browsing-context">browsing context</a>'s <code><a href="browsers.html#window">Window</a></code>
                   7424:   object, <em>not</em> the <code><a href="browsers.html#window">Window</a></code> object inside the
                   7425:   <code><a href="embedded-content-0.html#the-iframe-element">iframe</a></code>.</p>
                   7426: 
                   7427:   <p class="note">This isn't a security problem since the script that
                   7428:   moves the <code><a href="interactive-elements.html#the-div-element">div</a></code> into the outer <code>Document</code> can
                   7429:   only do so because they have the two <code>Document</code> object
                   7430:   have the same <a href="browsers.html#origin-0">origin</a>.</p>
                   7431: 
                   7432:   <p>Thus, the first alert says "http://example.com/outer".</p>
                   7433: 
                   7434:   <p>Once the <code><a href="interactive-elements.html#the-div-element">div</a></code> element's end tag is parsed, the
                   7435:   <code><a href="interactive-elements.html#the-div-element">div</a></code> element is popped off the stack, and so the next
                   7436:   <code><a href="semantics.html#script">script</a></code> element is in the inner <code>Document</code>:</p>
                   7437: 
                   7438:   <ul class="domTree"><li class="t1"><code><a href="semantics.html#the-html-element">html</a></code><ul><li class="t1"><code><a href="semantics.html#the-head-element">head</a></code></li><li class="t1"><code><a href="semantics.html#the-body-element">body</a></code><ul><li class="t1"><code><a href="semantics.html#script">script</a></code><ul><li class="t3"><code>#text</code>: <span title="">alert(document.URL);</span></li></ul></li></ul></li></ul></li></ul><p>This second alert will say "http://example.com/inner".</p>
                   7439: 
                   7440: 
                   7441: 
                   7442:   <h3 id="namespaces"><span class="secno">9.3 </span>Namespaces</h3>
                   7443: 
                   7444:   <p>The <dfn id="html-namespace-0">HTML namespace</dfn> is: <code>http://www.w3.org/1999/xhtml</code></p>
                   7445: 
                   7446:   <p>The <dfn id="mathml-namespace">MathML namespace</dfn> is: <code>http://www.w3.org/1998/Math/MathML</code></p>
                   7447: 
                   7448:   <p>The <dfn id="svg-namespace">SVG namespace</dfn> is: <code>http://www.w3.org/2000/svg</code></p>
                   7449: 
                   7450:   <p>The <dfn id="xlink-namespace">XLink namespace</dfn> is: <code>http://www.w3.org/1999/xlink</code></p>
                   7451: 
                   7452:   <p>The <dfn id="xml-namespace">XML namespace</dfn> is: <code>http://www.w3.org/XML/1998/namespace</code></p>
                   7453: 
                   7454:   <p>The <dfn id="xmlns-namespace">XMLNS namespace</dfn> is: <code>http://www.w3.org/2000/xmlns/</code></p>
                   7455: 
                   7456:   <hr><p>Data mining tools and other user agents that perform operations
1.83      mike     7457:   on <code><a href="iana-considerations.html#text-html">text/html</a></code> content without running scripts,
1.1       mike     7458:   evaluating CSS or XPath expressions, or otherwise exposing the
                   7459:   resulting DOM to arbitrary content, may "support namespaces" by just
                   7460:   asserting that their DOM node analogues are in certain namespaces,
                   7461:   without actually exposing the above strings.</p>
                   7462: 
                   7463: 
                   7464: 
                   7465: 
                   7466:   <h3 id="serializing-html-fragments"><span class="secno">9.4 </span>Serializing HTML fragments</h3>
                   7467: 
                   7468:   <p>The following steps form the <dfn id="html-fragment-serialization-algorithm">HTML fragment serialization
                   7469:   algorithm</dfn>. The algorithm takes as input a DOM
                   7470:   <code>Element</code> or <code>Document</code>, referred to as <var title="">the node</var>, and either returns a string or raises an
                   7471:   exception.</p>
                   7472: 
                   7473:   <p class="note">This algorithm serializes the <em>children</em> of
                   7474:   the node being serialized, not the node itself.</p>
                   7475: 
                   7476:   <ol><li><p>Let <var title="">s</var> be a string, and initialize it to
                   7477:    the empty string.</p></li>
                   7478: 
                   7479:    <li>
                   7480: 
                   7481:     <p>For each child node of <var title="">the node</var>, in
                   7482:     <a href="infrastructure.html#tree-order">tree order</a>, run the following steps:
                   7483: 
                   7484:     </p><ol><li><p>Let <var title="">current node</var> be the child node
                   7485:      being processed.</p></li>
                   7486: 
                   7487:      <li>
                   7488: 
                   7489:       <p>Append the appropriate string from the following list to
                   7490:       <var title="">s</var>:</p>
                   7491: 
                   7492:       <dl class="switch"><dt>If <var title="">current node</var> is an <code title="">Element</code></dt>
                   7493: 
                   7494:        <dd>
                   7495: 
                   7496:         <p>Append a U+003C LESS-THAN SIGN (<code title="">&lt;</code>)
                   7497:         character, followed by the element's tag name. (For nodes
                   7498:         created by the <a href="#html-parser">HTML parser</a> or <code title="">Document.createElement()</code>, the tag name will be
                   7499:         lowercase.)</p>
                   7500: 
                   7501:         <p>For each attribute that the element has, append a U+0020
                   7502:         SPACE character, the attribute's name (which, for attributes
                   7503:         set by the <a href="#html-parser">HTML parser</a> or by <code title="">Element.setAttributeNode()</code> or <code title="">Element.setAttribute()</code>, will be lowercase), a
                   7504:         U+003D EQUALS SIGN (<code title="">=</code>) character, a
                   7505:         U+0022 QUOTATION MARK (<code title="">"</code>)
                   7506:         character, the attribute's value, <a href="#escapingString" title="escaping a
                   7507:         string">escaped as described below</a> in <i>attribute
                   7508:         mode</i>, and a second U+0022 QUOTATION MARK (<code title="">"</code>) character.</p>
                   7509: 
                   7510:         <p>While the exact order of attributes is UA-defined, and may
                   7511:         depend on factors such as the order that the attributes were
                   7512:         given in the original markup, the sort order must be stable,
                   7513:         such that consecutive invocations of this algorithm serialize an
                   7514:         element's attributes in the same order.</p>
                   7515: 
                   7516:         <p>Append a U+003E GREATER-THAN SIGN (<code title="">&gt;</code>)
                   7517:         character.</p>
                   7518: 
                   7519:         <p>If <var title="">current node</var> is an
1.5       mike     7520:         <code><a href="the-canvas-element.html#the-area-element">area</a></code>, <code><a href="semantics.html#the-base-element">base</a></code>, <code><a href="obsolete.html#basefont">basefont</a></code>,
1.1       mike     7521:         <code>bgsound</code>, <code><a href="semantics.html#the-br-element">br</a></code>, <code><a href="tabular-data.html#the-col-element">col</a></code>,
1.5       mike     7522:         <code><a href="embedded-content-0.html#the-embed-element">embed</a></code>, <code><a href="obsolete.html#frame">frame</a></code>, <code><a href="semantics.html#the-hr-element">hr</a></code>,
1.1       mike     7523:         <code><a href="embedded-content-0.html#the-img-element">img</a></code>, <code><a href="forms.html#the-input-element">input</a></code>, <code><a href="forms.html#the-keygen-element">keygen</a></code>,
                   7524:         <code><a href="semantics.html#the-link-element">link</a></code>, <code><a href="semantics.html#meta">meta</a></code>, <code><a href="embedded-content-0.html#the-param-element">param</a></code>,
1.5       mike     7525:         <code><a href="obsolete.html#spacer">spacer</a></code>, or <code>wbr</code> element, then
1.1       mike     7526:         continue on to the next child node at this point.</p> <!--
                   7527:         also, i guess: image and isindex, but we don't list those
                   7528:         because we don't consider those "elements", more "macros", and
                   7529:         thus we should never serialize them -->
                   7530: 
                   7531:         <p>If <var title="">current node</var> is a <code><a href="semantics.html#the-pre-element">pre</a></code>,
1.42      mike     7532:         <code><a href="forms.html#the-textarea-element">textarea</a></code>, or <code><a href="obsolete.html#listing">listing</a></code> element, append
1.1       mike     7533:         a U+000A LINE FEED (LF) character.</p>
                   7534: 
                   7535:         <p>Append the value of running the <a href="#html-fragment-serialization-algorithm">HTML fragment
                   7536:         serialization algorithm</a> on the <var title="">current
                   7537:         node</var> element (thus recursing into this algorithm for
                   7538:         that element), followed by a U+003C LESS-THAN SIGN (<code title="">&lt;</code>) character, a U+002F SOLIDUS (<code title="">/</code>) character, the element's tag name again,
                   7539:         and finally a U+003E GREATER-THAN SIGN (<code title="">&gt;</code>) character.</p>
                   7540: 
                   7541:        </dd>
                   7542: 
                   7543: 
                   7544:        <dt>If <var title="">current node</var> is a <code title="">Text</code> or <code title="">CDATASection</code>
                   7545:        node</dt>
                   7546: 
                   7547:        <dd>
                   7548: 
1.19      mike     7549:         <p>If the parent of <var title="">current node</var> is a
1.42      mike     7550:         <code><a href="semantics.html#the-style-element">style</a></code>, <code><a href="semantics.html#script">script</a></code>, <code><a href="obsolete.html#xmp">xmp</a></code>,
1.19      mike     7551:         <code><a href="embedded-content-0.html#the-iframe-element">iframe</a></code>, <code><a href="obsolete.html#noembed">noembed</a></code>,
1.5       mike     7552:         <code><a href="obsolete.html#noframes">noframes</a></code>, <code><a href="semantics.html#the-noscript-element">noscript</a></code>, or
1.42      mike     7553:         <code><a href="obsolete.html#plaintext">plaintext</a></code> element, then append the value of <var title="">current node</var>'s <code title="">data</code> DOM
1.1       mike     7554:         attribute literally.</p> <!-- note about noscript: we're
                   7555:         assuming here that scripting is enabled. If this algorithm is
1.19      mike     7556:         used with scripting disabled, this won't work
                   7557:         right. (e.g. This might affect calling innerHTML on nodes in a
                   7558:         document that is being designMode'd) -->
1.1       mike     7559: 
                   7560:         <p>Otherwise, append the value of <var title="">current
                   7561:         node</var>'s <code title="">data</code> DOM attribute, <a href="#escapingString" title="escaping a string">escaped as described
                   7562:         below</a>.</p>
                   7563: 
                   7564:        </dd>
                   7565: 
                   7566: 
                   7567:        <dt>If <var title="">current node</var> is a <code title="">Comment</code></dt>
                   7568: 
                   7569:        <dd>
                   7570: 
                   7571:         <p>Append the literal string <code>&lt;!--</code> (U+003C
                   7572:         LESS-THAN SIGN, U+0021 EXCLAMATION MARK, U+002D HYPHEN-MINUS,
                   7573:         U+002D HYPHEN-MINUS), followed by the value of <var title="">current node</var>'s <code title="">data</code> DOM
                   7574:         attribute, followed by the literal string <code>--&gt;</code>
                   7575:         (U+002D HYPHEN-MINUS, U+002D HYPHEN-MINUS, U+003E GREATER-THAN
                   7576:         SIGN).</p>
                   7577: 
                   7578:        </dd>
                   7579: 
                   7580: 
                   7581:        <dt>If <var title="">current node</var> is a <code title="">ProcessingInstruction</code></dt>
                   7582: 
                   7583:        <dd>
                   7584: 
                   7585:         <p>Append the literal string <code>&lt;?</code> (U+003C
                   7586:         LESS-THAN SIGN, U+003F QUESTION MARK), followed by the value
                   7587:         of <var title="">current node</var>'s <code title="">target</code> DOM attribute, followed by a single
                   7588:         U+0020 SPACE character, followed by the value of <var title="">current node</var>'s <code title="">data</code> DOM
                   7589:         attribute, followed by a single U+003E GREATER-THAN SIGN
                   7590:         character ('&gt;').</p>
                   7591: 
                   7592:        </dd>
                   7593: 
                   7594: 
                   7595:        <dt>If <var title="">current node</var> is a <code title="">DocumentType</code></dt>
                   7596: 
                   7597:        <dd>
                   7598: 
                   7599:         <p>Append the literal string <code>&lt;!DOCTYPE</code> (U+003C
                   7600:         LESS-THAN SIGN, U+0021 EXCLAMATION MARK, U+0044 LATIN CAPITAL
                   7601:         LETTER D, U+004F LATIN CAPITAL LETTER O, U+0043 LATIN CAPITAL
                   7602:         LETTER C, U+0054 LATIN CAPITAL LETTER T, U+0059 LATIN CAPITAL
                   7603:         LETTER Y, U+0050 LATIN CAPITAL LETTER P, U+0045 LATIN CAPITAL
                   7604:         LETTER E), followed by a space (U+0020 SPACE), followed by the
                   7605:         value of <var title="">current node</var>'s <code title="">name</code> DOM attribute, followed by the literal
                   7606:         string <code>&gt;</code> (U+003E GREATER-THAN SIGN).</p>
                   7607: 
                   7608:        </dd>
                   7609: 
                   7610: 
                   7611:       </dl><p>Other node types (e.g. <code title="">Attr</code>) cannot
                   7612:       occur as children of elements. If, despite this, they somehow do
                   7613:       occur, this algorithm must raise an
                   7614:       <code><a href="infrastructure.html#invalid_state_err">INVALID_STATE_ERR</a></code> exception.</p>
                   7615: 
                   7616:      </li>
                   7617: 
                   7618:     </ol></li>
                   7619: 
                   7620:    <li><p>The result of the algorithm is the string <var title="">s</var>.</p></li>
                   7621: 
                   7622:   </ol><p><dfn id="escapingString">Escaping a string</dfn> (for the
                   7623:   purposes of the algorithm above) consists of replacing any
                   7624:   occurrences of the "<code title="">&amp;</code>" character by the
                   7625:   string "<code title="">&amp;amp;</code>", any occurrences of the
                   7626:   U+00A0 NO-BREAK SPACE character by the string "<code title="">&amp;nbsp;</code>", and, if the algorithm was invoked in
                   7627:   the <i>attribute mode</i>, any occurrences of the "<code title="">"</code>" character by the string "<code title="">&amp;quot;</code>", or if it was not, any occurrences of
                   7628:   the "<code title="">&lt;</code>" character by the string "<code title="">&amp;lt;</code>", any occurrences of the "<code title="">&gt;</code>" character by the string "<code title="">&amp;gt;</code>".</p>
                   7629: 
                   7630:   <p class="note">Entity reference nodes are <a href="infrastructure.html#entity-references">assumed to be expanded</a> by the user
                   7631:   agent, and are therefore not covered in the algorithm above.</p>
                   7632: 
                   7633:   <p class="note">It is possible that the output of this algorithm, if
                   7634:   parsed with an <a href="#html-parser">HTML parser</a>, will not return the
                   7635:   original tree structure. For instance, if a <code><a href="forms.html#the-textarea-element">textarea</a></code>
                   7636:   element to which a <code title="">Comment</code> node has been
                   7637:   appended is serialized and the output is then reparsed, the comment
                   7638:   will end up being displayed in the text field. Similarly, if, as a
                   7639:   result of DOM manipulation, an element contains a comment that
                   7640:   contains the literal string "<code title="">--&gt;</code>", then
                   7641:   when the result of serializing the element is parsed, the comment
                   7642:   will be truncated at that point and the rest of the comment will be
                   7643:   interpreted as markup. More examples would be making a
                   7644:   <code><a href="semantics.html#script">script</a></code> element contain a text node with the text string
                   7645:   "<code>&lt;/script&gt;</code>", or having a <code><a href="semantics.html#the-p-element">p</a></code> element that
                   7646:   contains a <code><a href="semantics.html#the-ul-element">ul</a></code> element (as the <code><a href="semantics.html#the-ul-element">ul</a></code> element's
                   7647:   <a href="#syntax-start-tag" title="syntax-start-tag">start tag</a> would imply the end
                   7648:   tag for the <code><a href="semantics.html#the-p-element">p</a></code>).</p>
                   7649: 
                   7650: 
                   7651:   <h3 id="parsing-html-fragments"><span class="secno">9.5 </span>Parsing HTML fragments</h3>
                   7652: 
                   7653:   <p>The following steps form the <dfn id="html-fragment-parsing-algorithm">HTML fragment parsing
                   7654:   algorithm</dfn>. The algorithm optionally takes as input an
                   7655:   <code>Element</code> node, referred to as the <var title="">context</var> element, which gives the context for the
                   7656:   parser, as well as <var title="">input</var>, a string to parse, and
                   7657:   returns a list of zero or more nodes.</p>
                   7658: 
                   7659:   <p class="note">Parts marked <dfn id="fragment-case">fragment case</dfn> in algorithms
                   7660:   in the parser section are parts that only occur if the parser was
                   7661:   created for the purposes of this algorithm (and with a <var title="">context</var> element). The algorithms have been annotated
                   7662:   with such markings for informational purposes only; such markings
                   7663:   have no normative weight. If it is possible for a condition
                   7664:   described as a <a href="#fragment-case">fragment case</a> to occur even when the
                   7665:   parser wasn't created for the purposes of handling this algorithm,
                   7666:   then that is an error in the specification.</p>
                   7667: 
                   7668:   <ol><li>
                   7669: 
                   7670:     <p>Create a new <code>Document</code> node, and mark it as being
                   7671:     an <a href="dom.html#html-documents" title="HTML documents">HTML document</a>.</p>
                   7672: 
                   7673:    </li>
                   7674: 
                   7675:    <li>
                   7676: 
                   7677:     <p>If there is a <var title="">context</var> element, and the
                   7678:     <code>Document</code> of the <var title="">context</var> element
                   7679:     is in <a href="dom.html#quirks-mode">quirks mode</a>, then let the <code>Document</code>
                   7680:     be in <a href="dom.html#quirks-mode">quirks mode</a>. Otherwise, if there is a <var title="">context</var> element, and the <code>Document</code> of
                   7681:     the <var title="">context</var> element is in <a href="dom.html#limited-quirks-mode">limited quirks
                   7682:     mode</a>, then let the <code>Document</code> be in
                   7683:     <a href="dom.html#limited-quirks-mode">limited quirks mode</a>. Otherwise, leave the
                   7684:     <code>Document</code> in <a href="dom.html#no-quirks-mode">no quirks mode</a>.</p>
                   7685: 
                   7686:    </li>
                   7687: 
                   7688:    <li>
                   7689: 
                   7690:     <p>Create a new <a href="#html-parser">HTML parser</a>, and associate it with
                   7691:     the just created <code>Document</code> node.</p>
                   7692: 
                   7693:    </li>
                   7694: 
                   7695:    <li>
                   7696: 
                   7697:     <p>If there is a <var title="">context</var> element, run these
                   7698:     substeps:</p>
                   7699: 
                   7700:     <ol><li>
                   7701: 
                   7702:       <p>Set the <a href="#html-parser">HTML parser</a>'s <a href="#tokenization">tokenization</a>
                   7703:       stage's <a href="#content-model-flag">content model flag</a> according to the <var title="">context</var> element, as follows:</p>
                   7704: 
                   7705:       <dl class="switch"><dt>If it is a <code><a href="semantics.html#the-title-element">title</a></code> or <code><a href="forms.html#the-textarea-element">textarea</a></code>
                   7706:        element</dt>
                   7707: 
                   7708:        <dd>Set the <a href="#content-model-flag">content model flag</a> to
                   7709:        the RCDATA state.</dd>
                   7710: 
                   7711: 
                   7712:        <dt>If it is a <code><a href="semantics.html#the-style-element">style</a></code>, <code><a href="semantics.html#script">script</a></code>,
1.42      mike     7713:        <code><a href="obsolete.html#xmp">xmp</a></code>, <code><a href="embedded-content-0.html#the-iframe-element">iframe</a></code>, <code><a href="obsolete.html#noembed">noembed</a></code>, or
1.5       mike     7714:        <code><a href="obsolete.html#noframes">noframes</a></code> element</dt>
1.1       mike     7715: 
                   7716:        <dd>Set the <a href="#content-model-flag">content model flag</a> to
1.91      mike     7717:        the RAWTEXT state.</dd>
1.1       mike     7718: 
                   7719: 
                   7720:        <dt>If it is a <code><a href="semantics.html#the-noscript-element">noscript</a></code> element</dt>
                   7721: 
                   7722:        <dd>If the <a href="#scripting-flag">scripting flag</a> is enabled, set the
1.91      mike     7723:        <a href="#content-model-flag">content model flag</a> to the RAWTEXT
1.1       mike     7724:        state. Otherwise, set the <a href="#content-model-flag">content model flag</a> to the
                   7725:        PCDATA state.</dd>
                   7726: 
                   7727: 
1.42      mike     7728:        <dt>If it is a <code><a href="obsolete.html#plaintext">plaintext</a></code> element</dt>
1.1       mike     7729: 
                   7730:        <dd>Set the <a href="#content-model-flag">content model flag</a> to
                   7731:        PLAINTEXT.</dd>
                   7732: 
                   7733: 
                   7734:        <dt>Otherwise</dt>
                   7735: 
                   7736:        <dd>Leave the <a href="#content-model-flag">content model flag</a> in the PCDATA
                   7737:        state.</dd>
                   7738: 
                   7739:       </dl></li>
                   7740: 
                   7741:      <li>
                   7742: 
                   7743:       <p>Let <var title="">root</var> be a new <code><a href="semantics.html#the-html-element">html</a></code> element
                   7744:       with no attributes.</p>
                   7745: 
                   7746:      </li>
                   7747: 
                   7748:      <li>
                   7749: 
                   7750:       <p>Append the element <var title="">root</var> to the
                   7751:       <code>Document</code> node created above.</p>
                   7752: 
                   7753:      </li>
                   7754: 
                   7755:      <li>
                   7756: 
                   7757:       <p>Set up the parser's <a href="#stack-of-open-elements">stack of open elements</a> so that
                   7758:       it contains just the single element <var title="">root</var>.</p>
                   7759: 
                   7760:      </li>
                   7761: 
                   7762:      <li>
                   7763: 
                   7764:       <p><a href="#reset-the-insertion-mode-appropriately" title="reset the insertion mode appropriately">Reset the
                   7765:       parser's insertion mode appropriately</a>.</p>
                   7766: 
                   7767:       <p class="note">The parser will reference the <var title="">context</var> element as part of that algorithm.</p>
                   7768: 
                   7769:      </li>
                   7770: 
                   7771:      <li>
                   7772: 
                   7773:       <p>Set the parser's <a href="#form-element-pointer"><code>form</code> element pointer</a>
                   7774:       to the nearest node to the <var title="">context</var> element
                   7775:       that is a <code><a href="forms.html#the-form-element">form</a></code> element (going straight up the
                   7776:       ancestor chain, and including the element itself, if it is a
                   7777:       <code><a href="forms.html#the-form-element">form</a></code> element), or, if there is no such
                   7778:       <code><a href="forms.html#the-form-element">form</a></code> element, to null.</p>
                   7779: 
                   7780:      </li>
                   7781: 
                   7782:     </ol></li>
                   7783: 
                   7784:    <li>
                   7785: 
                   7786:     <p>Place into the <a href="#the-input-stream">input stream</a> for the <a href="#html-parser">HTML
                   7787:     parser</a> just created the <var title="">input</var>. The
                   7788:     encoding <a href="#concept-encoding-confidence" title="concept-encoding-confidence">confidence</a> is
                   7789:     <i>irrelevant</i>.</p>
                   7790: 
                   7791:    </li>
                   7792: 
                   7793:    <li>
                   7794: 
                   7795:     <p>Start the parser and let it run until it has consumed all the
                   7796:     characters just inserted into the input stream.</p>
                   7797: 
                   7798:    </li>
                   7799: 
                   7800:    <li>
                   7801: 
                   7802:     <p>If there is a <var title="">context</var> element, return the
                   7803:     child nodes of <var title="">root</var>, in <a href="infrastructure.html#tree-order">tree
                   7804:     order</a>.</p>
                   7805: 
                   7806:     <p>Otherwise, return the children of the <code>Document</code>
                   7807:     object, in <a href="infrastructure.html#tree-order">tree order</a>.</p>
                   7808: 
                   7809:    </li>
                   7810: 
1.97      mike     7811:   </ol></div>
                   7812: 
                   7813: 
                   7814: 
                   7815:   </body></html>

Webmaster