index.html
changeset 67 8188d1e767f6
parent 66 8dbd8dbdefdc
child 69 4cdaaec40df7
equal deleted inserted replaced
66:8dbd8dbdefdc 67:8188d1e767f6
    78     <script type="text/javascript" src="respecConfig.js" class='remove'></script>
    78     <script type="text/javascript" src="respecConfig.js" class='remove'></script>
    79 </head>
    79 </head>
    80 <body>
    80 <body>
    81 
    81 
    82     <section id="abstract">
    82     <section id="abstract">
    83        <p>This specification defines various APIs for programmatic access to 
    83        <p>This specification defines various APIs for programmatic access to
    84           HTML and generic XML parsers by web applications for use in parsing 
    84           HTML and generic XML parsers by web applications for use in parsing
    85           and serializing DOM nodes.</p>
    85           and serializing DOM nodes.</p>
    86     </section>
    86     </section>
    87 
    87 
    88     <section id="sotd">
    88     <section id="sotd">
    89         <p>This specification is based on the original work of the <a href="http://domparsing.spec.whatwg.org/">
    89         <p>This specification is based on the original work of the <a href="http://domparsing.spec.whatwg.org/">
    90             DOM Parsing and Serialization</a> Living Specification, though it has diverged in terms of 
    90             DOM Parsing and Serialization</a> Living Specification, though it has diverged in terms of
    91             supported features, normative requirements, and algorithm specificity. As appropriate, 
    91             supported features, normative requirements, and algorithm specificity. As appropriate,
    92             relevant fixes from the living specification are incorporated into this document. 
    92             relevant fixes from the living specification are incorporated into this document.
    93     </section>
    93     </section>
    94 
    94 
    95 
    95 
    96     <section id="issues" class="introductory">
    96     <section id="issues" class="introductory">
    97         <h1>Issues</h1>
    97         <h1>Issues</h1>
    98         
    98 
    99         <p class=issue>Open issues that appear throughout the remainder of this 
    99         <p class=issue>Open issues that appear throughout the remainder of this
   100         document will be highlighted like this.</p>
   100         document will be highlighted like this.</p>
   101     </section>
   101     </section>
   102 
   102 
   103     <section id="conformance">
   103     <section id="conformance">
   104         <p>Requirements phrased in the imperative as part of algorithms
   104         <p>Requirements phrased in the imperative as part of algorithms
   116         <p id="hardwareLimitations">User agents may impose
   116         <p id="hardwareLimitations">User agents may impose
   117         implementation-specific limits on otherwise unconstrained inputs,
   117         implementation-specific limits on otherwise unconstrained inputs,
   118         e.g. to prevent denial of service attacks, to guard against running
   118         e.g. to prevent denial of service attacks, to guard against running
   119         out of memory, or to work around platform-specific limitations.</p>
   119         out of memory, or to work around platform-specific limitations.</p>
   120 
   120 
   121         <p>When a method or an attribute is said to call another method or 
   121         <p>When a method or an attribute is said to call another method or
   122         attribute, the user agent must invoke its internal API for that 
   122         attribute, the user agent must invoke its internal API for that
   123         attribute or method so that e.g. the author can't change the behavior 
   123         attribute or method so that e.g. the author can't change the behavior
   124         by overriding attributes or methods with custom properties or functions 
   124         by overriding attributes or methods with custom properties or functions
   125         in ECMAScript.</p>
   125         in ECMAScript.</p>
   126 
   126 
   127         <p>Unless otherwise stated, string comparisons are done in a <a
   127         <p>Unless otherwise stated, string comparisons are done in a <a
   128         data-spec="DOM4" class="externalDFN" title="case-sensitive">
   128         data-spec="DOM4" class="externalDFN" title="case-sensitive">
   129         case-sensitive</a> manner.</p>
   129         case-sensitive</a> manner.</p>
   130 
   130 
   131         <p>If an algorithm calls into another algorithm, any exception that is 
   131         <p>If an algorithm calls into another algorithm, any exception that is
   132         thrown by the latter (unless it is explicitly caught), must cause the 
   132         thrown by the latter (unless it is explicitly caught), must cause the
   133         former to terminate, and the exception to be propagated up to 
   133         former to terminate, and the exception to be propagated up to
   134         <em>its</em> caller.</p>
   134         <em>its</em> caller.</p>
   135     
   135 
   136         <section>
   136         <section>
   137             <h2>Dependencies</h2>
   137             <h2>Dependencies</h2>
   138 
   138 
   139             <p>The IDL fragments in this specification must be interpreted as
   139             <p>The IDL fragments in this specification must be interpreted as
   140             required for conforming IDL fragments, as described in the Web IDL
   140             required for conforming IDL fragments, as described in the Web IDL
   179         attribute being discussed was called.
   179         attribute being discussed was called.
   180     </section>
   180     </section>
   181 
   181 
   182     <section>
   182     <section>
   183         <h2>Namespaces</h2>
   183         <h2>Namespaces</h2>
   184         
   184 
   185         <p>The <dfn title="html-ns">HTML namespace</dfn> is <code>http://www.w3.org/1999/xhtml</code>.
   185         <p>The <dfn title="html-ns">HTML namespace</dfn> is <code>http://www.w3.org/1999/xhtml</code>.
   186         <p>The <dfn title="xml-ns">XML namespace</dfn> is <code>http://www.w3.org/XML/1998/namespace</code>.
   186         <p>The <dfn title="xml-ns">XML namespace</dfn> is <code>http://www.w3.org/XML/1998/namespace</code>.
   187         <p>The <dfn title="xmlns-ns">XMLNS namespace</dfn> is <code>http://www.w3.org/2000/xmlns/</code>.
   187         <p>The <dfn title="xmlns-ns">XMLNS namespace</dfn> is <code>http://www.w3.org/2000/xmlns/</code>.
   188     </section>
   188     </section>
   189 
   189 
   202               <li>
   202               <li>
   203                 <p>If the <var>context element</var>'s
   203                 <p>If the <var>context element</var>'s
   204                 <a title="concept-node-document" data-spec="DOM4" class="externalDFN">node document</a>
   204                 <a title="concept-node-document" data-spec="DOM4" class="externalDFN">node document</a>
   205                 is an <a title="html-document" data-spec="DOM4" class="externalDFN">HTML document</a>: let
   205                 is an <a title="html-document" data-spec="DOM4" class="externalDFN">HTML document</a>: let
   206                 <var>algorithm</var> be the
   206                 <var>algorithm</var> be the
   207                 <a title="html-fragment-parsing-algorithm" data-spec="HTML5" class="externalDFN">HTML 
   207                 <a title="html-fragment-parsing-algorithm" data-spec="HTML5" class="externalDFN">HTML
   208                 fragment parsing algorithm</a>.</p>
   208                 fragment parsing algorithm</a>.</p>
   209 
   209 
   210                 <p>If the <var>context element</var>'s
   210                 <p>If the <var>context element</var>'s
   211                 <a title="concept-node-document" data-spec="DOM4" class="externalDFN">node document</a>
   211                 <a title="concept-node-document" data-spec="DOM4" class="externalDFN">node document</a>
   212                 is an <a title="xml-document" data-spec="DOM4" class="externalDFN">XML document</a>: let
   212                 is an <a title="xml-document" data-spec="DOM4" class="externalDFN">XML document</a>: let
   213                 <var>algorithm</var> be the
   213                 <var>algorithm</var> be the
   214                 <a title="xml-fragment-parsing-algorithm" data-spec="HTML5" class="externalDFN">XML 
   214                 <a title="xml-fragment-parsing-algorithm" data-spec="HTML5" class="externalDFN">XML
   215                 fragment parsing algorithm</a>.</p>
   215                 fragment parsing algorithm</a>.</p>
   216               </li>
   216               </li>
   217 
   217 
   218               <li>Let <var>new children</var> be the result of invoking <var>algorithm</var> with <var>markup</var> as
   218               <li>Let <var>new children</var> be the result of invoking <var>algorithm</var> with <var>markup</var> as
   219               the <var>input</var>, and <var>context element</var> as the
   219               the <var>input</var>, and <var>context element</var> as the
   226               is <var>context element</var>'s
   226               is <var>context element</var>'s
   227               <a title="concept-node-document" data-spec="DOM4" class="externalDFN">node document</a>.
   227               <a title="concept-node-document" data-spec="DOM4" class="externalDFN">node document</a>.
   228 
   228 
   229               <li><a data-spec="DOM4" title="concept-node-append" class="externalDFN">Append</a>
   229               <li><a data-spec="DOM4" title="concept-node-append" class="externalDFN">Append</a>
   230               each <a data-spec="DOM4" title="concept-node" class="externalDFN">node</a> in
   230               each <a data-spec="DOM4" title="concept-node" class="externalDFN">node</a> in
   231               <var>new children</var> to <var>fragment</var> 
   231               <var>new children</var> to <var>fragment</var>
   232               (in <a data-spec="DOM4" title="concept-tree-order" class="externalDFN">tree order</a>).
   232               (in <a data-spec="DOM4" title="concept-tree-order" class="externalDFN">tree order</a>).
   233 
   233 
   234               <p class=note>This ensures the
   234               <p class=note>This ensures the
   235               <a title="concept-node-document" data-spec="DOM4" class="externalDFN">node document</a>
   235               <a title="concept-node-document" data-spec="DOM4" class="externalDFN">node document</a>
   236               for the new <a data-spec="DOM4" title="concept-node" class="externalDFN">nodes</a> is correct.
   236               for the new <a data-spec="DOM4" title="concept-node" class="externalDFN">nodes</a> is correct.
   239             </ol>
   239             </ol>
   240     </section>
   240     </section>
   241 
   241 
   242     <section>
   242     <section>
   243         <h2>Serializing</h2>
   243         <h2>Serializing</h2>
   244         <p>The following steps form the 
   244         <p>The following steps form the
   245             <dfn title="concept-fragment-serializing-algorithm">fragment serializing algorithm</dfn>,
   245             <dfn title="concept-fragment-serializing-algorithm">fragment serializing algorithm</dfn>,
   246             whose arguments are a <code><a title="node" data-spec="DOM4" class="externalDFN">Node</a></code> 
   246             whose arguments are a <code><a title="node" data-spec="DOM4" class="externalDFN">Node</a></code>
   247             <var>node</var> and a flag <dfn title="concept-well-formed">require well-formed</dfn>:
   247             <var>node</var> and a flag <dfn title="concept-well-formed">require well-formed</dfn>:
   248 
   248 
   249         <ol>
   249         <ol>
   250             <li>Let <var>context document</var> be the value of <var>node</var>'s
   250             <li>Let <var>context document</var> be the value of <var>node</var>'s
   251                 <a title="concept-node-document" data-spec="DOM4" class="externalDFN">node document</a>.
   251                 <a title="concept-node-document" data-spec="DOM4" class="externalDFN">node document</a>.
   252             <li>If <var>context document</var> is an
   252             <li>If <var>context document</var> is an
   253                 <a title="html-document" data-spec="DOM4" class="externalDFN">HTML document</a>, 
   253                 <a title="html-document" data-spec="DOM4" class="externalDFN">HTML document</a>,
   254                 return an <a title="concept-serialize-html">HTML serialization</a> of <var>node</var>.
   254                 return an <a title="concept-serialize-html">HTML serialization</a> of <var>node</var>.
   255             <li>Otherwise, <var>context document</var> is an
   255             <li>Otherwise, <var>context document</var> is an
   256                 <a title="xml-document" data-spec="DOM4" class="externalDFN">XML document</a>;
   256                 <a title="xml-document" data-spec="DOM4" class="externalDFN">XML document</a>;
   257                 return an <a title="concept-serialize-xml">XML serialization</a> of <var>node</var>
   257                 return an <a title="concept-serialize-xml">XML serialization</a> of <var>node</var>
   258                 passing the flag <var>require well-formed</var>.
   258                 passing the flag <var>require well-formed</var>.
   259             <p class="note">The <a title="concept-serialize-xml">XML serialization</a> defined in this document
   259             <p class="note">The <a title="concept-serialize-xml">XML serialization</a> defined in this document
   260                 conforms to the requirements of the <a data-spec="HTML5" title="xml-fragment-serialization-algorithm" 
   260                 conforms to the requirements of the <a data-spec="HTML5" title="xml-fragment-serialization-algorithm"
   261                 class="externalDFN">XML fragment serialization algorithm</a> defined in [[HTML5]].</p>
   261                 class="externalDFN">XML fragment serialization algorithm</a> defined in [[HTML5]].</p>
   262         </ol>
   262         </ol>
   263 
   263 
   264         <p>To produce an <dfn title="concept-serialize-html">HTML serialization</dfn> of a
   264         <p>To produce an <dfn title="concept-serialize-html">HTML serialization</dfn> of a
   265             <code><a title="node" data-spec="DOM4" class="externalDFN">Node</a></code> <var>node</var>, the user agent
   265             <code><a title="node" data-spec="DOM4" class="externalDFN">Node</a></code> <var>node</var>, the user agent
   266             must run the
   266             must run the
   267             <a data-spec="HTML5" title="html-fragment-serialization-algorithm" class="externalDFN">HTML 
   267             <a data-spec="HTML5" title="html-fragment-serialization-algorithm" class="externalDFN">HTML
   268             fragment serialization algorithm</a> [[!HTML5]] on <var>node</var> and return the string produced.
   268             fragment serialization algorithm</a> [[!HTML5]] on <var>node</var> and return the string produced.
   269 
   269 
   270         <p>To produce an <dfn title="concept-serialize-xml">XML serialization</dfn> of a
   270         <p>To produce an <dfn title="concept-serialize-xml">XML serialization</dfn> of a
   271             <code><a title="node" data-spec="DOM4" class="externalDFN">Node</a></code> <var>node</var> given a
   271             <code><a title="node" data-spec="DOM4" class="externalDFN">Node</a></code> <var>node</var> given a
   272             flag <var>require well-formed</var>, run the following steps:
   272             flag <var>require well-formed</var>, run the following steps:
   273         <ol>
   273         <ol>
   274             <li>Let <dfn title="concept-context-namespace">context namespace</dfn> be <code>null</code>.
   274             <li>Let <dfn title="concept-context-namespace">context namespace</dfn> be <code>null</code>.
   275                 The <a title="concept-context-namespace">context namespace</a> is changed when a
   275                 The <a title="concept-context-namespace">context namespace</a> is changed when a
   276                 <var>node</var> serializes a different default namespace definition from its parent. The 
   276                 <var>node</var> serializes a different default namespace definition from its parent. The
   277                 algorithm assumes no namespace to start.
   277                 algorithm assumes no namespace to start.
   278             <li>Let <dfn title="concept-namespace-prefix-map">namespace prefix map</dfn> be a new map 
   278             <li>Let <dfn title="concept-namespace-prefix-map">namespace prefix map</dfn> be a new map
   279                 for associating <code>namespaceURI</code> and namespace <code>prefix</code> pairs, where 
   279                 for associating <code>namespaceURI</code> and namespace <code>prefix</code> pairs, where
   280                 <code>namespaceURI</code> values are the map's keys, and <code>prefix</code> values are 
   280                 <code>namespaceURI</code> values are the map's keys, and <code>prefix</code> values are
   281                 the map's key values. The <a title="concept-namespace-prefix-map">namespace prefix map</a>
   281                 the map's key values. The <a title="concept-namespace-prefix-map">namespace prefix map</a>
   282                 will be populated by previously seen namespaceURIs and their most recent prefix associations
   282                 will be populated by previously seen namespaceURIs and their most recent prefix associations
   283                 for a subtree. <span class="note"><strong>Note:</strong> the 
   283                 for a subtree. <span class="note"><strong>Note:</strong> the
   284                 <a title="concept-namespace-prefix-map">namespace prefix map</a> only associates a single
   284                 <a title="concept-namespace-prefix-map">namespace prefix map</a> only associates a single
   285                 prefix value with a given namespaceURI. During serialization, if different namespace prefixes 
   285                 prefix value with a given namespaceURI. During serialization, if different namespace prefixes
   286                 are found that map to the same namespaceURI, the last one encountered "wins" by replacing the
   286                 are found that map to the same namespaceURI, the last one encountered "wins" by replacing the
   287                 existing key value in the map with the new prefix value.</span>
   287                 existing key value in the map with the new prefix value.</span>
   288             <li>Initialize the <a title="concept-namespace-prefix-map">namespace prefix map</a> with the 
   288             <li>Initialize the <a title="concept-namespace-prefix-map">namespace prefix map</a> with the
   289                 <a title="xml-ns">XML namespace</a> key and string "<code>xml</code>" as the key value.
   289                 <a title="xml-ns">XML namespace</a> key and string "<code>xml</code>" as the key value.
   290             <li>Let <dfn title="concept-generated-prefix">generated namespace prefix index</dfn> be an integer
   290             <li>Let <dfn title="concept-generated-prefix">generated namespace prefix index</dfn> be an integer
   291                 with a value of <code>1</code>. The <a title="concept-generated-prefix">generated namespace
   291                 with a value of <code>1</code>. The <a title="concept-generated-prefix">generated namespace
   292                 prefix index</a> is used to generate a new unique prefix value when no suitable existing 
   292                 prefix index</a> is used to generate a new unique prefix value when no suitable existing
   293                 namespace prefix is available to serialize a <var>node</var>'s namespaceURI (or the namespaceURI
   293                 namespace prefix is available to serialize a <var>node</var>'s namespaceURI (or the namespaceURI
   294                 of one of <var>node</var>'s attributes). <span class="note">See the 
   294                 of one of <var>node</var>'s attributes). <span class="note">See the
   295                 <a title="concept-generate-prefix">generate a prefix</a> algorithm.</span>
   295                 <a title="concept-generate-prefix">generate a prefix</a> algorithm.</span>
   296             <li>Return the result of running the <a title="concept-xml-serialization-algorithm">XML serialization
   296             <li>Return the result of running the <a title="concept-xml-serialization-algorithm">XML serialization
   297                 algorithm</a> on <var>node</var> passing the <a title="concept-context-namespace">context 
   297                 algorithm</a> on <var>node</var> passing the <a title="concept-context-namespace">context
   298                 namespace</a>, <a title="concept-namespace-prefix-map">namespace prefix map</a>, 
   298                 namespace</a>, <a title="concept-namespace-prefix-map">namespace prefix map</a>,
   299                 <a title="concept-generated-prefix">generated namespace prefix index</a> reference, and the
   299                 <a title="concept-generated-prefix">generated namespace prefix index</a> reference, and the
   300                 flag <var>require well-formed</var>. If an <dfn title="concept-algorithm-exception">exception</dfn>
   300                 flag <var>require well-formed</var>. If an <dfn title="concept-algorithm-exception">exception</dfn>
   301                 occurs during the execution of the algorithm, then catch that exception and throw a 
   301                 occurs during the execution of the algorithm, then catch that exception and throw a
   302                 <code><a data-spec="DOM4" title="domexception" class="externalDFN">DOMException</a></code> with 
   302                 <code><a data-spec="DOM4" title="domexception" class="externalDFN">DOMException</a></code> with
   303                 name "<code><a data-spec="DOM4" title="invalidstateerror" class="externalDFN">InvalidStateError</a></code>".
   303                 name "<code><a data-spec="DOM4" title="invalidstateerror" class="externalDFN">InvalidStateError</a></code>".
   304         </ol>
   304         </ol>
   305         
   305 
   306         <p>An <a title="concept-serialize-xml">XML serialization</a> differs from an 
   306         <p>An <a title="concept-serialize-xml">XML serialization</a> differs from an
   307             <a title="concept-serialize-html">HTML serialization</a> in the following ways:
   307             <a title="concept-serialize-html">HTML serialization</a> in the following ways:
   308         <ul>
   308         <ul>
   309             <li><a title="element" data-spec="DOM4" class="externalDFN">Elements</a> and
   309             <li><a title="element" data-spec="DOM4" class="externalDFN">Elements</a> and
   310                 <a title="concept-attribute" data-spec="DOM4" class="externalDFN">attributes</a>
   310                 <a title="concept-attribute" data-spec="DOM4" class="externalDFN">attributes</a>
   311                 will always be serialized such that their namespaceURI is preserved. In some cases 
   311                 will always be serialized such that their namespaceURI is preserved. In some cases
   312                 this means that an existing prefix, prefix declaration attribute or default namespace 
   312                 this means that an existing prefix, prefix declaration attribute or default namespace
   313                 declaration attribute might be dropped, substituted or changed.
   313                 declaration attribute might be dropped, substituted or changed.
   314                 An <a title="concept-serialize-html">HTML serialization</a> does not attempt to 
   314                 An <a title="concept-serialize-html">HTML serialization</a> does not attempt to
   315                 preserve the namespaceURI.
   315                 preserve the namespaceURI.
   316             <li><a title="element" data-spec="DOM4" class="externalDFN">Elements</a> not in the
   316             <li><a title="element" data-spec="DOM4" class="externalDFN">Elements</a> not in the
   317                 <a title="html-ns">HTML namespace</a> containing no <a title="concept-tree-child" 
   317                 <a title="html-ns">HTML namespace</a> containing no <a title="concept-tree-child"
   318                 data-spec="DOM4" class="externalDFN">children</a>, are serialized using 
   318                 data-spec="DOM4" class="externalDFN">children</a>, are serialized using
   319                 the self-closing tag syntax (i.e., according to the <code>EmptyElemTag</code> 
   319                 the self-closing tag syntax (i.e., according to the <code>EmptyElemTag</code>
   320                 production of [[XML10]]).
   320                 production of [[XML10]]).
   321         </ul>
   321         </ul>
   322         
   322 
   323         <p>Otherwise, the algorithm for producing an <a title="concept-serialize-xml">XML serialization</a> 
   323         <p>Otherwise, the algorithm for producing an <a title="concept-serialize-xml">XML serialization</a>
   324             is designed to produce a serialization that is compatible with the 
   324             is designed to produce a serialization that is compatible with the
   325             <a title="html-parser" data-spec="HTML5" class="externalDFN">HTML parser</a>. For example, 
   325             <a title="html-parser" data-spec="HTML5" class="externalDFN">HTML parser</a>. For example,
   326             elements in the <a title="html-ns">HTML namespace</a> that contain no child nodes are serialized 
   326             elements in the <a title="html-ns">HTML namespace</a> that contain no child nodes are serialized
   327             with an explicit begin and end tag rather than using the self-closing tag syntax [[XML10]].
   327             with an explicit begin and end tag rather than using the self-closing tag syntax [[XML10]].
   328         
   328 
   329         <p class="note">Per [[DOM4]], <code><a title="interface-attr" data-spec="DOM4" class="externalDFN">Attr</a></code>
   329         <p class="note">Per [[DOM4]], <code><a title="interface-attr" data-spec="DOM4" class="externalDFN">Attr</a></code>
   330             objects do not inherit from <code><a title="node" data-spec="DOM4" class="externalDFN">Node</a></code>, and thus cannot 
   330             objects do not inherit from <code><a title="node" data-spec="DOM4" class="externalDFN">Node</a></code>, and thus cannot
   331             be serialized by the <a title="concept-xml-serialization-algorithm">XML serialization algorithm</a>.
   331             be serialized by the <a title="concept-xml-serialization-algorithm">XML serialization algorithm</a>.
   332             An attempt to serialize an <code><a title="interface-attr" data-spec="DOM4" class="externalDFN">Attr</a></code>
   332             An attempt to serialize an <code><a title="interface-attr" data-spec="DOM4" class="externalDFN">Attr</a></code>
   333             object will result in a <code>TypeError</code> exception [[WEBIDL]].
   333             object will result in a <code>TypeError</code> exception [[WEBIDL]].
   334         
   334 
   335         <p>To run the <dfn title="concept-xml-serialization-algorithm">XML serialization algorithm</dfn> on
   335         <p>To run the <dfn title="concept-xml-serialization-algorithm">XML serialization algorithm</dfn> on
   336             a <var>node</var> given a <a title="concept-context-namespace">context namespace</a> 
   336             a <var>node</var> given a <a title="concept-context-namespace">context namespace</a>
   337             <var>namespace</var>, a <a title="concept-namespace-prefix-map">namespace prefix map</a>
   337             <var>namespace</var>, a <a title="concept-namespace-prefix-map">namespace prefix map</a>
   338             <var>prefix map</var>, a <a title="concept-generated-prefix">generated namespace prefix index</a>
   338             <var>prefix map</var>, a <a title="concept-generated-prefix">generated namespace prefix index</a>
   339             <var>prefix index</var>, and a flag <var>require well-formed</var>, the user agent must run the 
   339             <var>prefix index</var>, and a flag <var>require well-formed</var>, the user agent must run the
   340             appropriate steps, depending on <var>node</var>'s interface:</p>
   340             appropriate steps, depending on <var>node</var>'s interface:</p>
   341         
   341 
   342         <dl class=switch>
   342         <dl class=switch>
   343             <dt><code><a title="interface-element" data-spec="DOM4" class="externalDFN">Element</a></code>
   343             <dt><code><a title="interface-element" data-spec="DOM4" class="externalDFN">Element</a></code>
   344             <dd>
   344             <dd>
   345                 <p>Run the following algorithm:
   345                 <p>Run the following algorithm:
   346                 <ol>
   346                 <ol>
   347                     <!-- "namespace" was passed via the caller, it's the default namespace scope -->
   347                     <!-- "namespace" was passed via the caller, it's the default namespace scope -->
   348                     <!-- "prefix map" was passed via the caller, it's the namespace->prefix map -->
   348                     <!-- "prefix map" was passed via the caller, it's the namespace->prefix map -->
   349                     <!-- "prefix index" was passed via the caller, it's a number for generating prefixes if necessary -->
   349                     <!-- "prefix index" was passed via the caller, it's a number for generating prefixes if necessary -->
   350                     <!-- "require well-formed" was passed via the caller, it's a flag (true/false) for whether certain validation steps should be taken during serialization. -->
   350                     <!-- "require well-formed" was passed via the caller, it's a flag (true/false) for whether certain validation steps should be taken during serialization. -->
   351                     <li>If the <a title="concept-well-formed">require well-formed</a> flag is set (its value is 
   351                     <li>If the <a title="concept-well-formed">require well-formed</a> flag is set (its value is
   352                         <code>true</code>), and this <var>node</var>'s 
   352                         <code>true</code>), and this <var>node</var>'s
   353                         <code><a title="dom-element-localname" data-spec="DOM4" class="externalDFN">localName</a></code>
   353                         <code><a title="dom-element-localname" data-spec="DOM4" class="externalDFN">localName</a></code>
   354                         attribute contains the character "<code>:</code>" (U+003A COLON) or does not match the
   354                         attribute contains the character "<code>:</code>" (U+003A COLON) or does not match the
   355                         XML <code>Name</code> production [[XML10]], then <a title="concept-algorithm-exception">throw an 
   355                         XML <code>Name</code> production [[XML10]], then <a title="concept-algorithm-exception">throw an
   356                         exception</a>; the serialization of this <var>node</var> would not be a well-formed element.
   356                         exception</a>; the serialization of this <var>node</var> would not be a well-formed element.
   357                     <li>Let <var>markup</var> be the string "<code>&lt;</code>" (U+003C LESS-THAN SIGN).
   357                     <li>Let <var>markup</var> be the string "<code>&lt;</code>" (U+003C LESS-THAN SIGN).
   358                     <li>Let <var>qualified name</var> be an empty string.
   358                     <li>Let <var>qualified name</var> be an empty string.
   359                     <li>Let a <var>skip end tag</var> flag have the value <code>false</code>.
   359                     <li>Let a <var>skip end tag</var> flag have the value <code>false</code>.
   360                     <li>Let an <var>ignore namespace definition attribute</var> flag have the value <code>false</code>.
   360                     <li>Let an <var>ignore namespace definition attribute</var> flag have the value <code>false</code>.
   361                     <li>Let <var>map</var> be a copy of the <var>prefix map</var>.
   361                     <li>Let <var>map</var> be a copy of the <var>prefix map</var>.
   362                     <li>Let <var>element prefixes list</var> be an empty list. <span class="note">This list is 
   362                     <li>Let <var>element prefixes list</var> be an empty list. <span class="note">This list is
   363                         local to each element. Its purpose is to ensure that there are no conflicting prefixes 
   363                         local to each element. Its purpose is to ensure that there are no conflicting prefixes
   364                         should a new namespace prefix attribute need to be generated.</span>
   364                         should a new namespace prefix attribute need to be generated.</span>
   365                     <li>Let <var>duplicate prefix definition</var> be <code>null</code>.
   365                     <li>Let <var>duplicate prefix definition</var> be <code>null</code>.
   366                     <li>Let <var>local default namespace</var> be the result of 
   366                     <li>Let <var>local default namespace</var> be the result of
   367                         <a title="concept-record-namespace-info">recording the namespace information</a> for 
   367                         <a title="concept-record-namespace-info">recording the namespace information</a> for
   368                         <var>node</var> given <var>map</var>, <var>element prefixes list</var>, and 
   368                         <var>node</var> given <var>map</var>, <var>element prefixes list</var>, and
   369                         <var>duplicate prefix definition</var>.
   369                         <var>duplicate prefix definition</var>.
   370                     <p class="note">This above step will update the <var>map</var> with any found namespace prefix 
   370                     <p class="note">This above step will update the <var>map</var> with any found namespace prefix
   371                         definitions, add the found prefix definitions to the <var>element prefixes list</var>, optionally 
   371                         definitions, add the found prefix definitions to the <var>element prefixes list</var>, optionally
   372                         set the <var>duplicate prefix definition</var> value, and return a local default namespace 
   372                         set the <var>duplicate prefix definition</var> value, and return a local default namespace
   373                         value defined by a default namespace attribute if one exists. Otherwise it returns
   373                         value defined by a default namespace attribute if one exists. Otherwise it returns
   374                         <code>null</code>.</p>
   374                         <code>null</code>.</p>
   375                     <li>Let <var>inherited ns</var> be a copy of <var>namespace</var>.
   375                     <li>Let <var>inherited ns</var> be a copy of <var>namespace</var>.
   376                     <li>Let <var>ns</var> be the value of <var>node</var>'s 
   376                     <li>Let <var>ns</var> be the value of <var>node</var>'s
   377                         <code><a title="dom-element-namespaceuri" data-spec="DOM4" class="externalDFN">namespaceURI</a></code>
   377                         <code><a title="dom-element-namespaceuri" data-spec="DOM4" class="externalDFN">namespaceURI</a></code>
   378                         attribute.
   378                         attribute.
   379                     <li>If <var>inherited ns</var> is equal to <var>ns</var>, then:
   379                     <li>If <var>inherited ns</var> is equal to <var>ns</var>, then:
   380                     <ol>
   380                     <ol>
   381                         <li>If <var>local default namespace</var> is not <code>null</code>, then set <var>ignore 
   381                         <li>If <var>local default namespace</var> is not <code>null</code>, then set <var>ignore
   382                             namespace definition attribute</var> to <code>true</code>.
   382                             namespace definition attribute</var> to <code>true</code>.
   383                         <li>If <var>ns</var> is the <a title="xml-ns">XML namespace</a>, then let <var>qualified name</var> 
   383                         <li>If <var>ns</var> is the <a title="xml-ns">XML namespace</a>, then let <var>qualified name</var>
   384                             be the concatenation of the string "<code>xml:</code>" and the value of <var>node</var>'s 
   384                             be the concatenation of the string "<code>xml:</code>" and the value of <var>node</var>'s
   385                             <code><a title="dom-element-localname" data-spec="DOM4" class="externalDFN">localName</a></code>.
   385                             <code><a title="dom-element-localname" data-spec="DOM4" class="externalDFN">localName</a></code>.
   386                         <li>Otherwise, let <var>qualified name</var> be the value of <var>node</var>'s 
   386                         <li>Otherwise, let <var>qualified name</var> be the value of <var>node</var>'s
   387                             <code><a title="dom-element-localname" data-spec="DOM4" class="externalDFN">localName</a></code>.
   387                             <code><a title="dom-element-localname" data-spec="DOM4" class="externalDFN">localName</a></code>.
   388                             <span class="note">The <var>node</var>'s prefix is always dropped.</span>
   388                             <span class="note">The <var>node</var>'s prefix is always dropped.</span>
   389                         <li>Append the value of <var>qualified name</var> to <var>markup</var>.
   389                         <li>Append the value of <var>qualified name</var> to <var>markup</var>.
   390                     </ol>
   390                     </ol>
   391                     <li>Otherwise, <var>inherited ns</var> is not equal to <var>ns</var> (the <var>node</var>'s
   391                     <li>Otherwise, <var>inherited ns</var> is not equal to <var>ns</var> (the <var>node</var>'s
   392                         own namespace is different from the context namespace of its parent). Run these sub-steps:
   392                         own namespace is different from the context namespace of its parent). Run these sub-steps:
   393                     <!-- The serialization algorithm must differentiate this node's namespace from it's parent's default
   393                     <!-- The serialization algorithm must differentiate this node's namespace from it's parent's default
   394                         namespace. There are two ways to do this: (1) [preferred due to assumed minimum length] use a 
   394                         namespace. There are two ways to do this: (1) [preferred due to assumed minimum length] use a
   395                         namespace prefix if one is available or (2) use a default namespace declaration. Both cases can 
   395                         namespace prefix if one is available or (2) use a default namespace declaration. Both cases can
   396                         run into conflicts with existing attributes on the element and are handled accordingly. -->
   396                         run into conflicts with existing attributes on the element and are handled accordingly. -->
   397                     <ol>
   397                     <ol>
   398                         <li>Let <var>prefix</var> be the value of <var>node</var>'s 
   398                         <li>Let <var>prefix</var> be the value of <var>node</var>'s
   399                             <code><a title="dom-element-prefix" data-spec="DOM4" class="externalDFN">prefix</a></code>
   399                             <code><a title="dom-element-prefix" data-spec="DOM4" class="externalDFN">prefix</a></code>
   400                             attribute.
   400                             attribute.
   401                         <li>Let <var>candidate prefix</var> be a value from <var>map</var> where there exists a key in 
   401                         <li>Let <var>candidate prefix</var> be a value from <var>map</var> where there exists a key in
   402                             <var>map</var> that matches the value of <var>ns</var> or if there is no such key, then let
   402                             <var>map</var> that matches the value of <var>ns</var> or if there is no such key, then let
   403                             <var>candidate prefix</var> be <code>null</code>.
   403                             <var>candidate prefix</var> be <code>null</code>.
   404                         <!-- Found a suitable prefix to use, either locally, or inherited through a parent node that 
   404                         <!-- Found a suitable prefix to use, either locally, or inherited through a parent node that
   405                             matches the node's namespaceURI. This prefix will be used in serialization even if the node 
   405                             matches the node's namespaceURI. This prefix will be used in serialization even if the node
   406                             doesn't have a real prefix. -->
   406                             doesn't have a real prefix. -->
   407                         <li>If <var>candidate prefix</var> is not <code>null</code> (a suitable namespace prefix is defined 
   407                         <li>If <var>candidate prefix</var> is not <code>null</code> (a suitable namespace prefix is defined
   408                             which maps to <var>ns</var>), then:
   408                             which maps to <var>ns</var>), then:
   409                         <ol>
   409                         <ol>
   410                             <li>Let <var>qualified name</var> be the concatenation of <var>candidate prefix</var>, 
   410                             <li>Let <var>qualified name</var> be the concatenation of <var>candidate prefix</var>,
   411                                 "<code>:</code>" (U+003A COLON), and <var>node</var>'s <code>
   411                                 "<code>:</code>" (U+003A COLON), and <var>node</var>'s <code>
   412                                 <a title="dom-element-localname" data-spec="DOM4" class="externalDFN">localName</a></code>.
   412                                 <a title="dom-element-localname" data-spec="DOM4" class="externalDFN">localName</a></code>.
   413                                 <span class="note">There exists on this <var>node</var> or the <var>node</var>'s ancestry a 
   413                                 <span class="note">There exists on this <var>node</var> or the <var>node</var>'s ancestry a
   414                                 namespace prefix definition that defines the <var>node</var>'s namespace.</span>
   414                                 namespace prefix definition that defines the <var>node</var>'s namespace.</span>
   415                             <li>If <var>local default namespace</var> is not <code>null</code> (there exists a locally-defined
   415                             <li>If <var>local default namespace</var> is not <code>null</code> (there exists a locally-defined
   416                                 default namespace declaration attribute), then let <var>inherited ns</var> get the value of
   416                                 default namespace declaration attribute), then let <var>inherited ns</var> get the value of
   417                                 <var>ns</var>.
   417                                 <var>ns</var>.
   418                             <li>Append the value of <var>qualified name</var> to <var>markup</var>.
   418                             <li>Append the value of <var>qualified name</var> to <var>markup</var>.
   419                         </ol>
   419                         </ol>
   420                         <!-- Now there's no existing namespace->prefix mapping to override; try to use a prefix: -->
   420                         <!-- Now there's no existing namespace->prefix mapping to override; try to use a prefix: -->
   421                         <li>Otherwise, if <var>prefix</var> is not <code>null</code> and <var>local default namespace</var> is 
   421                         <li>Otherwise, if <var>prefix</var> is not <code>null</code> and <var>local default namespace</var> is
   422                             <code>null</code>, then:
   422                             <code>null</code>, then:
   423                         <ol>
   423                         <ol>
   424                             <li>If the <var>element prefixes list</var> contains the value of <var>prefix</var>, then 
   424                             <li>If the <var>element prefixes list</var> contains the value of <var>prefix</var>, then
   425                                 let <var>prefix</var> be the result of 
   425                                 let <var>prefix</var> be the result of
   426                                 <a title="concept-generate-prefix">generating a prefix</a> providing as input the
   426                                 <a title="concept-generate-prefix">generating a prefix</a> providing as input the
   427                                 <a title="concept-namespace-prefix-map">namespace prefix map</a> <var>map</var>, 
   427                                 <a title="concept-namespace-prefix-map">namespace prefix map</a> <var>map</var>,
   428                                 <var>node</var>'s <var>ns</var> string, and the <var>prefix index</var> integer.
   428                                 <var>node</var>'s <var>ns</var> string, and the <var>prefix index</var> integer.
   429                             <li>Otherwise, append to <var>map</var> a new key <var>ns</var> whose key value is 
   429                             <li>Otherwise, append to <var>map</var> a new key <var>ns</var> whose key value is
   430                                 <var>prefix</var>.
   430                                 <var>prefix</var>.
   431                             <!-- Prefix is now either real or generated, and added to the map. -->
   431                             <!-- Prefix is now either real or generated, and added to the map. -->
   432                             <li>Let <var>qualified name</var> be the concatenation
   432                             <li>Let <var>qualified name</var> be the concatenation
   433                             of <var>prefix</var>, "<code>:</code>" (U+003A COLON), and <var>node</var>'s
   433                             of <var>prefix</var>, "<code>:</code>" (U+003A COLON), and <var>node</var>'s
   434                             <code><a title="dom-element-localname" data-spec="DOM4" class="externalDFN">localName</a></code>.
   434                             <code><a title="dom-element-localname" data-spec="DOM4" class="externalDFN">localName</a></code>.
   435                             <li>Append the value of <var>qualified name</var> to <var>markup</var>.
   435                             <li>Append the value of <var>qualified name</var> to <var>markup</var>.
   436                             <li>Append the following to <var>markup</var>, in the order listed: <span class="note">The following 
   436                             <li>Append the following to <var>markup</var>, in the order listed: <span class="note">The following
   437                                 serializes the new namespace/prefix association just added to the <var>map</var>.</span>
   437                                 serializes the new namespace/prefix association just added to the <var>map</var>.</span>
   438                             <ol>
   438                             <ol>
   439                                 <li>"<code> </code>" (U+0020 SPACE);
   439                                 <li>"<code> </code>" (U+0020 SPACE);
   440                                 <li>The string "<code>xmlns:</code>";
   440                                 <li>The string "<code>xmlns:</code>";
   441                                 <li>The value of <var>prefix</var>;
   441                                 <li>The value of <var>prefix</var>;
   442                                 <li>"<code>="</code>" (U+003D EQUALS SIGN, U+0022 QUOTATION MARK);
   442                                 <li>"<code>="</code>" (U+003D EQUALS SIGN, U+0022 QUOTATION MARK);
   443                                 <li>The result of <a title="concept-serialize-attr-value">serializing an attribute value</a> 
   443                                 <li>The result of <a title="concept-serialize-attr-value">serializing an attribute value</a>
   444                                     given <var>ns</var> and the <a title="concept-well-formed">require well-formed</a> flag 
   444                                     given <var>ns</var> and the <a title="concept-well-formed">require well-formed</a> flag
   445                                     as input;
   445                                     as input;
   446                                 <li>"<code>"</code>" (U+0022 QUOTATION MARK).
   446                                 <li>"<code>"</code>" (U+0022 QUOTATION MARK).
   447                             </ol>
   447                             </ol>
   448                         </ol>
   448                         </ol>
   449                         <!-- Giving up on the prefix route, try to use a default namespace instead (stomping on an existing
   449                         <!-- Giving up on the prefix route, try to use a default namespace instead (stomping on an existing
   450                              one if necessary) and dropping the node's prefix -->
   450                              one if necessary) and dropping the node's prefix -->
   451                         <li>Otherwise, if <var>local default namespace</var> is <code>null</code>, or <var>local default 
   451                         <li>Otherwise, if <var>local default namespace</var> is <code>null</code>, or <var>local default
   452                             namespace</var> is not <code>null</code> and its value is not equal to <var>ns</var>, then:
   452                             namespace</var> is not <code>null</code> and its value is not equal to <var>ns</var>, then:
   453                         <ol>
   453                         <ol>
   454                             <li>Set the <var>ignore namespace definition attribute</var> flag to <code>true</code>.
   454                             <li>Set the <var>ignore namespace definition attribute</var> flag to <code>true</code>.
   455                             <li>Let <var>qualified name</var> be the value of <var>node</var>'s <code><a title="dom-element-localname" 
   455                             <li>Let <var>qualified name</var> be the value of <var>node</var>'s <code><a title="dom-element-localname"
   456                                 data-spec="DOM4" class="externalDFN">localName</a></code>.
   456                                 data-spec="DOM4" class="externalDFN">localName</a></code>.
   457                             <li>Let the value of <var>inherited ns</var> be <var>ns</var>. <span class="note">The new
   457                             <li>Let the value of <var>inherited ns</var> be <var>ns</var>. <span class="note">The new
   458                                 default namespace will be used in the serialization to define this <var>node</var>'s 
   458                                 default namespace will be used in the serialization to define this <var>node</var>'s
   459                                 namespace and act as the context namespace for its <a title="concept-tree-child" 
   459                                 namespace and act as the context namespace for its <a title="concept-tree-child"
   460                                 data-spec="DOM4" class="externalDFN">children</a>.</span>
   460                                 data-spec="DOM4" class="externalDFN">children</a>.</span>
   461                             <li>Append the value of <var>qualified name</var> to <var>markup</var>.
   461                             <li>Append the value of <var>qualified name</var> to <var>markup</var>.
   462                             <li>Append the following to <var>markup</var>, in the order listed: <span class="note">The following 
   462                             <li>Append the following to <var>markup</var>, in the order listed: <span class="note">The following
   463                                 serializes the new (or replacement) default namespace definition.</span>
   463                                 serializes the new (or replacement) default namespace definition.</span>
   464                             <ol>
   464                             <ol>
   465                                 <li>"<code> </code>" (U+0020 SPACE);
   465                                 <li>"<code> </code>" (U+0020 SPACE);
   466                                 <li>The string "<code>xmlns</code>";
   466                                 <li>The string "<code>xmlns</code>";
   467                                 <li>"<code>="</code>" (U+003D EQUALS SIGN, U+0022 QUOTATION MARK);
   467                                 <li>"<code>="</code>" (U+003D EQUALS SIGN, U+0022 QUOTATION MARK);
   468                                 <li>The result of <a title="concept-serialize-attr-value">serializing an attribute value</a> 
   468                                 <li>The result of <a title="concept-serialize-attr-value">serializing an attribute value</a>
   469                                     given <var>ns</var> and the <a title="concept-well-formed">require well-formed</a> flag
   469                                     given <var>ns</var> and the <a title="concept-well-formed">require well-formed</a> flag
   470                                     as input;
   470                                     as input;
   471                                 <li>"<code>"</code>" (U+0022 QUOTATION MARK).
   471                                 <li>"<code>"</code>" (U+0022 QUOTATION MARK).
   472                             </ol>
   472                             </ol>
   473                         </ol>
   473                         </ol>
   474                         <!-- Finally, regardless of prefix, the node has a local default namespace that matches 'ns'.
   474                         <!-- Finally, regardless of prefix, the node has a local default namespace that matches 'ns'.
   475                             So, we'll just use that and drop the prefix -->
   475                             So, we'll just use that and drop the prefix -->
   476                         <li>Otherwise, the <var>node</var> has a <var>local default namespace</var> that matches 
   476                         <li>Otherwise, the <var>node</var> has a <var>local default namespace</var> that matches
   477                             <var>ns</var>. Let <var>qualified name</var> be the value of <var>node</var>'s
   477                             <var>ns</var>. Let <var>qualified name</var> be the value of <var>node</var>'s
   478                             <code><a title="dom-element-localname" data-spec="DOM4" class="externalDFN">localName</a></code>,
   478                             <code><a title="dom-element-localname" data-spec="DOM4" class="externalDFN">localName</a></code>,
   479                             let the value of <var>inherited ns</var> be <var>ns</var>, and append the value of 
   479                             let the value of <var>inherited ns</var> be <var>ns</var>, and append the value of
   480                             <var>qualified name</var> to <var>markup</var>.
   480                             <var>qualified name</var> to <var>markup</var>.
   481                     </ol>
   481                     </ol>
   482                     <li>Append to <var>markup</var> the result of the
   482                     <li>Append to <var>markup</var> the result of the
   483                         <a title="concept-serialize-xml-attributes">XML serialization of <var>node</var>'s 
   483                         <a title="concept-serialize-xml-attributes">XML serialization of <var>node</var>'s
   484                         attributes</a> given the
   484                         attributes</a> given the
   485                         <a title="concept-namespace-prefix-map">namespace prefix map</a> <var>map</var>,
   485                         <a title="concept-namespace-prefix-map">namespace prefix map</a> <var>map</var>,
   486                         the <a title="concept-generated-prefix">generated prefix index</a> <var>prefix index</var>, the 
   486                         the <a title="concept-generated-prefix">generated prefix index</a> <var>prefix index</var>, the
   487                         flag <var>ignore namespace definition attribute</var> and the value of <var>duplicate 
   487                         flag <var>ignore namespace definition attribute</var> and the value of <var>duplicate
   488                         prefix definition</var>.
   488                         prefix definition</var>.
   489                     <li>If <var>ns</var> is the <a title="html-ns">HTML namespace</a>,
   489                     <li>If <var>ns</var> is the <a title="html-ns">HTML namespace</a>,
   490                         and the <var>node</var>'s list of 
   490                         and the <var>node</var>'s list of
   491                         <a title="concept-tree-child" data-spec="DOM4" class="externalDFN">children</a>
   491                         <a title="concept-tree-child" data-spec="DOM4" class="externalDFN">children</a>
   492                         is empty, and the <var>node</var>'s
   492                         is empty, and the <var>node</var>'s
   493                         <code><a title="dom-element-localname" data-spec="DOM4" class="externalDFN">localName</a></code>
   493                         <code><a title="dom-element-localname" data-spec="DOM4" class="externalDFN">localName</a></code>
   494                         matches any one of the following 
   494                         matches any one of the following
   495                         <a title="void-elements" data-spec="HTML5" class="externalDFN">void elements</a>:
   495                         <a title="void-elements" data-spec="HTML5" class="externalDFN">void elements</a>:
   496                         "<code>area</code>",
   496                         "<code>area</code>",
   497                         "<code>base</code>",
   497                         "<code>base</code>",
   498                         "<code>basefont</code>",
   498                         "<code>basefont</code>",
   499                         "<code>bgsound</code>",
   499                         "<code>bgsound</code>",
   517                             <li>"<code> </code>" (U+0020 SPACE);
   517                             <li>"<code> </code>" (U+0020 SPACE);
   518                             <li>"<code>/</code>" (U+002F SOLIDUS).
   518                             <li>"<code>/</code>" (U+002F SOLIDUS).
   519                         </ol>
   519                         </ol>
   520                         and set the <var>skip end tag</var> flag to <code>true</code>.
   520                         and set the <var>skip end tag</var> flag to <code>true</code>.
   521                     <li>If <var>ns</var> is not the <a title="html-ns">HTML namespace</a>,
   521                     <li>If <var>ns</var> is not the <a title="html-ns">HTML namespace</a>,
   522                         and the <var>node</var>'s list of 
   522                         and the <var>node</var>'s list of
   523                         <a title="concept-tree-child" data-spec="DOM4" class="externalDFN">children</a>
   523                         <a title="concept-tree-child" data-spec="DOM4" class="externalDFN">children</a>
   524                         is empty, then append "<code>/</code>" (U+002F SOLIDUS) to <var>markup</var>
   524                         is empty, then append "<code>/</code>" (U+002F SOLIDUS) to <var>markup</var>
   525                         and set the <var>skip end tag</var> flag to <code>true</code>.
   525                         and set the <var>skip end tag</var> flag to <code>true</code>.
   526                     <li>Append "<code>&gt;</code>" (U+003E GREATER-THAN SIGN) to <var>markup</var>.
   526                     <li>Append "<code>&gt;</code>" (U+003E GREATER-THAN SIGN) to <var>markup</var>.
   527                     <li>If the value of <var>skip end tag</var> is <code>true</code>, then return 
   527                     <li>If the value of <var>skip end tag</var> is <code>true</code>, then return
   528                         the value of <var>markup</var> and skip the remaining steps. The 
   528                         the value of <var>markup</var> and skip the remaining steps. The
   529                         <var>node</var> is a leaf-node.
   529                         <var>node</var> is a leaf-node.
   530                     <li>If <var>ns</var> is the <a title="html-ns">HTML namespace</a>, and the <var>node</var>'s 
   530                     <li>If <var>ns</var> is the <a title="html-ns">HTML namespace</a>, and the <var>node</var>'s
   531                         <code><a title="dom-element-localname" data-spec="DOM4" class="externalDFN">localName</a></code>
   531                         <code><a title="dom-element-localname" data-spec="DOM4" class="externalDFN">localName</a></code>
   532                         matches the string "<code>template</code>", then this is a 
   532                         matches the string "<code>template</code>", then this is a
   533                         <code><a title="the-template-element" data-spec="HTML5" class="externalDFN">template</a></code> element. 
   533                         <code><a title="the-template-element" data-spec="HTML5" class="externalDFN">template</a></code> element.
   534                         Append to <var>markup</var> the result of running the 
   534                         Append to <var>markup</var> the result of running the
   535                         <a title="concept-xml-serialization-algorithm">XML serialization algorithm</a> on the 
   535                         <a title="concept-xml-serialization-algorithm">XML serialization algorithm</a> on the
   536                         <a title="the-template-element" data-spec="HTML5" class="externalDFN">template</a> element's  
   536                         <a title="the-template-element" data-spec="HTML5" class="externalDFN">template</a> element's
   537                         <a title="template-contents" data-spec="HTML5" class="externalDFN">template contents</a>
   537                         <a title="template-contents" data-spec="HTML5" class="externalDFN">template contents</a>
   538                         (a <code><a title="interface-documentfragment" data-spec="DOM4" class="externalDFN">DocumentFragment</a></code>),
   538                         (a <code><a title="interface-documentfragment" data-spec="DOM4" class="externalDFN">DocumentFragment</a></code>),
   539                         providing the value of <var>inherited ns</var> for the 
   539                         providing the value of <var>inherited ns</var> for the
   540                         <a title="concept-context-namespace">context namespace</a>,
   540                         <a title="concept-context-namespace">context namespace</a>,
   541                         <var>map</var> for the <a title="concept-namespace-prefix-map">namespace prefix map</a>,
   541                         <var>map</var> for the <a title="concept-namespace-prefix-map">namespace prefix map</a>,
   542                         <var>prefix index</var> for the 
   542                         <var>prefix index</var> for the
   543                         <a title="concept-generated-prefix">generated namespace prefix index</a>, and the value
   543                         <a title="concept-generated-prefix">generated namespace prefix index</a>, and the value
   544                         of the <var>require well-formed</var> flag. <span class="note">This allows 
   544                         of the <var>require well-formed</var> flag. <span class="note">This allows
   545                         <a title="template-contents" data-spec="HTML5" class="externalDFN">template content</a> to
   545                         <a title="template-contents" data-spec="HTML5" class="externalDFN">template content</a> to
   546                         round-trip , given the rules for
   546                         round-trip , given the rules for
   547                         <a title="parsing-xhtml-documents" data-spec="HTML5" class="externalDFN">parsing XHTML documents</a>
   547                         <a title="parsing-xhtml-documents" data-spec="HTML5" class="externalDFN">parsing XHTML documents</a>
   548                         [[HTML5]].</span>
   548                         [[HTML5]].</span>
   549                     <li>Otherwise, append to <var>markup</var> the result of running the  
   549                     <li>Otherwise, append to <var>markup</var> the result of running the
   550                         <a title="concept-xml-serialization-algorithm">XML serialization algorithm</a> on each 
   550                         <a title="concept-xml-serialization-algorithm">XML serialization algorithm</a> on each
   551                         of <var>node</var>'s
   551                         of <var>node</var>'s
   552                         <a title="concept-tree-child" data-spec="DOM4" class="externalDFN">children</a>,
   552                         <a title="concept-tree-child" data-spec="DOM4" class="externalDFN">children</a>,
   553                         in <a data-spec="DOM4" title="concept-tree-order" class="externalDFN">tree order</a>,
   553                         in <a data-spec="DOM4" title="concept-tree-order" class="externalDFN">tree order</a>,
   554                         providing the value of <var>inherited ns</var> for the 
   554                         providing the value of <var>inherited ns</var> for the
   555                         <a title="concept-context-namespace">context namespace</a>,
   555                         <a title="concept-context-namespace">context namespace</a>,
   556                         <var>map</var> for the <a title="concept-namespace-prefix-map">namespace prefix map</a>,
   556                         <var>map</var> for the <a title="concept-namespace-prefix-map">namespace prefix map</a>,
   557                         <var>prefix index</var> for the 
   557                         <var>prefix index</var> for the
   558                         <a title="concept-generated-prefix">generated namespace prefix index</a>, and the value
   558                         <a title="concept-generated-prefix">generated namespace prefix index</a>, and the value
   559                         of the <var>require well-formed</var> flag.
   559                         of the <var>require well-formed</var> flag.
   560                     <li>Append the following to <var>markup</var>, in the order listed:
   560                     <li>Append the following to <var>markup</var>, in the order listed:
   561                         <ol>
   561                         <ol>
   562                             <li>"<code>&lt;/</code>" (U+003C LESS-THAN SIGN, U+002F SOLIDUS);
   562                             <li>"<code>&lt;/</code>" (U+003C LESS-THAN SIGN, U+002F SOLIDUS);
   566                     <li>Return the value of <var>markup</var>.
   566                     <li>Return the value of <var>markup</var>.
   567                 </ol>
   567                 </ol>
   568 
   568 
   569             <dt><code><a title="interface-document" data-spec="DOM4" class="externalDFN">Document</a></code>
   569             <dt><code><a title="interface-document" data-spec="DOM4" class="externalDFN">Document</a></code>
   570             <dd>
   570             <dd>
   571                 <p>If the <a title="concept-well-formed">require well-formed</a> flag is set (its value is 
   571                 <p>If the <a title="concept-well-formed">require well-formed</a> flag is set (its value is
   572                     <code>true</code>), and this <var>node</var> has no 
   572                     <code>true</code>), and this <var>node</var> has no
   573                     <code><a title="dom-document-documentelement" data-spec="DOM4" class="externalDFN">documentElement</a></code>
   573                     <code><a title="dom-document-documentelement" data-spec="DOM4" class="externalDFN">documentElement</a></code>
   574                     (the <code><a title="dom-document-documentelement" data-spec="DOM4" class="externalDFN">documentElement</a></code>
   574                     (the <code><a title="dom-document-documentelement" data-spec="DOM4" class="externalDFN">documentElement</a></code>
   575                     attribute's value is <code>null</code>), then <a title="concept-algorithm-exception">throw an 
   575                     attribute's value is <code>null</code>), then <a title="concept-algorithm-exception">throw an
   576                     exception</a>; the serialization of this <var>node</var> would not be a well-formed document.
   576                     exception</a>; the serialization of this <var>node</var> would not be a well-formed document.
   577                 <p>Otherwise, run the following steps:
   577                 <p>Otherwise, run the following steps:
   578                 <ol>
   578                 <ol>
   579                     <li>Let <var>serialized document</var> be an empty string.
   579                     <li>Let <var>serialized document</var> be an empty string.
   580                     <li>Append to <var>serialized document</var> the string produced by running the steps to 
   580                     <li>Append to <var>serialized document</var> the string produced by running the steps to
   581                         <a title="concept-serialize-doctype">produce a DocumentType serialization</a>
   581                         <a title="concept-serialize-doctype">produce a DocumentType serialization</a>
   582                         of <var>node</var>'s 
   582                         of <var>node</var>'s
   583                         <code><a title="dom-document-doctype" data-spec="DOM4" class="externalDFN">doctype</a></code>
   583                         <code><a title="dom-document-doctype" data-spec="DOM4" class="externalDFN">doctype</a></code>
   584                         attribute provided the <var>require well-formed</var> flag if <var>node</var>'s 
   584                         attribute provided the <var>require well-formed</var> flag if <var>node</var>'s
   585                         <code><a title="dom-document-doctype" data-spec="DOM4" class="externalDFN">doctype</a></code>
   585                         <code><a title="dom-document-doctype" data-spec="DOM4" class="externalDFN">doctype</a></code>
   586                         attribute is not <code>null</code>.
   586                         attribute is not <code>null</code>.
   587                     <li>For each <a title="concept-tree-child" data-spec="DOM4" class="externalDFN">child</a>
   587                     <li>For each <a title="concept-tree-child" data-spec="DOM4" class="externalDFN">child</a>
   588                         <var>child</var> of <var>node</var>, in 
   588                         <var>child</var> of <var>node</var>, in
   589                         <a data-spec="DOM4" title="concept-tree-order" class="externalDFN">tree order</a>, run the 
   589                         <a data-spec="DOM4" title="concept-tree-order" class="externalDFN">tree order</a>, run the
   590                         <a title="concept-xml-serialization-algorithm">XML serialization algorithm</a>
   590                         <a title="concept-xml-serialization-algorithm">XML serialization algorithm</a>
   591                         on the <var>child</var> given a <a title="concept-context-namespace">context namespace</a>
   591                         on the <var>child</var> given a <a title="concept-context-namespace">context namespace</a>
   592                         <var>namespace</var>, a <a title="concept-namespace-prefix-map">namespace prefix map</a>
   592                         <var>namespace</var>, a <a title="concept-namespace-prefix-map">namespace prefix map</a>
   593                         <var>prefix map</var>, a reference to a <a title="concept-generated-prefix">generated 
   593                         <var>prefix map</var>, a reference to a <a title="concept-generated-prefix">generated
   594                         namespace prefix index</a> <var>prefix index</var>, flag <var>require well-formed</var>, and
   594                         namespace prefix index</a> <var>prefix index</var>, flag <var>require well-formed</var>, and
   595                         append the result to <var>serialized document</var>.
   595                         append the result to <var>serialized document</var>.
   596                     <li>Return the value of <var>serialized document</var>.
   596                     <li>Return the value of <var>serialized document</var>.
   597                 </ol>
   597                 </ol>
   598 
   598 
   599             <dt><code><a title="interface-comment" data-spec="DOM4" class="externalDFN">Comment</a></code>
   599             <dt><code><a title="interface-comment" data-spec="DOM4" class="externalDFN">Comment</a></code>
   600             <dd>
   600             <dd>
   601                 <p>If the <a title="concept-well-formed">require well-formed</a> flag is set (its value is 
   601                 <p>If the <a title="concept-well-formed">require well-formed</a> flag is set (its value is
   602                     <code>true</code>), and <var>node</var>'s
   602                     <code>true</code>), and <var>node</var>'s
   603                     <code><a title="dom-characterdata-data" data-spec="DOM4" class="externalDFN">data</a></code>
   603                     <code><a title="dom-characterdata-data" data-spec="DOM4" class="externalDFN">data</a></code>
   604                     contains characters that are not matched by the XML <code>Char</code> production [[XML10]] or
   604                     contains characters that are not matched by the XML <code>Char</code> production [[XML10]] or
   605                     contains "<code>--</code>" (two adjacent U+002D HYPHEN-MINUS characters) or that ends with 
   605                     contains "<code>--</code>" (two adjacent U+002D HYPHEN-MINUS characters) or that ends with
   606                     a "<code>-</code>" (U+002D HYPHEN-MINUS) character, then 
   606                     a "<code>-</code>" (U+002D HYPHEN-MINUS) character, then
   607                     <a title="concept-algorithm-exception">throw an exception</a>; the serialization of this 
   607                     <a title="concept-algorithm-exception">throw an exception</a>; the serialization of this
   608                     <var>node</var>'s 
   608                     <var>node</var>'s
   609                     <code><a title="dom-characterdata-data" data-spec="DOM4" class="externalDFN">data</a></code>
   609                     <code><a title="dom-characterdata-data" data-spec="DOM4" class="externalDFN">data</a></code>
   610                     would not be well-formed.
   610                     would not be well-formed.
   611                 <p>Return the concatenation of "<code>&lt;!--</code>", <var>node</var>'s
   611                 <p>Return the concatenation of "<code>&lt;!--</code>", <var>node</var>'s
   612                 <code><a title="dom-characterdata-data" data-spec="DOM4" class="externalDFN">data</a></code>, and
   612                 <code><a title="dom-characterdata-data" data-spec="DOM4" class="externalDFN">data</a></code>, and
   613                 "<code>--></code>".
   613                 "<code>--></code>".
   614 
   614 
   615             <!-- Removing CDATA Serialization steps as this interface type is removed from DOM4:
   615             <!-- Removing CDATA Serialization steps as this interface type is removed from DOM4:
   616             <dt><code><a title="cdata" data-spec="DOML2" class="externalDFN">CDATASection</a></code>
   616             <dt><code><a title="cdata" data-spec="DOML2" class="externalDFN">CDATASection</a></code>
   617             <dd><ol>
   617             <dd><ol>
   618                 <li>Let <var>markup</var> be the concatenation of "<code>&lt;![CDATA[</code>", 
   618                 <li>Let <var>markup</var> be the concatenation of "<code>&lt;![CDATA[</code>",
   619                     <var>node</var>'s <code><a title="dom-characterdata-data" data-spec="DOM4" 
   619                     <var>node</var>'s <code><a title="dom-characterdata-data" data-spec="DOM4"
   620                     class="externalDFN">data</a></code>, and "<code>]]></code>".
   620                     class="externalDFN">data</a></code>, and "<code>]]></code>".
   621                 <li>Return the value of <var>markup</var>.
   621                 <li>Return the value of <var>markup</var>.
   622               </ol>
   622               </ol>
   623 
   623 
   624               <p class=note>CDATASection objects may be created by the historical 
   624               <p class=note>CDATASection objects may be created by the historical
   625             <code>document.createCDATASection</code> API, or as a result of parsing an
   625             <code>document.createCDATASection</code> API, or as a result of parsing an
   626             <a title="xml-document" data-spec="DOM4" class="externalDFN">XML document</a>.
   626             <a title="xml-document" data-spec="DOM4" class="externalDFN">XML document</a>.
   627             -->
   627             -->
   628             
   628 
   629             <dt><code><a title="interface-text" data-spec="DOM4" class="externalDFN">Text</a></code>
   629             <dt><code><a title="interface-text" data-spec="DOM4" class="externalDFN">Text</a></code>
   630             <dd><ol>
   630             <dd><ol>
   631                 <li>If the <a title="concept-well-formed">require well-formed</a> flag is set (its value is 
   631                 <li>If the <a title="concept-well-formed">require well-formed</a> flag is set (its value is
   632                     <code>true</code>), and <var>node</var>'s
   632                     <code>true</code>), and <var>node</var>'s
   633                     <code><a title="dom-characterdata-data" data-spec="DOM4" class="externalDFN">data</a></code>
   633                     <code><a title="dom-characterdata-data" data-spec="DOM4" class="externalDFN">data</a></code>
   634                     contains characters that are not matched by the XML <code>Char</code> production [[XML10]], 
   634                     contains characters that are not matched by the XML <code>Char</code> production [[XML10]],
   635                     then <a title="concept-algorithm-exception">throw an exception</a>; the serialization of this 
   635                     then <a title="concept-algorithm-exception">throw an exception</a>; the serialization of this
   636                     <var>node</var>'s 
   636                     <var>node</var>'s
   637                     <code><a title="dom-characterdata-data" data-spec="DOM4" class="externalDFN">data</a></code>
   637                     <code><a title="dom-characterdata-data" data-spec="DOM4" class="externalDFN">data</a></code>
   638                     would not be well-formed.
   638                     would not be well-formed.
   639                 <li>Let <var>markup</var> be the value of <var>node</var>'s
   639                 <li>Let <var>markup</var> be the value of <var>node</var>'s
   640                 <code><a title="dom-characterdata-data" data-spec="DOM4" class="externalDFN">data</a></code>.
   640                 <code><a title="dom-characterdata-data" data-spec="DOM4" class="externalDFN">data</a></code>.
   641                 
   641 
   642                 <li>Replace any occurrences of "<code>&amp;</code>" in <var>markup</var> by
   642                 <li>Replace any occurrences of "<code>&amp;</code>" in <var>markup</var> by
   643                 "<code>&amp;amp;</code>".
   643                 "<code>&amp;amp;</code>".
   644                 
   644 
   645                 <li>Replace any occurrences of "<code>&lt;</code>" in <var>markup</var> by
   645                 <li>Replace any occurrences of "<code>&lt;</code>" in <var>markup</var> by
   646                 "<code>&amp;lt;</code>".
   646                 "<code>&amp;lt;</code>".
   647                 
   647 
   648                 <li>Replace any occurrences of "<code>&gt;</code>" in <var>markup</var> by
   648                 <li>Replace any occurrences of "<code>&gt;</code>" in <var>markup</var> by
   649                 "<code>&amp;gt;</code>".
   649                 "<code>&amp;gt;</code>".
   650                 
   650 
   651                 <li>Return the value of <var>markup</var>.
   651                 <li>Return the value of <var>markup</var>.
   652               </ol>
   652               </ol>
   653             <dt><code><a title="interface-documentfragment" data-spec="DOM4" class="externalDFN">DocumentFragment</a></code>
   653             <dt><code><a title="interface-documentfragment" data-spec="DOM4" class="externalDFN">DocumentFragment</a></code>
   654             <dd><ol>
   654             <dd><ol>
   655                 <li>Let <var>markup</var> the empty string.
   655                 <li>Let <var>markup</var> the empty string.
   656 
   656 
   657                 <li>For each <a title="concept-tree-child" data-spec="DOM4" class="externalDFN">child</a> 
   657                 <li>For each <a title="concept-tree-child" data-spec="DOM4" class="externalDFN">child</a>
   658                     <var>child</var> of <var>node</var>, in 
   658                     <var>child</var> of <var>node</var>, in
   659                     <a data-spec="DOM4" title="concept-tree-order" class="externalDFN">tree order</a>, 
   659                     <a data-spec="DOM4" title="concept-tree-order" class="externalDFN">tree order</a>,
   660                     run the <a title="concept-xml-serialization-algorithm">XML serialization algorithm</a>
   660                     run the <a title="concept-xml-serialization-algorithm">XML serialization algorithm</a>
   661                     on the <var>child</var> given 
   661                     on the <var>child</var> given
   662                     a <a title="concept-context-namespace">context namespace</a> <var>namespace</var>, a
   662                     a <a title="concept-context-namespace">context namespace</a> <var>namespace</var>, a
   663                     <a title="concept-namespace-prefix-map">namespace prefix map</a> <var>prefix map</var>,
   663                     <a title="concept-namespace-prefix-map">namespace prefix map</a> <var>prefix map</var>,
   664                     a reference to a <a title="concept-generated-prefix">generated namespace prefix index</a> 
   664                     a reference to a <a title="concept-generated-prefix">generated namespace prefix index</a>
   665                     <var>prefix index</var>, and flag <var>require well-formed</var>. Concatenate the result 
   665                     <var>prefix index</var>, and flag <var>require well-formed</var>. Concatenate the result
   666                     to <var>markup</var>.
   666                     to <var>markup</var>.
   667                 <li>Return the value of <var>markup</var>.
   667                 <li>Return the value of <var>markup</var>.
   668               </ol>
   668               </ol>
   669               
   669 
   670             <dt><code><a title="interface-documenttype" data-spec="DOM4" class="externalDFN">DocumentType</a></code>
   670             <dt><code><a title="interface-documenttype" data-spec="DOM4" class="externalDFN">DocumentType</a></code>
   671             <dd>Run the steps to <a title="concept-serialize-doctype">produce a DocumentType 
   671             <dd>Run the steps to <a title="concept-serialize-doctype">produce a DocumentType
   672                 serialization</a> of <var>node</var> given the <a title="concept-well-formed">require well-formed</a>
   672                 serialization</a> of <var>node</var> given the <a title="concept-well-formed">require well-formed</a>
   673                 flag, and return the string this produced.
   673                 flag, and return the string this produced.
   674             
   674 
   675             <dt><code><a title="interface-processinginstruction" data-spec="DOM4" class="externalDFN">ProcessingInstruction</a></code>
   675             <dt><code><a title="interface-processinginstruction" data-spec="DOM4" class="externalDFN">ProcessingInstruction</a></code>
   676             <dd><ol>
   676             <dd><ol>
   677                 <li>If the <a title="concept-well-formed">require well-formed</a> flag is set (its value is 
   677                 <li>If the <a title="concept-well-formed">require well-formed</a> flag is set (its value is
   678                     <code>true</code>), and <var>node</var>'s
   678                     <code>true</code>), and <var>node</var>'s
   679                     <code><a title="dom-processinginstruction-target" data-spec="DOM4" class="externalDFN">target</a></code>
   679                     <code><a title="dom-processinginstruction-target" data-spec="DOM4" class="externalDFN">target</a></code>
   680                     contains a "<code>:</code>" (U+003A COLON) character or is an 
   680                     contains a "<code>:</code>" (U+003A COLON) character or is an
   681                     <a data-spec="DOM4" class="externalDFN" title="ascii-case-insensitive">ASCII case-insensitive</a>
   681                     <a data-spec="DOM4" class="externalDFN" title="ascii-case-insensitive">ASCII case-insensitive</a>
   682                     match for the string "<code>xml</code>", then <a title="concept-algorithm-exception">throw an 
   682                     match for the string "<code>xml</code>", then <a title="concept-algorithm-exception">throw an
   683                     exception</a>; the serialization of this <var>node</var>'s 
   683                     exception</a>; the serialization of this <var>node</var>'s
   684                     <code><a title="dom-processinginstruction-target" data-spec="DOM4" class="externalDFN">target</a></code>
   684                     <code><a title="dom-processinginstruction-target" data-spec="DOM4" class="externalDFN">target</a></code>
   685                     would not be well-formed.
   685                     would not be well-formed.
   686                 <li>If the <a title="concept-well-formed">require well-formed</a> flag is set (its value is 
   686                 <li>If the <a title="concept-well-formed">require well-formed</a> flag is set (its value is
   687                     <code>true</code>), and <var>node</var>'s
   687                     <code>true</code>), and <var>node</var>'s
   688                     <code><a title="dom-characterdata-data" data-spec="DOM4" class="externalDFN">data</a></code>
   688                     <code><a title="dom-characterdata-data" data-spec="DOM4" class="externalDFN">data</a></code>
   689                     contains characters that are not matched by the XML <code>Char</code> production [[XML10]] or
   689                     contains characters that are not matched by the XML <code>Char</code> production [[XML10]] or
   690                     contains the string "<code>?></code>" (U+003F QUESTION MARK, U+003E GREATER-THAN SIGN),
   690                     contains the string "<code>?></code>" (U+003F QUESTION MARK, U+003E GREATER-THAN SIGN),
   691                     then <a title="concept-algorithm-exception">throw an exception</a>; the serialization of this 
   691                     then <a title="concept-algorithm-exception">throw an exception</a>; the serialization of this
   692                     <var>node</var>'s 
   692                     <var>node</var>'s
   693                     <code><a title="dom-characterdata-data" data-spec="DOM4" class="externalDFN">data</a></code>
   693                     <code><a title="dom-characterdata-data" data-spec="DOM4" class="externalDFN">data</a></code>
   694                     would not be well-formed.
   694                     would not be well-formed.
   695                 <li>Let <var>markup</var> be the concatenation of the following, in the order listed:
   695                 <li>Let <var>markup</var> be the concatenation of the following, in the order listed:
   696                 <ol>
   696                 <ol>
   697                     <li>"<code>&lt;?</code>" (U+003C LESS-THAN SIGN, U+003F QUESTION MARK);
   697                     <li>"<code>&lt;?</code>" (U+003C LESS-THAN SIGN, U+003F QUESTION MARK);
   698                     <li>The value of <var>node</var>'s <code><a title="dom-processinginstruction-target" 
   698                     <li>The value of <var>node</var>'s <code><a title="dom-processinginstruction-target"
   699                         data-spec="DOM4" class="externalDFN">target</a></code>;
   699                         data-spec="DOM4" class="externalDFN">target</a></code>;
   700                     <li>"<code> </code>" (U+0020 SPACE);
   700                     <li>"<code> </code>" (U+0020 SPACE);
   701                     <li>The value of <var>node</var>'s <code><a title="dom-characterdata-data" 
   701                     <li>The value of <var>node</var>'s <code><a title="dom-characterdata-data"
   702                         data-spec="DOM4" class="externalDFN">data</a></code>;
   702                         data-spec="DOM4" class="externalDFN">data</a></code>;
   703                     <li>"<code>?></code>" (U+003F QUESTION MARK, U+003E GREATER-THAN SIGN).
   703                     <li>"<code>?></code>" (U+003F QUESTION MARK, U+003E GREATER-THAN SIGN).
   704                 </ol>
   704                 </ol>
   705                 <li>Return the value of <var>markup</var>.
   705                 <li>Return the value of <var>markup</var>.
   706               </ol>
   706               </ol>
   707               
   707 
   708         </dl>
   708         </dl>
   709 
   709 
   710         <p>To <dfn title="concept-serialize-doctype">produce a DocumentType serialization</dfn> of a
   710         <p>To <dfn title="concept-serialize-doctype">produce a DocumentType serialization</dfn> of a
   711             <code><a title="node" data-spec="DOM4" class="externalDFN">Node</a></code> <var>node</var>, given a 
   711             <code><a title="node" data-spec="DOM4" class="externalDFN">Node</a></code> <var>node</var>, given a
   712             <a title="concept-well-formed">require well-formed</a> flag, the user agent must return 
   712             <a title="concept-well-formed">require well-formed</a> flag, the user agent must return
   713             the result of the following algorithm:</p>
   713             the result of the following algorithm:</p>
   714                 
   714 
   715         <ol>
   715         <ol>
   716             <li>If the <a title="concept-well-formed">require well-formed</a> flag is <code>true</code>
   716             <li>If the <a title="concept-well-formed">require well-formed</a> flag is <code>true</code>
   717                 and the <var>node</var>'s 
   717                 and the <var>node</var>'s
   718                 <code><a title="dom-documenttype-publicid" data-spec="DOM4" class="externalDFN">publicId</a></code>
   718                 <code><a title="dom-documenttype-publicid" data-spec="DOM4" class="externalDFN">publicId</a></code>
   719                 attribute contains characters that are not matched by the XML <code>PubidChar</code> production 
   719                 attribute contains characters that are not matched by the XML <code>PubidChar</code> production
   720                 [[XML10]], then <a title="concept-algorithm-exception">throw an exception</a>; the serialization 
   720                 [[XML10]], then <a title="concept-algorithm-exception">throw an exception</a>; the serialization
   721                 of this <var>node</var> would not be a well-formed document type declaration.
   721                 of this <var>node</var> would not be a well-formed document type declaration.
   722             <li>If the <a title="concept-well-formed">require well-formed</a> flag is <code>true</code>
   722             <li>If the <a title="concept-well-formed">require well-formed</a> flag is <code>true</code>
   723                 and the <var>node</var>'s 
   723                 and the <var>node</var>'s
   724                 <code><a title="dom-documenttype-systemid" data-spec="DOM4" class="externalDFN">systemId</a></code>
   724                 <code><a title="dom-documenttype-systemid" data-spec="DOM4" class="externalDFN">systemId</a></code>
   725                 attribute contains characters that are not matched by the XML <code>Char</code> production 
   725                 attribute contains characters that are not matched by the XML <code>Char</code> production
   726                 [[XML10]] or that contains both a "<code>"</code>" (U+0022 QUOTATION MARK) and a "<code>'</code>" 
   726                 [[XML10]] or that contains both a "<code>"</code>" (U+0022 QUOTATION MARK) and a "<code>'</code>"
   727                 (U+0027 APOSTROPHE), then <a title="concept-algorithm-exception">throw an exception</a>; the 
   727                 (U+0027 APOSTROPHE), then <a title="concept-algorithm-exception">throw an exception</a>; the
   728                 serialization of this <var>node</var> would not be a well-formed document type declaration.
   728                 serialization of this <var>node</var> would not be a well-formed document type declaration.
   729             <li>Let <var>markup</var> be an empty string.
   729             <li>Let <var>markup</var> be an empty string.
   730             <li>Append the string "<code>&lt;!DOCTYPE</code>" to <var>markup</var>.
   730             <li>Append the string "<code>&lt;!DOCTYPE</code>" to <var>markup</var>.
   731             <li>Append "<code> </code>" (U+0020 SPACE) to <var>markup</var>.
   731             <li>Append "<code> </code>" (U+0020 SPACE) to <var>markup</var>.
   732             <li>Append the value of the <var>node</var>'s 
   732             <li>Append the value of the <var>node</var>'s
   733                 <code><a title="dom-documenttype-name" data-spec="DOM4" class="externalDFN">name</a></code>
   733                 <code><a title="dom-documenttype-name" data-spec="DOM4" class="externalDFN">name</a></code>
   734                 attribute to <var>markup</var>. For a <var>node</var> belonging to an
   734                 attribute to <var>markup</var>. For a <var>node</var> belonging to an
   735                 <a title="html-document" data-spec="DOM4" class="externalDFN">HTML document</a>,
   735                 <a title="html-document" data-spec="DOM4" class="externalDFN">HTML document</a>,
   736                 the value will be all lowercase.
   736                 the value will be all lowercase.
   737             <li>If the <var>node</var>'s 
   737             <li>If the <var>node</var>'s
   738                 <code><a title="dom-documenttype-publicid" data-spec="DOM4" class="externalDFN">publicId</a></code>
   738                 <code><a title="dom-documenttype-publicid" data-spec="DOM4" class="externalDFN">publicId</a></code>
   739                 is not the empty string then append the following, in the order listed, to <var>markup</var>:
   739                 is not the empty string then append the following, in the order listed, to <var>markup</var>:
   740                 <ol>
   740                 <ol>
   741                     <li>"<code> </code>" (U+0020 SPACE);
   741                     <li>"<code> </code>" (U+0020 SPACE);
   742                     <li>The string "<code>PUBLIC</code>";
   742                     <li>The string "<code>PUBLIC</code>";
   743                     <li>"<code> </code>" (U+0020 SPACE);
   743                     <li>"<code> </code>" (U+0020 SPACE);
   744                     <li>"<code>"</code>" (U+0022 QUOTATION MARK);
   744                     <li>"<code>"</code>" (U+0022 QUOTATION MARK);
   745                     <li>The value of the <var>node</var>'s 
   745                     <li>The value of the <var>node</var>'s
   746                         <code><a title="dom-documenttype-publicid" data-spec="DOM4" class="externalDFN">publicId</a></code>
   746                         <code><a title="dom-documenttype-publicid" data-spec="DOM4" class="externalDFN">publicId</a></code>
   747                         attribute;
   747                         attribute;
   748                     <li>"<code>"</code>" (U+0022 QUOTATION MARK).
   748                     <li>"<code>"</code>" (U+0022 QUOTATION MARK).
   749                 </ol>
   749                 </ol>
   750             </li>
   750             </li>
   751             <li>If the <var>node</var>'s 
   751             <li>If the <var>node</var>'s
   752                 <code><a title="dom-documenttype-systemid" data-spec="DOM4" class="externalDFN">systemId</a></code>
   752                 <code><a title="dom-documenttype-systemid" data-spec="DOM4" class="externalDFN">systemId</a></code>
   753                 is not the empty string and the <var>node</var>'s 
   753                 is not the empty string and the <var>node</var>'s
   754                 <code><a title="dom-documenttype-publicid" data-spec="DOM4" class="externalDFN">publicId</a></code>
   754                 <code><a title="dom-documenttype-publicid" data-spec="DOM4" class="externalDFN">publicId</a></code>
   755                 is set to the empty string, then append the following, in the order listed, to <var>markup</var>:
   755                 is set to the empty string, then append the following, in the order listed, to <var>markup</var>:
   756                 <ol>
   756                 <ol>
   757                     <li>"<code> </code>" (U+0020 SPACE);
   757                     <li>"<code> </code>" (U+0020 SPACE);
   758                     <li>The string "<code>SYSTEM</code>".
   758                     <li>The string "<code>SYSTEM</code>".
   759                 </ol>
   759                 </ol>
   760             </li>
   760             </li>
   761             <li>If the <var>node</var>'s 
   761             <li>If the <var>node</var>'s
   762                 <code><a title="dom-documenttype-systemid" data-spec="DOM4" class="externalDFN">systemId</a></code>
   762                 <code><a title="dom-documenttype-systemid" data-spec="DOM4" class="externalDFN">systemId</a></code>
   763                 is not the empty string then append the following, in the order listed, to <var>markup</var>:
   763                 is not the empty string then append the following, in the order listed, to <var>markup</var>:
   764                 <ol>
   764                 <ol>
   765                     <li>"<code> </code>" (U+0020 SPACE);
   765                     <li>"<code> </code>" (U+0020 SPACE);
   766                     <li>"<code>"</code>" (U+0022 QUOTATION MARK);
   766                     <li>"<code>"</code>" (U+0022 QUOTATION MARK);
   767                     <li>The value of the <var>node</var>'s 
   767                     <li>The value of the <var>node</var>'s
   768                         <code><a title="dom-documenttype-systemid" data-spec="DOM4" class="externalDFN">systemId</a></code>
   768                         <code><a title="dom-documenttype-systemid" data-spec="DOM4" class="externalDFN">systemId</a></code>
   769                         attribute;
   769                         attribute;
   770                     <li>"<code>"</code>" (U+0022 QUOTATION MARK).
   770                     <li>"<code>"</code>" (U+0022 QUOTATION MARK).
   771                 </ol>
   771                 </ol>
   772             </li>
   772             </li>
   773             <!-- Removing internalSubset serialization steps as this property is not supported by DOM4. Also,
   773             <!-- Removing internalSubset serialization steps as this property is not supported by DOM4. Also,
   774                 optional requirements don't help improve interoperability:
   774                 optional requirements don't help improve interoperability:
   775             <li>Optional: if the <var>node</var> has an (historical) 
   775             <li>Optional: if the <var>node</var> has an (historical)
   776                 <code><a title="ID-Core-DocType-internalSubset" data-spec="DOM3" class="externalDFN">internalSubset</a></code>
   776                 <code><a title="ID-Core-DocType-internalSubset" data-spec="DOM3" class="externalDFN">internalSubset</a></code>
   777                 and the
   777                 and the
   778                 <code><a title="ID-Core-DocType-internalSubset" data-spec="DOM3" class="externalDFN">internalSubset</a></code>
   778                 <code><a title="ID-Core-DocType-internalSubset" data-spec="DOM3" class="externalDFN">internalSubset</a></code>
   779                 attribute's value is a non-empty string, then append the following,
   779                 attribute's value is a non-empty string, then append the following,
   780                 in the order listed, to <var>markup</var>:
   780                 in the order listed, to <var>markup</var>:
   781                 <ol>
   781                 <ol>
   782                     <li>"<code> </code>" (U+0020 SPACE);
   782                     <li>"<code> </code>" (U+0020 SPACE);
   783                     <li>"<code>[</code>" (U+005B LEFT SQUARE BRACKET);
   783                     <li>"<code>[</code>" (U+005B LEFT SQUARE BRACKET);
   784                     <li>The value of the <var>node</var>'s 
   784                     <li>The value of the <var>node</var>'s
   785                         <code><a title="ID-Core-DocType-internalSubset" data-spec="DOM3" class="externalDFN">internalSubset</a></code>
   785                         <code><a title="ID-Core-DocType-internalSubset" data-spec="DOM3" class="externalDFN">internalSubset</a></code>
   786                         attribute;
   786                         attribute;
   787                     <li>"<code>]</code>" (U+005D RIGHT SQUARE BRACKET);
   787                     <li>"<code>]</code>" (U+005D RIGHT SQUARE BRACKET);
   788                 </ol>
   788                 </ol>
   789                 <p class=note>A <var>node</var> belonging to an
   789                 <p class=note>A <var>node</var> belonging to an
   790                    <a title="html-document" data-spec="DOM4" class="externalDFN">HTML document</a>
   790                    <a title="html-document" data-spec="DOM4" class="externalDFN">HTML document</a>
   791                    will never have an 
   791                    will never have an
   792                    <code><a title="ID-Core-DocType-internalSubset" data-spec="DOM3" class="externalDFN">internalSubset</a></code>
   792                    <code><a title="ID-Core-DocType-internalSubset" data-spec="DOM3" class="externalDFN">internalSubset</a></code>
   793                    because any <code><a title="ID-Core-DocType-internalSubset" data-spec="DOM3" class="externalDFN">internalSubset</a></code>
   793                    because any <code><a title="ID-Core-DocType-internalSubset" data-spec="DOM3" class="externalDFN">internalSubset</a></code>
   794                    markup is ignored by the parser.</p>
   794                    markup is ignored by the parser.</p>
   795             </li>
   795             </li>
   796             -->
   796             -->
   797             <li>Append "<code>&gt;</code>" (U+003E GREATER-THAN SIGN) to <var>markup</var>.
   797             <li>Append "<code>&gt;</code>" (U+003E GREATER-THAN SIGN) to <var>markup</var>.
   798             <li>Return the value of <var>markup</var>.
   798             <li>Return the value of <var>markup</var>.
   799         </ol>
   799         </ol>
   800 
   800 
   801         <p>To <dfn title="concept-record-namespace-info">record the namespace information</dfn> for an 
   801         <p>To <dfn title="concept-record-namespace-info">record the namespace information</dfn> for an
   802             <code><a title="element" data-spec="DOM4" class="externalDFN">Element</a></code> <var>element</var>, given a 
   802             <code><a title="element" data-spec="DOM4" class="externalDFN">Element</a></code> <var>element</var>, given a
   803             <a title="concept-namespace-prefix-map">namespace prefix map</a> <var>map</var>, an
   803             <a title="concept-namespace-prefix-map">namespace prefix map</a> <var>map</var>, an
   804             <var>element prefixes list</var> (initially empty), and a <var>duplicate prefix 
   804             <var>element prefixes list</var> (initially empty), and a <var>duplicate prefix
   805             definition</var> reference, the user agent must run the following steps:
   805             definition</var> reference, the user agent must run the following steps:
   806         <ol>
   806         <ol>
   807             <li>Let <var>default namespace attr value</var> be <code>null</code>.
   807             <li>Let <var>default namespace attr value</var> be <code>null</code>.
   808             <li><dfn title="record-namespace-loop">Main</dfn>: For each <a title="concept-attribute" data-spec="DOM4" class="externalDFN">attribute</a>
   808             <li><dfn title="record-namespace-loop">Main</dfn>: For each <a title="concept-attribute" data-spec="DOM4" class="externalDFN">attribute</a>
   809                 <var>attr</var> in <var>element</var>'s
   809                 <var>attr</var> in <var>element</var>'s
   810                 <code><a title="dom-element-attributes" data-spec="DOM4" class="externalDFN">attributes</a></code>,
   810                 <code><a title="dom-element-attributes" data-spec="DOM4" class="externalDFN">attributes</a></code>,
   811                 in the order they are specified in the <var>element</var>'s
   811                 in the order they are specified in the <var>element</var>'s
   812                 <a title="dom-element-attributes" data-spec="DOM4" class="externalDFN">attribute list</a>:
   812                 <a title="dom-element-attributes" data-spec="DOM4" class="externalDFN">attribute list</a>:
   813                 
   813 
   814                 <p class="note">The following conditional steps add namespace prefixes
   814                 <p class="note">The following conditional steps add namespace prefixes
   815                     into the <var>element prefixes list</var> and add or replace them in the <var>map</var>. 
   815                     into the <var>element prefixes list</var> and add or replace them in the <var>map</var>.
   816                     Only attributes in the <a title="xmlns-ns">XMLNS namespace</a> are
   816                     Only attributes in the <a title="xmlns-ns">XMLNS namespace</a> are
   817                     considered (e.g., attributes made to look like namespace declarations via 
   817                     considered (e.g., attributes made to look like namespace declarations via
   818                     <code><a title="dom-element-setattribute" data-spec="DOM4" 
   818                     <code><a title="dom-element-setattribute" data-spec="DOM4"
   819                     class="externalDFN">setAttribute</a>(<em>"xmlns:pretend-prefix"</em>,
   819                     class="externalDFN">setAttribute</a>(<em>"xmlns:pretend-prefix"</em>,
   820                     <em>"pretend-namespace"</em>)</code> are not included).</p>
   820                     <em>"pretend-namespace"</em>)</code> are not included).</p>
   821             <ol>
   821             <ol>
   822                 <li>Let <var>attribute namespace</var> be the value of <var>attr</var>'s  
   822                 <li>Let <var>attribute namespace</var> be the value of <var>attr</var>'s
   823                     <code><a title="dom-attr-namespaceuri" data-spec="DOM4" class="externalDFN">namespaceURI</a></code>
   823                     <code><a title="dom-attr-namespaceuri" data-spec="DOM4" class="externalDFN">namespaceURI</a></code>
   824                     value.
   824                     value.
   825                 <li>Let <var>attribute prefix</var> be the value of <var>attr</var>'s 
   825                 <li>Let <var>attribute prefix</var> be the value of <var>attr</var>'s
   826                         <code><a title="dom-attr-prefix" data-spec="DOM4" class="externalDFN">prefix</a></code>.
   826                         <code><a title="dom-attr-prefix" data-spec="DOM4" class="externalDFN">prefix</a></code>.
   827                 <li>If the <var>attribute namespace</var> is the <a title="xmlns-ns">XMLNS namespace</a>, then:
   827                 <li>If the <var>attribute namespace</var> is the <a title="xmlns-ns">XMLNS namespace</a>, then:
   828                 <ol>
   828                 <ol>
   829                     <li>If <var>attribute prefix</var> is <code>null</code>, then <var>attr</var> is a 
   829                     <li>If <var>attribute prefix</var> is <code>null</code>, then <var>attr</var> is a
   830                         default namespace declaration. Set the <var>default namespace attr value</var> to 
   830                         default namespace declaration. Set the <var>default namespace attr value</var> to
   831                         <var>attr</var>'s <code><a title="dom-attr-value" data-spec="DOM4"
   831                         <var>attr</var>'s <code><a title="dom-attr-value" data-spec="DOM4"
   832                         class="externalDFN">value</a></code> and stop running these steps, returning to 
   832                         class="externalDFN">value</a></code> and stop running these steps, returning to
   833                         <a title="record-namespace-loop">Main</a> to visit the next attribute.
   833                         <a title="record-namespace-loop">Main</a> to visit the next attribute.
   834                     <li>Otherwise, the <var>attribute prefix</var> is not <code>null</code> and <var>attr</var>
   834                     <li>Otherwise, the <var>attribute prefix</var> is not <code>null</code> and <var>attr</var>
   835                         is a namespace prefix definition. Run the following steps:
   835                         is a namespace prefix definition. Run the following steps:
   836                     <ol>
   836                     <ol>
   837                         <li>Let <var>prefix definition</var> be the value of <var>attr</var>'s 
   837                         <li>Let <var>prefix definition</var> be the value of <var>attr</var>'s
   838                             <code><a title="dom-attr-localname" data-spec="DOM4" class="externalDFN">localName</a></code>.
   838                             <code><a title="dom-attr-localname" data-spec="DOM4" class="externalDFN">localName</a></code>.
   839                         <li>Let <var>namespace definition</var> be the value of <var>attr</var>'s 
   839                         <li>Let <var>namespace definition</var> be the value of <var>attr</var>'s
   840                             <code><a title="dom-attr-value" data-spec="DOM4" class="externalDFN">value</a></code>.
   840                             <code><a title="dom-attr-value" data-spec="DOM4" class="externalDFN">value</a></code>.
   841                         <li>If a key matching the value of <var>namespace definition</var> already exists in
   841                         <li>If a key matching the value of <var>namespace definition</var> already exists in
   842                             <var>map</var>, and the key's value matches <var>prefix definition</var>, then 
   842                             <var>map</var>, and the key's value matches <var>prefix definition</var>, then
   843                             this is a duplicate namespace prefix definition. Set the value of <var>duplicate 
   843                             this is a duplicate namespace prefix definition. Set the value of <var>duplicate
   844                             prefix definition</var> to <var>prefix definition</var>.
   844                             prefix definition</var> to <var>prefix definition</var>.
   845                         <li>Otherwise, if the key matching the value of <var>namespace definition</var> already 
   845                         <li>Otherwise, if the key matching the value of <var>namespace definition</var> already
   846                             exists in <var>map</var>, but the key's value does not match <var>prefix definition</var>,
   846                             exists in <var>map</var>, but the key's value does not match <var>prefix definition</var>,
   847                             then update the key's value to be <var>prefix definition</var>.
   847                             then update the key's value to be <var>prefix definition</var>.
   848                         <li>Otherwise, no key matching the value of <var>namespace definition</var> exists;
   848                         <li>Otherwise, no key matching the value of <var>namespace definition</var> exists;
   849                             append to <var>map</var> a new key <var>namespace definition</var>
   849                             append to <var>map</var> a new key <var>namespace definition</var>
   850                             whose key value is the <var>prefix definition</var>.
   850                             whose key value is the <var>prefix definition</var>.
   852                     </ol>
   852                     </ol>
   853                 </ol>
   853                 </ol>
   854             </ol>
   854             </ol>
   855             <li>Return the value of <var>default namespace attr value</var>.
   855             <li>Return the value of <var>default namespace attr value</var>.
   856         </ol>
   856         </ol>
   857         
   857 
   858         <p>To <dfn title="concept-generate-prefix">generate a prefix</dfn> given a 
   858         <p>To <dfn title="concept-generate-prefix">generate a prefix</dfn> given a
   859             <a title="concept-namespace-prefix-map">namespace prefix map</a> <var>map</var>, a 
   859             <a title="concept-namespace-prefix-map">namespace prefix map</a> <var>map</var>, a
   860             string <var>new namespace</var>, and a reference to a
   860             string <var>new namespace</var>, and a reference to a
   861             <a title="concept-generated-prefix">generated namespace prefix index</a> <var>prefix
   861             <a title="concept-generated-prefix">generated namespace prefix index</a> <var>prefix
   862             index</var>, the user agent must run the following steps:
   862             index</var>, the user agent must run the following steps:
   863         <ol>
   863         <ol>
   864             <li>Let <var>generated prefix</var> be the concatenation of the string "<code>ns</code>" and
   864             <li>Let <var>generated prefix</var> be the concatenation of the string "<code>ns</code>" and
   865                 the current numerical value of <var>prefix index</var>.
   865                 the current numerical value of <var>prefix index</var>.
   866             <li>Let the value of <var>prefix index</var> be incremented by one.
   866             <li>Let the value of <var>prefix index</var> be incremented by one.
   867             <li>Append to <var>map</var> a new key <var>new namespace</var> whose key value is the 
   867             <li>Append to <var>map</var> a new key <var>new namespace</var> whose key value is the
   868                 <var>generated prefix</var>.
   868                 <var>generated prefix</var>.
   869             <li>Return the value of <var>generated prefix</var>.
   869             <li>Return the value of <var>generated prefix</var>.
   870         </ol>
   870         </ol>
   871         
   871 
   872         <p>The <dfn title="concept-serialize-xml-attributes">XML serialization of the attributes</dfn>
   872         <p>The <dfn title="concept-serialize-xml-attributes">XML serialization of the attributes</dfn>
   873             of an <code><a title="concept-element" data-spec="DOM4" class="externalDFN">Element</a></code>
   873             of an <code><a title="concept-element" data-spec="DOM4" class="externalDFN">Element</a></code>
   874             <var>element</var> together with a <a title="concept-namespace-prefix-map">namespace prefix 
   874             <var>element</var> together with a <a title="concept-namespace-prefix-map">namespace prefix
   875             map</a> <var>map</var>, a <a title="concept-generated-prefix">generated prefix index</a> 
   875             map</a> <var>map</var>, a <a title="concept-generated-prefix">generated prefix index</a>
   876             <var>prefix index</var> reference, a flag <var>ignore namespace definition attribute</var>, a
   876             <var>prefix index</var> reference, a flag <var>ignore namespace definition attribute</var>, a
   877             <var>duplicate prefix definition</var> value, and a flag <var>require well-formed</var>,
   877             <var>duplicate prefix definition</var> value, and a flag <var>require well-formed</var>,
   878             is the result of the following algorithm:
   878             is the result of the following algorithm:
   879         <ol>
   879         <ol>
   880             <li>Let <var>result</var> be the empty string.
   880             <li>Let <var>result</var> be the empty string.
   881             <li>Let <var>localname set</var> be a new empty 
   881             <li>Let <var>localname set</var> be a new empty
   882                 <dfn title="concept-namespace-localname-set">namespace localname set</dfn>. This <var>localname
   882                 <dfn title="concept-namespace-localname-set">namespace localname set</dfn>. This <var>localname
   883                 set</var> will contain tuples of unique attribute 
   883                 set</var> will contain tuples of unique attribute
   884                 <code><a title="dom-attr-namespaceuri" data-spec="DOM4" class="externalDFN">namespaceURI</a></code>
   884                 <code><a title="dom-attr-namespaceuri" data-spec="DOM4" class="externalDFN">namespaceURI</a></code>
   885                 and <code><a title="dom-element-localname" data-spec="DOM4" class="externalDFN">localName</a></code>
   885                 and <code><a title="dom-element-localname" data-spec="DOM4" class="externalDFN">localName</a></code>
   886                 pairs, and is populated as each <var>attr</var> is processed.
   886                 pairs, and is populated as each <var>attr</var> is processed.
   887                 <span class="note">This set is used to [optionally] enforce the well-formed constraint that an 
   887                 <span class="note">This set is used to [optionally] enforce the well-formed constraint that an
   888                 element cannot have two attributes with the same 
   888                 element cannot have two attributes with the same
   889                 <code><a title="dom-attr-namespaceuri" data-spec="DOM4" class="externalDFN">namespaceURI</a></code>
   889                 <code><a title="dom-attr-namespaceuri" data-spec="DOM4" class="externalDFN">namespaceURI</a></code>
   890                 and <code><a title="dom-element-localname" data-spec="DOM4" class="externalDFN">localName</a></code>. 
   890                 and <code><a title="dom-element-localname" data-spec="DOM4" class="externalDFN">localName</a></code>.
   891                 This can occur when two otherwise identical attributes on the same element differ only by their 
   891                 This can occur when two otherwise identical attributes on the same element differ only by their
   892                 prefix values.</span>
   892                 prefix values.</span>
   893             <li><dfn title="serialize-attributes-loop">Main</dfn>: For each <a title="concept-attribute" data-spec="DOM4" class="externalDFN">attribute</a>
   893             <li><dfn title="serialize-attributes-loop">Main</dfn>: For each <a title="concept-attribute" data-spec="DOM4" class="externalDFN">attribute</a>
   894                 <var>attr</var> in <var>element</var>'s
   894                 <var>attr</var> in <var>element</var>'s
   895                 <code><a title="dom-element-attributes" data-spec="DOM4" class="externalDFN">attributes</a></code>,
   895                 <code><a title="dom-element-attributes" data-spec="DOM4" class="externalDFN">attributes</a></code>,
   896                 in the order they are specified in the <var>element</var>'s
   896                 in the order they are specified in the <var>element</var>'s
   897                 <a title="dom-element-attributes" data-spec="DOM4" class="externalDFN">attribute list</a>:
   897                 <a title="dom-element-attributes" data-spec="DOM4" class="externalDFN">attribute list</a>:
   898             <ol>
   898             <ol>
   899                 <li>If the <a title="concept-well-formed">require well-formed</a> flag is set (its value is 
   899                 <li>If the <a title="concept-well-formed">require well-formed</a> flag is set (its value is
   900                     <code>true</code>), and the <var>localname set</var> contains a tuple whose values match those 
   900                     <code>true</code>), and the <var>localname set</var> contains a tuple whose values match those
   901                     of a new tuple consisting of <var>attr</var>'s 
   901                     of a new tuple consisting of <var>attr</var>'s
   902                     <code><a title="dom-attr-namespaceuri" data-spec="DOM4" class="externalDFN">namespaceURI</a></code>
   902                     <code><a title="dom-attr-namespaceuri" data-spec="DOM4" class="externalDFN">namespaceURI</a></code>
   903                     attribute and <code><a title="dom-element-localname" data-spec="DOM4" class="externalDFN">localName</a></code>
   903                     attribute and <code><a title="dom-element-localname" data-spec="DOM4" class="externalDFN">localName</a></code>
   904                     attribute, then <a title="concept-algorithm-exception">throw an exception</a>; the serialization of this 
   904                     attribute, then <a title="concept-algorithm-exception">throw an exception</a>; the serialization of this
   905                     <var>attr</var> would fail to produce a well-formed element serialization.
   905                     <var>attr</var> would fail to produce a well-formed element serialization.
   906                 <li>Create a new tuple consisting of <var>attr</var>'s 
   906                 <li>Create a new tuple consisting of <var>attr</var>'s
   907                     <code><a title="dom-attr-namespaceuri" data-spec="DOM4" class="externalDFN">namespaceURI</a></code>
   907                     <code><a title="dom-attr-namespaceuri" data-spec="DOM4" class="externalDFN">namespaceURI</a></code>
   908                     attribute and <code><a title="dom-element-localname" data-spec="DOM4" class="externalDFN">localName</a></code>
   908                     attribute and <code><a title="dom-element-localname" data-spec="DOM4" class="externalDFN">localName</a></code>
   909                     attribute, and add it to the <var>localname set</var>.
   909                     attribute, and add it to the <var>localname set</var>.
   910                 <li>Let <var>attribute namespace</var> be the value of <var>attr</var>'s  
   910                 <li>Let <var>attribute namespace</var> be the value of <var>attr</var>'s
   911                     <code><a title="dom-attr-namespaceuri" data-spec="DOM4" class="externalDFN">namespaceURI</a></code>
   911                     <code><a title="dom-attr-namespaceuri" data-spec="DOM4" class="externalDFN">namespaceURI</a></code>
   912                     value.
   912                     value.
   913                 <!-- Check for an unregistered attribute namespace, and if so, serialize a definition for it -->
   913                 <!-- Check for an unregistered attribute namespace, and if so, serialize a definition for it -->
   914                 <li>Let <var>candidate prefix</var> be <code>null</code>.
   914                 <li>Let <var>candidate prefix</var> be <code>null</code>.
   915                 <li>If <var>attribute namespace</var> is not <code>null</code>, then run these sub-steps:
   915                 <li>If <var>attribute namespace</var> is not <code>null</code>, then run these sub-steps:
   916                 <ol>
   916                 <ol>
   917                     <li>If the value of <var>attribute namespace</var> is the 
   917                     <li>If the value of <var>attribute namespace</var> is the
   918                         <a title="xmlns-ns">XMLNS namespace</a> and either the <var>attr</var>'s 
   918                         <a title="xmlns-ns">XMLNS namespace</a> and either the <var>attr</var>'s
   919                         <code><a title="dom-attr-prefix" data-spec="DOM4" class="externalDFN">prefix</a></code>
   919                         <code><a title="dom-attr-prefix" data-spec="DOM4" class="externalDFN">prefix</a></code>
   920                         is <code>null</code> and the <var>ignore namespace definition 
   920                         is <code>null</code> and the <var>ignore namespace definition
   921                         attribute</var> flag is <code>true</code> or the <var>attr</var>'s 
   921                         attribute</var> flag is <code>true</code> or the <var>attr</var>'s
   922                         <code><a title="dom-attr-prefix" data-spec="DOM4" class="externalDFN">prefix</a></code>
   922                         <code><a title="dom-attr-prefix" data-spec="DOM4" class="externalDFN">prefix</a></code>
   923                         is not <code>null</code> and the <var>attr</var>'s 
   923                         is not <code>null</code> and the <var>attr</var>'s
   924                         <code><a title="dom-attr-localname" data-spec="DOM4" class="externalDFN">localName</a></code>
   924                         <code><a title="dom-attr-localname" data-spec="DOM4" class="externalDFN">localName</a></code>
   925                         matches the value of <var>duplicate prefix definition</var>, then stop running 
   925                         matches the value of <var>duplicate prefix definition</var>, then stop running
   926                         these steps and goto <a title="serialize-attributes-loop">Main</a> to visit the next attribute.
   926                         these steps and goto <a title="serialize-attributes-loop">Main</a> to visit the next attribute.
   927                     <li>Otherwise, if there exists a key in <var>map</var> that matches the value of <var>attribute 
   927                     <li>Otherwise, if there exists a key in <var>map</var> that matches the value of <var>attribute
   928                         namespace</var>, then let <var>candidate prefix</var> be that key's value from the 
   928                         namespace</var>, then let <var>candidate prefix</var> be that key's value from the
   929                         <var>map</var>.
   929                         <var>map</var>.
   930                     <li>Otherwise, there is no key matching <var>attribute namespace</var> in <var>map</var> and
   930                     <li>Otherwise, there is no key matching <var>attribute namespace</var> in <var>map</var> and
   931                         the <var>attribute namespace</var> is not the <a title="xmlns-ns">XMLNS namespace</a>. 
   931                         the <var>attribute namespace</var> is not the <a title="xmlns-ns">XMLNS namespace</a>.
   932                         Run these steps:
   932                         Run these steps:
   933                     <ol>
   933                     <ol>
   934                         <li>Let <var>candidate prefix</var> be the result of 
   934                         <li>Let <var>candidate prefix</var> be the result of
   935                             <a title="concept-generate-prefix">generating a prefix</a> providing <var>map</var>, 
   935                             <a title="concept-generate-prefix">generating a prefix</a> providing <var>map</var>,
   936                             <var>attribute namespace</var>, and <var>prefix index</var> as input.
   936                             <var>attribute namespace</var>, and <var>prefix index</var> as input.
   937                         <li>Append the following to <var>result</var>, in the order listed:
   937                         <li>Append the following to <var>result</var>, in the order listed:
   938                         <ol>
   938                         <ol>
   939                             <li>"<code> </code>" (U+0020 SPACE);
   939                             <li>"<code> </code>" (U+0020 SPACE);
   940                             <li>The string "<code>xmlns:</code>";
   940                             <li>The string "<code>xmlns:</code>";
   941                             <li>The value of <var>candidate prefix</var>;
   941                             <li>The value of <var>candidate prefix</var>;
   942                             <li>"<code>="</code>" (U+003D EQUALS SIGN, U+0022 QUOTATION MARK);
   942                             <li>"<code>="</code>" (U+003D EQUALS SIGN, U+0022 QUOTATION MARK);
   943                             <li>The result of <a title="concept-serialize-attr-value">serializing an attribute value</a> 
   943                             <li>The result of <a title="concept-serialize-attr-value">serializing an attribute value</a>
   944                                 given <var>attribute namespace</var> and the 
   944                                 given <var>attribute namespace</var> and the
   945                                 <a title="concept-well-formed">require well-formed</a> flag as input;
   945                                 <a title="concept-well-formed">require well-formed</a> flag as input;
   946                             <li>"<code>"</code>" (U+0022 QUOTATION MARK).
   946                             <li>"<code>"</code>" (U+0022 QUOTATION MARK).
   947                         </ol>
   947                         </ol>
   948                     </ol>
   948                     </ol>
   949                 </ol>
   949                 </ol>
   950                 <!-- A namespace prefix has been set by this point if it needed to be set -->
   950                 <!-- A namespace prefix has been set by this point if it needed to be set -->
   951                 <li>Append a "<code> </code>" (U+0020 SPACE) to <var>result</var>.
   951                 <li>Append a "<code> </code>" (U+0020 SPACE) to <var>result</var>.
   952                 <li>If <var>candidate prefix</var> is not <code>null</code>, then append to <var>result</var>
   952                 <li>If <var>candidate prefix</var> is not <code>null</code>, then append to <var>result</var>
   953                     the concatenation of <var>candidate prefix</var> with "<code>:</code>" (U+003A COLON).
   953                     the concatenation of <var>candidate prefix</var> with "<code>:</code>" (U+003A COLON).
   954                 <!-- Check for well-formed localName -->
   954                 <!-- Check for well-formed localName -->
   955                 <li>If the <a title="concept-well-formed">require well-formed</a> flag is set (its value is 
   955                 <li>If the <a title="concept-well-formed">require well-formed</a> flag is set (its value is
   956                     <code>true</code>), and this <var>attr</var>'s 
   956                     <code>true</code>), and this <var>attr</var>'s
   957                     <code><a title="dom-element-localname" data-spec="DOM4" class="externalDFN">localName</a></code>
   957                     <code><a title="dom-element-localname" data-spec="DOM4" class="externalDFN">localName</a></code>
   958                     attribute contains the character "<code>:</code>" (U+003A COLON) or does not match the XML 
   958                     attribute contains the character "<code>:</code>" (U+003A COLON) or does not match the XML
   959                     <code>Name</code> production [[XML10]] or equals "<code>xmlns</code>" and <var>attribute 
   959                     <code>Name</code> production [[XML10]] or equals "<code>xmlns</code>" and <var>attribute
   960                     namespace</var> is <code>null</code>, then <a title="concept-algorithm-exception">throw an 
   960                     namespace</var> is <code>null</code>, then <a title="concept-algorithm-exception">throw an
   961                     exception</a>; the serialization of this <var>attr</var> would not be a well-formed attribute.
   961                     exception</a>; the serialization of this <var>attr</var> would not be a well-formed attribute.
   962                 <!-- Write out the standard attribute -->
   962                 <!-- Write out the standard attribute -->
   963                 <li>Append the following strings to <var>result</var>, in the order listed:
   963                 <li>Append the following strings to <var>result</var>, in the order listed:
   964                 <ol>
   964                 <ol>
   965                     <li>The value of <var>attr</var>'s
   965                     <li>The value of <var>attr</var>'s
   966                         <code><a title="dom-attr-localname" data-spec="DOM4" class="externalDFN">localName</a></code>;
   966                         <code><a title="dom-attr-localname" data-spec="DOM4" class="externalDFN">localName</a></code>;
   967                     <li>"<code>="</code>" (U+003D EQUALS SIGN, U+0022 QUOTATION MARK);
   967                     <li>"<code>="</code>" (U+003D EQUALS SIGN, U+0022 QUOTATION MARK);
   968                     <li>The result of <a title="concept-serialize-attr-value">serializing an attribute value</a> 
   968                     <li>The result of <a title="concept-serialize-attr-value">serializing an attribute value</a>
   969                         given <var>attr</var>'s
   969                         given <var>attr</var>'s
   970                         <code><a title="concept-attribute-value" data-spec="DOM4" class="externalDFN">value</a></code>
   970                         <code><a title="concept-attribute-value" data-spec="DOM4" class="externalDFN">value</a></code>
   971                         attribute and the <a title="concept-well-formed">require well-formed</a> flag as input;
   971                         attribute and the <a title="concept-well-formed">require well-formed</a> flag as input;
   972                     <li>"<code>"</code>" (U+0022 QUOTATION MARK).
   972                     <li>"<code>"</code>" (U+0022 QUOTATION MARK).
   973                 </ol>
   973                 </ol>
   974             </ol>
   974             </ol>
   975             <li>Return the value of <var>result</var>.
   975             <li>Return the value of <var>result</var>.
   976         </ol>
   976         </ol>
   977         
   977 
   978         <p>To <dfn title="concept-serialize-attr-value">serialize an attribute value</dfn> given an 
   978         <p>To <dfn title="concept-serialize-attr-value">serialize an attribute value</dfn> given an
   979             <var>attribute value</var> and <a title="concept-well-formed">require well-formed</a> flag,
   979             <var>attribute value</var> and <a title="concept-well-formed">require well-formed</a> flag,
   980             the user agent must run the following steps:
   980             the user agent must run the following steps:
   981         <ol>
   981         <ol>
   982             <li>If the <a title="concept-well-formed">require well-formed</a> flag is set (its value is 
   982             <li>If the <a title="concept-well-formed">require well-formed</a> flag is set (its value is
   983                 <code>true</code>), and <var>attribute value</var> contains characters that are not matched 
   983                 <code>true</code>), and <var>attribute value</var> contains characters that are not matched
   984                 by the XML <code>Char</code> production [[XML10]], then 
   984                 by the XML <code>Char</code> production [[XML10]], then
   985                 <a title="concept-algorithm-exception">throw an exception</a>; the serialization of this 
   985                 <a title="concept-algorithm-exception">throw an exception</a>; the serialization of this
   986                 <var>attribute value</var> would fail to produce a well-formed element serialization.
   986                 <var>attribute value</var> would fail to produce a well-formed element serialization.
   987             <li>If <var>attribute value</var> is <code>null</code>, then return the empty string.
   987             <li>If <var>attribute value</var> is <code>null</code>, then return the empty string.
   988             <li>Otherwise, <var>attribute value</var> is a string. Return the value of 
   988             <li>Otherwise, <var>attribute value</var> is a string. Return the value of
   989                 <var>attribute value</var>, first replacing any occurrences of the following:
   989                 <var>attribute value</var>, first replacing any occurrences of the following:
   990             <ol>
   990             <ol>
   991                 <li>"<code>&quot;</code>" with "<code>&amp;quot;</code>"
   991                 <li>"<code>&quot;</code>" with "<code>&amp;quot;</code>"
   992                 <li>"<code>&amp;</code>" with "<code>&amp;amp;</code>"
   992                 <li>"<code>&amp;</code>" with "<code>&amp;amp;</code>"
   993                 <li>"<code>&lt;</code>" with "<code>&amp;lt;</code>"
   993                 <li>"<code>&lt;</code>" with "<code>&amp;lt;</code>"
  1000     </section>
  1000     </section>
  1001 </section>
  1001 </section>
  1002 
  1002 
  1003 <section>
  1003 <section>
  1004     <h1>The <code>DOMParser</code> interface</h1>
  1004     <h1>The <code>DOMParser</code> interface</h1>
  1005     
  1005 
  1006 <pre class=extraidl>enum <span class=idlInterfaceID>SupportedType</span> {
  1006 <pre class=extraidl>enum <span class=idlInterfaceID>SupportedType</span> {
  1007     "text/html",
  1007     "text/html",
  1008     "text/xml",
  1008     "text/xml",
  1009     "application/xml",
  1009     "application/xml",
  1010     "application/xhtml+xml",
  1010     "application/xhtml+xml",
  1048                     <li>Parse <var>str</var> with a namespace-enabled
  1048                     <li>Parse <var>str</var> with a namespace-enabled
  1049                     <code><a data-spec="HTML5" title="xml-parser" class="externalDFN">XML parser</a></code>.
  1049                     <code><a data-spec="HTML5" title="xml-parser" class="externalDFN">XML parser</a></code>.
  1050 
  1050 
  1051                     <p class="note">For all XHTML <code><a data-spec="HTML5" title="script" class="externalDFN">script</a></code>
  1051                     <p class="note">For all XHTML <code><a data-spec="HTML5" title="script" class="externalDFN">script</a></code>
  1052                         elements parsed using the <code><a data-spec="HTML5" title="xml-parser" class="externalDFN">XML parser</a></code>,
  1052                         elements parsed using the <code><a data-spec="HTML5" title="xml-parser" class="externalDFN">XML parser</a></code>,
  1053                         the equivalent of the <a data-spec="HTML5" title="scripting-flag" class="externalDFN">scripting flag</a> must 
  1053                         the equivalent of the <a data-spec="HTML5" title="scripting-flag" class="externalDFN">scripting flag</a> must
  1054                         be set to "disabled".</p>
  1054                         be set to "disabled".</p>
  1055 
  1055 
  1056                     <li>If the previous step didn't return an error, return the newly
  1056                     <li>If the previous step didn't return an error, return the newly
  1057                     created <a title="concept-document" data-spec="DOM4" class="externalDFN">document</a>.
  1057                     created <a title="concept-document" data-spec="DOM4" class="externalDFN">document</a>.
  1058 
  1058 
  1059                     <!-- This seemed like a good idea, but isn't web compatible, unfortunately.
  1059                     <!-- This seemed like a good idea, but isn't web compatible, unfortunately.
  1060                     <li>Otherwise, throw a 
  1060                     <li>Otherwise, throw a
  1061                     <code><a data-spec="DOM4" title="domexception" class="externalDFN">DOMException</a></code> 
  1061                     <code><a data-spec="DOM4" title="domexception" class="externalDFN">DOMException</a></code>
  1062                     with name <code>SyntaxError</code>. -->
  1062                     with name <code>SyntaxError</code>. -->
  1063                     
  1063 
  1064                     <li>Let <var>document</var> be a newly-created
  1064                     <li>Let <var>document</var> be a newly-created
  1065                     <a data-spec="DOM4" title="xml-document" class="externalDFN">XML Document</a>.
  1065                     <a data-spec="DOM4" title="xml-document" class="externalDFN">XML Document</a>.
  1066                     <span class="note">The <var>document</var> will use the 
  1066                     <span class="note">The <var>document</var> will use the
  1067                     <code><a data-spec="DOM4" title="document" class="externalDFN">Document</a></code> interface
  1067                     <code><a data-spec="DOM4" title="document" class="externalDFN">Document</a></code> interface
  1068                     rather than the <code><a data-spec="DOM4" title="xmldocument" class="externalDFN">XMLDocument</a></code>
  1068                     rather than the <code><a data-spec="DOM4" title="xmldocument" class="externalDFN">XMLDocument</a></code>
  1069                     interface.</span>
  1069                     interface.</span>
  1070 
  1070 
  1071                     <li>
  1071                     <li>
  1090             </dl>
  1090             </dl>
  1091 
  1091 
  1092             <p>In any case, the returned
  1092             <p>In any case, the returned
  1093             <a title="concept-document" data-spec="DOM4" class="externalDFN">document</a>'s
  1093             <a title="concept-document" data-spec="DOM4" class="externalDFN">document</a>'s
  1094             <a title="concept-document-content-type" data-spec="DOM4" class="externalDFN">content type</a>
  1094             <a title="concept-document-content-type" data-spec="DOM4" class="externalDFN">content type</a>
  1095             must be the <var>type</var> argument. Additionally, the 
  1095             must be the <var>type</var> argument. Additionally, the
  1096             <a title="concept-document" data-spec="DOM4" class="externalDFN">document</a> must have a
  1096             <a title="concept-document" data-spec="DOM4" class="externalDFN">document</a> must have a
  1097             <a title="concept-document-url" data-spec="DOM4" class="externalDFN">URL</a> value equal to 
  1097             <a title="concept-document-url" data-spec="DOM4" class="externalDFN">URL</a> value equal to
  1098             the URL of the 
  1098             the URL of the
  1099             <a title="active-document" data-spec="HTML5" class="externalDFN">active document</a>, a 
  1099             <a title="active-document" data-spec="HTML5" class="externalDFN">active document</a>, a
  1100             <a title="location" data-spec="HTML5" class="externalDFN">location</a> value of <code>null</code>.
  1100             <a title="location" data-spec="HTML5" class="externalDFN">location</a> value of <code>null</code>.
  1101 
  1101 
  1102             <p class=note>The returned
  1102             <p class=note>The returned
  1103             <a title="concept-document" data-spec="DOM4" class="externalDFN">document</a>'s
  1103             <a title="concept-document" data-spec="DOM4" class="externalDFN">document</a>'s
  1104             <a title="concept-document-encoding" data-spec="DOM4" class="externalDFN">encoding</a> is
  1104             <a title="concept-document-encoding" data-spec="DOM4" class="externalDFN">encoding</a> is
  1115 
  1115 
  1116     <dl class="idl" title="[Constructor] interface XMLSerializer">
  1116     <dl class="idl" title="[Constructor] interface XMLSerializer">
  1117         <dt>DOMString serializeToString(Node root)</dt>
  1117         <dt>DOMString serializeToString(Node root)</dt>
  1118 
  1118 
  1119         <dd>The <dfn title="dom-xmlserializer-serializetostring"><code>serializeToString(<var>root</var>)</code></dfn>
  1119         <dd>The <dfn title="dom-xmlserializer-serializetostring"><code>serializeToString(<var>root</var>)</code></dfn>
  1120         method must <a title="concept-serialize-xml">produce an XML serialization</a> of <var>root</var> passing 
  1120         method must <a title="concept-serialize-xml">produce an XML serialization</a> of <var>root</var> passing
  1121         a value of <code>false</code> for the <a title="concept-well-formed">require well-formed</a> parameter, and return the result.</dd>
  1121         a value of <code>false</code> for the <a title="concept-well-formed">require well-formed</a> parameter, and return the result.</dd>
  1122     </dl>
  1122     </dl>
  1123 </section>
  1123 </section>
  1124 
  1124 
  1125 <section>
  1125 <section>
  1160                 <p>Can be set, to replace the contents of the element with nodes
  1160                 <p>Can be set, to replace the contents of the element with nodes
  1161                 parsed from the given string.
  1161                 parsed from the given string.
  1162 
  1162 
  1163                 <p>In the case of an <a title="xml-document" data-spec="DOM4" class="externalDFN">XML document</a>,
  1163                 <p>In the case of an <a title="xml-document" data-spec="DOM4" class="externalDFN">XML document</a>,
  1164                 will throw a
  1164                 will throw a
  1165                 <code><a data-spec="DOM4" title="domexception" class="externalDFN">DOMException</a></code> with name 
  1165                 <code><a data-spec="DOM4" title="domexception" class="externalDFN">DOMException</a></code> with name
  1166                 "<code><a data-spec="DOM4" title="invalidstateerror" class="externalDFN">InvalidStateError</a></code>"
  1166                 "<code><a data-spec="DOM4" title="invalidstateerror" class="externalDFN">InvalidStateError</a></code>"
  1167                 if the <code><a title="element" data-spec="DOM4" class="externalDFN">Element</a></code> cannot be serialized
  1167                 if the <code><a title="element" data-spec="DOM4" class="externalDFN">Element</a></code> cannot be serialized
  1168                 to XML, and a
  1168                 to XML, and a
  1169                 <code><a data-spec="DOM4" title="domexception" class="externalDFN">DOMException</a></code> with name 
  1169                 <code><a data-spec="DOM4" title="domexception" class="externalDFN">DOMException</a></code> with name
  1170                 "<code><a data-spec="DOM4" title="syntaxerror" class="externalDFN">SyntaxError</a></code>"
  1170                 "<code><a data-spec="DOM4" title="syntaxerror" class="externalDFN">SyntaxError</a></code>"
  1171                 if the given string is not well-formed.
  1171                 if the given string is not well-formed.
  1172             </dl>
  1172             </dl>
  1173 
  1173 
  1174             <p>On getting, return the result of invoking the 
  1174             <p>On getting, return the result of invoking the
  1175                 <a title="concept-fragment-serializing-algorithm">fragment serializing algorithm</a> on the 
  1175                 <a title="concept-fragment-serializing-algorithm">fragment serializing algorithm</a> on the
  1176                 <a title="context object">context object</a> providing <code>true</code> for the 
  1176                 <a title="context object">context object</a> providing <code>true</code> for the
  1177                 <a title="concept-well-formed">require well-formed</a> flag (this might throw an exception 
  1177                 <a title="concept-well-formed">require well-formed</a> flag (this might throw an exception
  1178                 instead of returning a string).
  1178                 instead of returning a string).
  1179 
  1179 
  1180             <p>On setting, these steps must be run:
  1180             <p>On setting, these steps must be run:
  1181             <ol>
  1181             <ol>
  1182                 <li>Let <var>fragment</var> be the result of invoking the
  1182                 <li>Let <var>fragment</var> be the result of invoking the
  1205                 <p>Can be set, to replace the element with nodes parsed from the given
  1205                 <p>Can be set, to replace the element with nodes parsed from the given
  1206                 string.
  1206                 string.
  1207 
  1207 
  1208                 <p>In the case of an <a title="xml-document" data-spec="DOM4" class="externalDFN">XML document</a>,
  1208                 <p>In the case of an <a title="xml-document" data-spec="DOM4" class="externalDFN">XML document</a>,
  1209                 will throw a
  1209                 will throw a
  1210                 <code><a data-spec="DOM4" title="domexception" class="externalDFN">DOMException</a></code> with name 
  1210                 <code><a data-spec="DOM4" title="domexception" class="externalDFN">DOMException</a></code> with name
  1211                 "<code><a data-spec="DOM4" title="invalidstateerror" class="externalDFN">InvalidStateError</a></code>"
  1211                 "<code><a data-spec="DOM4" title="invalidstateerror" class="externalDFN">InvalidStateError</a></code>"
  1212                 if the element cannot be serialized to XML, and a
  1212                 if the element cannot be serialized to XML, and a
  1213                 <code><a data-spec="DOM4" title="domexception" class="externalDFN">DOMException</a></code> with name 
  1213                 <code><a data-spec="DOM4" title="domexception" class="externalDFN">DOMException</a></code> with name
  1214                 "<code><a data-spec="DOM4" title="syntaxerror" class="externalDFN">SyntaxError</a></code>"
  1214                 "<code><a data-spec="DOM4" title="syntaxerror" class="externalDFN">SyntaxError</a></code>"
  1215                 if the given string is not well-formed.
  1215                 if the given string is not well-formed.
  1216 
  1216 
  1217                 <p>Throws a
  1217                 <p>Throws a
  1218                 <code><a data-spec="DOM4" title="domexception" class="externalDFN">DOMException</a></code> with name 
  1218                 <code><a data-spec="DOM4" title="domexception" class="externalDFN">DOMException</a></code> with name
  1219                 "<code><a data-spec="DOM4" title="nomodificationallowederror" class="externalDFN">NoModificationAllowedError</a></code>"
  1219                 "<code><a data-spec="DOM4" title="nomodificationallowederror" class="externalDFN">NoModificationAllowedError</a></code>"
  1220                 if the parent of the element is the
  1220                 if the parent of the element is the
  1221                 <code><a title="document" data-spec="DOM4" class="externalDFN">Document</a></code> node.
  1221                 <code><a title="document" data-spec="DOM4" class="externalDFN">Document</a></code> node.
  1222             </dl>
  1222             </dl>
  1223 
  1223 
  1224             <p>On getting, return the result of invoking the 
  1224             <p>On getting, return the result of invoking the
  1225                 <a title="concept-fragment-serializing-algorithm">fragment serializing algorithm</a> on a 
  1225                 <a title="concept-fragment-serializing-algorithm">fragment serializing algorithm</a> on a
  1226                 fictional node whose only child is the <a title="context object">context object</a>
  1226                 fictional node whose only child is the <a title="context object">context object</a>
  1227                 providing <code>true</code> for the <a title="concept-well-formed">require well-formed</a>
  1227                 providing <code>true</code> for the <a title="concept-well-formed">require well-formed</a>
  1228                 flag (this might throw an exception instead of returning a string).
  1228                 flag (this might throw an exception instead of returning a string).
  1229 
  1229 
  1230             <p>On setting, the following steps must be run:
  1230             <p>On setting, the following steps must be run:
  1237                 way to obtain a reference to the nodes created even if the remaining steps
  1237                 way to obtain a reference to the nodes created even if the remaining steps
  1238                 were run.
  1238                 were run.
  1239 
  1239 
  1240                 <li>If <var>parent</var> is a
  1240                 <li>If <var>parent</var> is a
  1241                 <code><a title="document" data-spec="DOM4" class="externalDFN">Document</a></code>, throw a
  1241                 <code><a title="document" data-spec="DOM4" class="externalDFN">Document</a></code>, throw a
  1242                 <code><a data-spec="DOM4" title="domexception" class="externalDFN">DOMException</a></code> with name 
  1242                 <code><a data-spec="DOM4" title="domexception" class="externalDFN">DOMException</a></code> with name
  1243                 "<code><a data-spec="DOM4" title="nomodificationallowederror" class="externalDFN">NoModificationAllowedError</a></code>"
  1243                 "<code><a data-spec="DOM4" title="nomodificationallowederror" class="externalDFN">NoModificationAllowedError</a></code>"
  1244                 exception.
  1244                 exception.
  1245 
  1245 
  1246                 <li>If <var>parent</var> is a
  1246                 <li>If <var>parent</var> is a
  1247                 <code><a title="documentfragment" data-spec="DOM4" class="externalDFN">DocumentFragment</a></code>, let
  1247                 <code><a title="documentfragment" data-spec="DOM4" class="externalDFN">DocumentFragment</a></code>, let
  1295 
  1295 
  1296                       <dt>"afterend"
  1296                       <dt>"afterend"
  1297                       <dd>After the element itself.
  1297                       <dd>After the element itself.
  1298                     </dl>
  1298                     </dl>
  1299 
  1299 
  1300                     <p>Throws a <code><a data-spec="DOM4" title="domexception" class="externalDFN">DOMException</a></code> with name 
  1300                     <p>Throws a <code><a data-spec="DOM4" title="domexception" class="externalDFN">DOMException</a></code> with name
  1301                     "<code><a data-spec="DOM4" title="syntaxerror" class="externalDFN">SyntaxError</a></code>"
  1301                     "<code><a data-spec="DOM4" title="syntaxerror" class="externalDFN">SyntaxError</a></code>"
  1302                     if the arguments have invalid values (e.g., in the case of an
  1302                     if the arguments have invalid values (e.g., in the case of an
  1303                     <a data-spec="DOM4" title="xml-document" class="externalDFN">XML document</a>, if the given string is
  1303                     <a data-spec="DOM4" title="xml-document" class="externalDFN">XML document</a>, if the given string is
  1304                     not well-formed).
  1304                     not well-formed).
  1305 
  1305 
  1306                     <p>Throws a
  1306                     <p>Throws a
  1307                     <code><a data-spec="DOM4" title="domexception" class="externalDFN">DOMException</a></code> with name 
  1307                     <code><a data-spec="DOM4" title="domexception" class="externalDFN">DOMException</a></code> with name
  1308                     "<code><a data-spec="DOM4" title="nomodificationallowederror" class="externalDFN">NoModificationAllowedError</a></code>"
  1308                     "<code><a data-spec="DOM4" title="nomodificationallowederror" class="externalDFN">NoModificationAllowedError</a></code>"
  1309                     if the given position isn't possible (e.g. inserting elements
  1309                     if the given position isn't possible (e.g. inserting elements
  1310                     after the root element of a <code><a title="document" data-spec="DOM4" class="externalDFN">Document</a></code>).
  1310                     after the root element of a <code><a title="document" data-spec="DOM4" class="externalDFN">Document</a></code>).
  1311                 </dl>
  1311                 </dl>
  1312 
  1312 
  1331                             <a data-spec="DOM4" title="concept-tree-parent" class="externalDFN">parent</a>.
  1331                             <a data-spec="DOM4" title="concept-tree-parent" class="externalDFN">parent</a>.
  1332 
  1332 
  1333                             <p>If <var>context</var> is null or a
  1333                             <p>If <var>context</var> is null or a
  1334                             <a data-spec="DOM4" class="externalDFN" title="concept-document">document</a>, throw
  1334                             <a data-spec="DOM4" class="externalDFN" title="concept-document">document</a>, throw
  1335                             a
  1335                             a
  1336                             <code><a data-spec="DOM4" title="domexception" class="externalDFN">DOMException</a></code> with name 
  1336                             <code><a data-spec="DOM4" title="domexception" class="externalDFN">DOMException</a></code> with name
  1337                             "<code><a data-spec="DOM4" title="nomodificationallowederror" class="externalDFN">NoModificationAllowedError</a></code>".
  1337                             "<code><a data-spec="DOM4" title="nomodificationallowederror" class="externalDFN">NoModificationAllowedError</a></code>".
  1338 
  1338 
  1339                         <dt>If <var>position</var> is an
  1339                         <dt>If <var>position</var> is an
  1340                         <a data-spec="DOM4" class="externalDFN" title="ascii-case-insensitive">ASCII case-insensitive</a> match for
  1340                         <a data-spec="DOM4" class="externalDFN" title="ascii-case-insensitive">ASCII case-insensitive</a> match for
  1341                         the string "afterbegin"
  1341                         the string "afterbegin"
  1384                       as its
  1384                       as its
  1385                       <a title="concept-node-document" data-spec="DOM4" class="externalDFN">node document</a>.
  1385                       <a title="concept-node-document" data-spec="DOM4" class="externalDFN">node document</a>.
  1386                     </ul>
  1386                     </ul>
  1387 
  1387 
  1388                 <li>Let <var>fragment</var> be the result of invoking the
  1388                 <li>Let <var>fragment</var> be the result of invoking the
  1389                 <a title="concept-parse-fragment">fragment parsing algorithm</a> with <var>text</var> as 
  1389                 <a title="concept-parse-fragment">fragment parsing algorithm</a> with <var>text</var> as
  1390                 <var>markup</var>, and <var>context</var> as the <var>context element</var>.
  1390                 <var>markup</var>, and <var>context</var> as the <var>context element</var>.
  1391 
  1391 
  1392                 <li>Use the first matching item from this list:
  1392                 <li>Use the first matching item from this list:
  1393 
  1393 
  1394                 <dl class=switch>
  1394                 <dl class=switch>
  1395                     <dt>If <var>position</var> is an
  1395                     <dt>If <var>position</var> is an
  1396                     <a data-spec="DOM4" class="externalDFN" title="ascii-case-insensitive">ASCII case-insensitive</a> match for
  1396                     <a data-spec="DOM4" class="externalDFN" title="ascii-case-insensitive">ASCII case-insensitive</a> match for
  1397                     the string "beforebegin"
  1397                     the string "beforebegin"
  1398             
  1398 
  1399                     <dd><a data-spec="DOM4" title="concept-node-insert" class="externalDFN">Insert</a>
  1399                     <dd><a data-spec="DOM4" title="concept-node-insert" class="externalDFN">Insert</a>
  1400                     <var>fragment</var> into the <a title="context object">context object</a>'s
  1400                     <var>fragment</var> into the <a title="context object">context object</a>'s
  1401                     <a data-spec="DOM4" title="concept-tree-parent" class="externalDFN">parent</a>
  1401                     <a data-spec="DOM4" title="concept-tree-parent" class="externalDFN">parent</a>
  1402                     before the <a title="context object">context object</a>.
  1402                     before the <a title="context object">context object</a>.
  1403 
  1403 
  1536                       as its
  1536                       as its
  1537                       <a title="concept-node-document" data-spec="DOM4" class="externalDFN">node document</a>.
  1537                       <a title="concept-node-document" data-spec="DOM4" class="externalDFN">node document</a>.
  1538                     </ul>
  1538                     </ul>
  1539 
  1539 
  1540                 <li>Let <var>fragment node</var> be the result of invoking the
  1540                 <li>Let <var>fragment node</var> be the result of invoking the
  1541                 <a title="concept-parse-fragment">fragment parsing algorithm</a> with <var>fragment</var> as 
  1541                 <a title="concept-parse-fragment">fragment parsing algorithm</a> with <var>fragment</var> as
  1542                 <var>markup</var>, and <var>element</var> as the <var>context element</var>.
  1542                 <var>markup</var>, and <var>element</var> as the <var>context element</var>.
  1543 
  1543 
  1544                 <li>Unmark all scripts in <var>fragment node</var> as "already started".
  1544                 <li>Unmark all scripts in <var>fragment node</var> as "already started".
  1545 
  1545 
  1546                 <li>Return the value of <var>fragment node</var>.
  1546                 <li>Return the value of <var>fragment node</var>.
  1549     </dl>
  1549     </dl>
  1550 </section>
  1550 </section>
  1551 
  1551 
  1552 <section class="appendix">
  1552 <section class="appendix">
  1553     <h1>Acknowledgements</h1>
  1553     <h1>Acknowledgements</h1>
  1554     <p>Thanks to Ms2ger [<a href="http://www.mozilla.org">Mozilla</a>] for maintaining the initial 
  1554     <p>Thanks to Ms2ger [<a href="http://www.mozilla.org">Mozilla</a>] for maintaining the initial
  1555        drafts of this specification and for its continued improvement in the 
  1555        drafts of this specification and for its continued improvement in the
  1556        <a href="http://domparsing.spec.whatwg.org/">Living Specification</a>.
  1556        <a href="http://domparsing.spec.whatwg.org/">Living Specification</a>.
  1557 
  1557 
  1558     <p>Thanks to Anne van Kesteren, Aryeh Gregor, Boris Zbarsky, Henri Sivonen, Simon Pieters, Victor Costan, and timeless
  1558     <p>Thanks to Anne van Kesteren, Aryeh Gregor, Boris Zbarsky, Henri Sivonen, Simon Pieters, Victor Costan, and timeless
  1559     for their useful comments.
  1559     for their useful comments.
  1560 
  1560 
  1565     [[HTML5]] and his useful comments.
  1565     [[HTML5]] and his useful comments.
  1566 </section>
  1566 </section>
  1567 
  1567 
  1568    <script>
  1568    <script>
  1569       try {
  1569       try {
  1570         var urlMap = { 
  1570         var urlMap = {
  1571             "DOM4": "http://www.w3.org/TR/dom/#",
  1571             "DOM4": "http://www.w3.org/TR/dom/#",
  1572             "HTML5": "http://www.w3.org/TR/html5/single-page.html#",
  1572             "HTML5": "http://www.w3.org/TR/html5/single-page.html#",
  1573         };
  1573         };
  1574         [].forEach.call(document.querySelectorAll("[class=externalDFN]"), function (el) {
  1574         [].forEach.call(document.querySelectorAll("[class=externalDFN]"), function (el) {
  1575             var key = el.getAttribute("data-spec");
  1575             var key = el.getAttribute("data-spec");