index.html
changeset 55 49c41bbec2b4
parent 54 2d082ea2c1ab
child 56 b9d2104e193a
equal deleted inserted replaced
54:2d082ea2c1ab 55:49c41bbec2b4
   242 
   242 
   243     <section>
   243     <section>
   244         <h2>Serializing</h2>
   244         <h2>Serializing</h2>
   245         <p>The following steps form the 
   245         <p>The following steps form the 
   246             <dfn title="concept-fragment-serializing-algorithm">fragment serializing algorithm</dfn>,
   246             <dfn title="concept-fragment-serializing-algorithm">fragment serializing algorithm</dfn>,
   247             whose arguments are a <a title="node" data-spec="DOM4" class="externalDFN">Node</a> 
   247             whose arguments are a <code><a title="node" data-spec="DOM4" class="externalDFN">Node</a></code> 
   248             <var>node</var> and a flag <dfn title="concept-well-formed">require well-formed</dfn>.
   248             <var>node</var> and a flag <dfn title="concept-well-formed">require well-formed</dfn>.
   249 
   249 
   250         <ol>
   250         <ol>
   251             <li>Let <var>context document</var> be <var>node</var>'s
   251             <li>Let <var>context document</var> be <var>node</var>'s
   252                 <a title="concept-node-document" data-spec="DOM4" class="externalDFN">node document</a>.
   252                 <a title="concept-node-document" data-spec="DOM4" class="externalDFN">node document</a>.
   261                 conforms to the requirements of the <a data-spec="HTML5" title="xml-fragment-serialization-algorithm" 
   261                 conforms to the requirements of the <a data-spec="HTML5" title="xml-fragment-serialization-algorithm" 
   262                 class="externalDFN">XML fragment serialization algorithm</a> defined in [[HTML5]].</p>
   262                 class="externalDFN">XML fragment serialization algorithm</a> defined in [[HTML5]].</p>
   263         </ol>
   263         </ol>
   264 
   264 
   265         <p>To produce an <dfn title="concept-serialize-html">HTML serialization</dfn> of a
   265         <p>To produce an <dfn title="concept-serialize-html">HTML serialization</dfn> of a
   266             <a title="node" data-spec="DOM4" class="externalDFN">Node</a> <var>node</var>, the user agent
   266             <code><a title="node" data-spec="DOM4" class="externalDFN">Node</a></code> <var>node</var>, the user agent
   267             must run the
   267             must run the
   268             <a data-spec="HTML5" title="html-fragment-serialization-algorithm" class="externalDFN">HTML 
   268             <a data-spec="HTML5" title="html-fragment-serialization-algorithm" class="externalDFN">HTML 
   269             fragment serialization algorithm</a> [[!HTML5]] on <var>node</var> and return the string produced.
   269             fragment serialization algorithm</a> [[!HTML5]] on <var>node</var> and return the string produced.
   270 
   270 
   271         <p>To produce an <dfn title="concept-serialize-xml">XML serialization</dfn> of a
   271         <p>To produce an <dfn title="concept-serialize-xml">XML serialization</dfn> of a
   272             <a title="node" data-spec="DOM4" class="externalDFN">Node</a> <var>node</var> given a
   272             <code><a title="node" data-spec="DOM4" class="externalDFN">Node</a></code> <var>node</var> given a
   273             flag <var>require well-formed</var>, run the following steps:
   273             flag <var>require well-formed</var>, run the following steps:
   274         <ol>
   274         <ol>
   275             <li>Let <dfn title="concept-context-namespace">context namespace</dfn> be <code>null</code>.
   275             <li>Let <dfn title="concept-context-namespace">context namespace</dfn> be <code>null</code>.
   276                 The <a title="concept-context-namespace">context namespace</a> is changed when a
   276                 The <a title="concept-context-namespace">context namespace</a> is changed when a
   277                 <var>node</var> serializes a different default namespace definition from its parent. The 
   277                 <var>node</var> serializes a different default namespace definition from its parent. The 
   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]], <a title="interface-attr" data-spec="DOM4" class="externalDFN">Attr</a>
   329         <p class="note">Per [[DOM4]], <code><a title="interface-attr" data-spec="DOM4" class="externalDFN">Attr</a></code>
   330             objects are not <a title="node" data-spec="DOM4" class="externalDFN">Node</a>s, 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 <a title="interface-attr" data-spec="DOM4" class="externalDFN">Attr</a>
   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 TypeError 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>
   381                     <ol>
   381                     <ol>
   382                         <li>If <var>local default namespace</var> is not <code>null</code>, then set <var>ignore 
   382                         <li>If <var>local default namespace</var> is not <code>null</code>, then set <var>ignore 
   383                             namespace definition attribute</var> to <code>true</code>.
   383                             namespace definition attribute</var> to <code>true</code>.
   384                         <li>If <var>ns</var> is the <a title="xml-ns">XML namespace</a>, then let <var>qualified name</var> 
   384                         <li>If <var>ns</var> is the <a title="xml-ns">XML namespace</a>, then let <var>qualified name</var> 
   385                             be the concatenation of the string "<code>xml:</code>" and the value of <var>node</var>'s 
   385                             be the concatenation of the string "<code>xml:</code>" and the value of <var>node</var>'s 
   386                             <a title="dom-element-localname" data-spec="DOM4" class="externalDFN">localName</a>.
   386                             <code><a title="dom-element-localname" data-spec="DOM4" class="externalDFN">localName</a></code>.
   387                         <li>Otherwise, let <var>qualified name</var> be the value of <var>node</var>'s 
   387                         <li>Otherwise, let <var>qualified name</var> be the value of <var>node</var>'s 
   388                             <a title="dom-element-localname" data-spec="DOM4" class="externalDFN">localName</a>.
   388                             <code><a title="dom-element-localname" data-spec="DOM4" class="externalDFN">localName</a></code>.
   389                             <span class="note">The <var>node</var>'s prefix is always dropped.</span>
   389                             <span class="note">The <var>node</var>'s prefix is always dropped.</span>
   390                         <li>Append the value of <var>qualified name</var> to <var>markup</var>.
   390                         <li>Append the value of <var>qualified name</var> to <var>markup</var>.
   391                     </ol>
   391                     </ol>
   392                     <li>Otherwise, <var>inherited ns</var> is not equal to <var>ns</var> (the <var>node</var>'s
   392                     <li>Otherwise, <var>inherited ns</var> is not equal to <var>ns</var> (the <var>node</var>'s
   393                         own namespace is different from the context namespace of its parent). Run these sub-steps:
   393                         own namespace is different from the context namespace of its parent). Run these sub-steps:
   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                         <a title="the-template-element" data-spec="HTML5" class="externalDFN">template</a> 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 <a title="interface-documentfragment" data-spec="DOM4" class="externalDFN">DocumentFragment</a>),
   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
   567 
   567 
   568             <dt><code><a title="interface-document" data-spec="DOM4" class="externalDFN">Document</a></code>
   568             <dt><code><a title="interface-document" data-spec="DOM4" class="externalDFN">Document</a></code>
   569             <dd>
   569             <dd>
   570                 <p>If the <a title="concept-well-formed">require well-formed</a> flag is set (its value is 
   570                 <p>If the <a title="concept-well-formed">require well-formed</a> flag is set (its value is 
   571                     <code>true</code>), and this <var>node</var> has no 
   571                     <code>true</code>), and this <var>node</var> has no 
   572                     <a title="dom-document-documentelement" data-spec="HTML5" class="externalDFN">documentElement</a>
   572                     <code><a title="dom-document-documentelement" data-spec="HTML5" class="externalDFN">documentElement</a></code>
   573                     (the <a title="dom-document-documentelement" data-spec="HTML5" class="externalDFN">documentElement</a>
   573                     (the <code><a title="dom-document-documentelement" data-spec="HTML5" class="externalDFN">documentElement</a></code>
   574                     attribute's value is <code>null</code>), then <a title="concept-algorithm-exception">throw an 
   574                     attribute's value is <code>null</code>), then <a title="concept-algorithm-exception">throw an 
   575                     exception</a>; the serialization of this <var>node</var> would not be a well-formed document.
   575                     exception</a>; the serialization of this <var>node</var> would not be a well-formed document.
   576                 <p>Otherwise, run the following steps:
   576                 <p>Otherwise, run the following steps:
   577                 <ol>
   577                 <ol>
   578                     <li>Let <var>serialized document</var> be an empty string.
   578                     <li>Let <var>serialized document</var> be an empty string.
   579                     <li>Append to <var>serialized document</var> the string produced by running the steps to 
   579                     <li>Append to <var>serialized document</var> the string produced by running the steps to 
   580                         <a title="concept-serialize-doctype">produce a DocumentType serialization</a>
   580                         <a title="concept-serialize-doctype">produce a DocumentType serialization</a>
   581                         of <var>node</var>'s 
   581                         of <var>node</var>'s 
   582                         <a title="dom-document-doctype" data-spec="HTML5" class="externalDFN">doctype</a>
   582                         <code><a title="dom-document-doctype" data-spec="HTML5" class="externalDFN">doctype</a></code>
   583                         attribute provided the <var>require well-formed</var> flag if <var>node</var>'s 
   583                         attribute provided the <var>require well-formed</var> flag if <var>node</var>'s 
   584                         <a title="dom-document-doctype" data-spec="HTML5" class="externalDFN">doctype</a>
   584                         <code><a title="dom-document-doctype" data-spec="HTML5" class="externalDFN">doctype</a></code>
   585                         attribute is not <code>null</code>.
   585                         attribute is not <code>null</code>.
   586                     <li>For each
   586                     <li>For each
   587                         <a title="concept-tree-child" data-spec="DOM4" class="externalDFN">child</a> of 
   587                         <a title="concept-tree-child" data-spec="DOM4" class="externalDFN">child</a> of 
   588                         <var>node</var>, in order, run the 
   588                         <var>node</var>, in order, run the 
   589                         <a title="concept-xml-serialization-algorithm">XML serialization algorithm</a>
   589                         <a title="concept-xml-serialization-algorithm">XML serialization algorithm</a>
   704               </ol>
   704               </ol>
   705               
   705               
   706         </dl>
   706         </dl>
   707 
   707 
   708         <p>To <dfn title="concept-serialize-doctype">produce a DocumentType serialization</dfn> of a
   708         <p>To <dfn title="concept-serialize-doctype">produce a DocumentType serialization</dfn> of a
   709             <a title="node" data-spec="DOM4" class="externalDFN">Node</a> <var>node</var>, given a 
   709             <code><a title="node" data-spec="DOM4" class="externalDFN">Node</a></code> <var>node</var>, given a 
   710             <a title="concept-well-formed">require well-formed</a> flag, the user agent must return 
   710             <a title="concept-well-formed">require well-formed</a> flag, the user agent must return 
   711             the result of the following algorithm:</p>
   711             the result of the following algorithm:</p>
   712                 
   712                 
   713         <ol>
   713         <ol>
   714             <li>If the <a title="concept-well-formed">require well-formed</a> flag is <code>true</code>
   714             <li>If the <a title="concept-well-formed">require well-formed</a> flag is <code>true</code>
   794             -->
   794             -->
   795             <li>Append "<code>&gt;</code>" (U+003E GREATER-THAN SIGN) to <var>markup</var>.
   795             <li>Append "<code>&gt;</code>" (U+003E GREATER-THAN SIGN) to <var>markup</var>.
   796         </ol>
   796         </ol>
   797 
   797 
   798         <p>To <dfn title="concept-record-namespace-info">record the namespace information</dfn> for an 
   798         <p>To <dfn title="concept-record-namespace-info">record the namespace information</dfn> for an 
   799             <a title="element" data-spec="DOM4" class="externalDFN">Element</a> <var>element</var>, given a 
   799             <code><a title="element" data-spec="DOM4" class="externalDFN">Element</a></code> <var>element</var>, given a 
   800             <a title="concept-namespace-prefix-map">namespace prefix map</a> <var>map</var>, an
   800             <a title="concept-namespace-prefix-map">namespace prefix map</a> <var>map</var>, an
   801             <var>element prefixes list</var> (initially empty), and a <var>duplicate prefix 
   801             <var>element prefixes list</var> (initially empty), and a <var>duplicate prefix 
   802             definition</var> reference, the user agent must run the following steps:
   802             definition</var> reference, the user agent must run the following steps:
   803         <ol>
   803         <ol>
   804             <li>Let <var>default namespace attr value</var> be <code>null</code>.
   804             <li>Let <var>default namespace attr value</var> be <code>null</code>.
   805             <li>For each <a title="concept-attribute" data-spec="DOM4" class="externalDFN">attribute</a>
   805             <li>For each <a title="concept-attribute" data-spec="DOM4" class="externalDFN">attribute</a>
   806                 <var>attr</var> in <var>element</var>'s
   806                 <var>attr</var> in <var>element</var>'s
   807                 <a title="concept-element-attribute" data-spec="DOM4" class="externalDFN">attributes</a>,
   807                 <code><a title="dom-element-attributes" data-spec="DOM4" class="externalDFN">attributes</a></code>,
   808                 in order:
   808                 in order:
   809             <ol>
   809             <ol>
   810                 <p class="note">The following conditional steps add namespace prefixes
   810                 <p class="note">The following conditional steps add namespace prefixes
   811                     into the <var>element prefixes list</var> and add or replace them in the <var>map</var>. 
   811                     into the <var>element prefixes list</var> and add or replace them in the <var>map</var>. 
   812                     Only attributes in the <a title="xmlns-ns">XMLNS namespace</a> are
   812                     Only attributes in the <a title="xmlns-ns">XMLNS namespace</a> are
   813                     considered (e.g., attributes made to look like namespace declarations via 
   813                     considered (e.g., attributes made to look like namespace declarations via 
   814                     <code><a title="dom-element-setattribute" data-spec="DOM4" 
   814                     <code><a title="dom-element-setattribute" data-spec="DOM4" 
   815                     class="externalDFN">setAttribute</a>(<em>"xmlns:pretend-prefix"</em>,
   815                     class="externalDFN">setAttribute</a>(<em>"xmlns:pretend-prefix"</em>,
   816                     <em>"pretend-namespace"</em>)</code> are not included).</p>
   816                     <em>"pretend-namespace"</em>)</code> are not included).</p>
   817                 <li>Let <var>attribute namespace</var> be the <var>attr</var>'s  
   817                 <li>Let <var>attribute namespace</var> be the <var>attr</var>'s  
   818                     <a title="dom-attribute-namespaceuri" data-spec="DOM4" class="externalDFN">namespaceURI</a>
   818                     <code><a title="dom-attribute-namespaceuri" data-spec="DOM4" class="externalDFN">namespaceURI</a></code>
   819                     value.
   819                     value.
   820                 <li>Let <var>attribute prefix</var> be the value of <var>attr</var>'s 
   820                 <li>Let <var>attribute prefix</var> be the value of <var>attr</var>'s 
   821                         <a title="dom-attribute-prefix" data-spec="DOM4" class="externalDFN">prefix</a>.
   821                         <code><a title="dom-attribute-prefix" data-spec="DOM4" class="externalDFN">prefix</a></code>.
   822                 <li>If the <var>attribute namespace</var> is the <a title="xmlns-ns">XMLNS namespace</a>, then:
   822                 <li>If the <var>attribute namespace</var> is the <a title="xmlns-ns">XMLNS namespace</a>, then:
   823                 <ol>
   823                 <ol>
   824                     <li>If <var>attribute prefix</var> is <code>null</code>, then <var>attr</var> is a 
   824                     <li>If <var>attribute prefix</var> is <code>null</code>, then <var>attr</var> is a 
   825                         default namespace declaration. Set the <var>default namespace attr value</var> to 
   825                         default namespace declaration. Set the <var>default namespace attr value</var> to 
   826                         <var>attr</var>'s <a title="dom-attribute-value" data-spec="DOM4"
   826                         <var>attr</var>'s <code><a title="dom-attribute-value" data-spec="DOM4"
   827                         class="externalDFN">value</a> and stop running these steps, returning to the 
   827                         class="externalDFN">value</a></code> and stop running these steps, returning to the 
   828                         top of the loop to visit the next attribute.
   828                         top of the loop to visit the next attribute.
   829                     <li>Otherwise, the <var>attribute prefix</var> is not <code>null</code> and <var>attr</var>
   829                     <li>Otherwise, the <var>attribute prefix</var> is not <code>null</code> and <var>attr</var>
   830                         is a namespace prefix definition. Run the following steps:
   830                         is a namespace prefix definition. Run the following steps:
   831                     <ol>
   831                     <ol>
   832                         <li>Let <var>prefix definition</var> be the value of <var>attr</var>'s 
   832                         <li>Let <var>prefix definition</var> be the value of <var>attr</var>'s 
   833                             <a title="dom-attribute-localname" data-spec="DOM4" class="externalDFN">localName</a>.
   833                             <code><a title="dom-attribute-localname" data-spec="DOM4" class="externalDFN">localName</a></code>.
   834                         <li>Let <var>namespace definition</var> be the value of <var>attr</var>'s 
   834                         <li>Let <var>namespace definition</var> be the value of <var>attr</var>'s 
   835                             <a title="dom-attribute-value" data-spec="DOM4" class="externalDFN">value</a>.
   835                             <code><a title="dom-attribute-value" data-spec="DOM4" class="externalDFN">value</a></code>.
   836                         <li>If a key matching the value of <var>namespace definition</var> already exists in
   836                         <li>If a key matching the value of <var>namespace definition</var> already exists in
   837                             <var>map</var>, and the key's value matches <var>prefix definition</var>, then 
   837                             <var>map</var>, and the key's value matches <var>prefix definition</var>, then 
   838                             this is a duplicate namespace prefix definition. Set the value of <var>duplicate 
   838                             this is a duplicate namespace prefix definition. Set the value of <var>duplicate 
   839                             prefix definition</var> to <var>prefix definition</var>.
   839                             prefix definition</var> to <var>prefix definition</var>.
   840                         <li>Otherwise, if the key matching the value of <var>namespace definition</var> already 
   840                         <li>Otherwise, if the key matching the value of <var>namespace definition</var> already 
   863                 <var>generated prefix</var>.
   863                 <var>generated prefix</var>.
   864             <li>Return the value of <var>generated prefix</var>.
   864             <li>Return the value of <var>generated prefix</var>.
   865         </ol>
   865         </ol>
   866         
   866         
   867         <p>The <dfn title="concept-serialize-xml-attributes">XML serialization of the attributes</dfn>
   867         <p>The <dfn title="concept-serialize-xml-attributes">XML serialization of the attributes</dfn>
   868             of an <a title="concept-element" data-spec="DOM4" class="externalDFN">Element</a>
   868             of an <code><a title="concept-element" data-spec="DOM4" class="externalDFN">Element</a></code>
   869             <var>element</var> together with a <a title="concept-namespace-prefix-map">namespace prefix 
   869             <var>element</var> together with a <a title="concept-namespace-prefix-map">namespace prefix 
   870             map</a> <var>map</var>, a <a title="concept-generated-prefix">generated prefix index</a> 
   870             map</a> <var>map</var>, a <a title="concept-generated-prefix">generated prefix index</a> 
   871             <var>prefix index</var> reference, a flag <var>ignore namespace definition attribute</var>, a
   871             <var>prefix index</var> reference, a flag <var>ignore namespace definition attribute</var>, a
   872             <var>duplicate prefix definition</var> value, and a flag <var>require well-formed</var>,
   872             <var>duplicate prefix definition</var> value, and a flag <var>require well-formed</var>,
   873             is the result of the following algorithm:
   873             is the result of the following algorithm:
   874         <ol>
   874         <ol>
   875             <li>Let <var>result</var> be the empty string.
   875             <li>Let <var>result</var> be the empty string.
   876             <li>Let <var>localname set</var> be a new empty 
   876             <li>Let <var>localname set</var> be a new empty 
   877                 <dfn title="concept-namespace-localname-set">namespace localname set</dfn>. This <var>localname
   877                 <dfn title="concept-namespace-localname-set">namespace localname set</dfn>. This <var>localname
   878                 set</var> will contain tuples of unique attribute <code>namespaceURI</code> and <code>localName</code>
   878                 set</var> will contain tuples of unique attribute 
       
   879                 <code><a title="dom-attribute-namespaceuri" data-spec="DOM4" class="externalDFN">namespaceURI</a></code>
       
   880                 and <code><a title="dom-element-localname" data-spec="DOM4" class="externalDFN">localName</a></code>
   879                 pairs, and is populated as each <var>attr</var> is processed.
   881                 pairs, and is populated as each <var>attr</var> is processed.
   880                 <span class="note">This set is used to [optionally] enforce the well-formed constraint that an 
   882                 <span class="note">This set is used to [optionally] enforce the well-formed constraint that an 
   881                 element cannot have two attributes with the same <code>namespaceURI</code> and <code>localName</code>. 
   883                 element cannot have two attributes with the same 
       
   884                 <code><a title="dom-attribute-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>. 
   882                 This can occur when two otherwise identical attributes on the same element differ only by their 
   886                 This can occur when two otherwise identical attributes on the same element differ only by their 
   883                 prefix values.</span>
   887                 prefix values.</span>
   884             <li>For each <a title="concept-attribute" data-spec="DOM4" class="externalDFN">attribute</a>
   888             <li>For each <a title="concept-attribute" data-spec="DOM4" class="externalDFN">attribute</a>
   885                 <var>attr</var> in <var>element</var>'s
   889                 <var>attr</var> in <var>element</var>'s
   886                 <a title="concept-element-attribute" data-spec="DOM4" class="externalDFN">attributes</a>,
   890                 <code><a title="dom-element-attributes" data-spec="DOM4" class="externalDFN">attributes</a></code>,
   887                 in order:
   891                 in order:
   888             <ol>
   892             <ol>
   889                 <li>If the <a title="concept-well-formed">require well-formed</a> flag is set (its value is 
   893                 <li>If the <a title="concept-well-formed">require well-formed</a> flag is set (its value is 
   890                     <code>true</code>), and the <var>localname set</var> contains a tuple whose values match those 
   894                     <code>true</code>), and the <var>localname set</var> contains a tuple whose values match those 
   891                     of a new tuple consisting of <var>attr</var>'s 
   895                     of a new tuple consisting of <var>attr</var>'s 
   896                 <li>Create a new tuple consisting of <var>attr</var>'s 
   900                 <li>Create a new tuple consisting of <var>attr</var>'s 
   897                     <code><a title="dom-attribute-namespaceuri" data-spec="DOM4" class="externalDFN">namespaceURI</a></code>
   901                     <code><a title="dom-attribute-namespaceuri" data-spec="DOM4" class="externalDFN">namespaceURI</a></code>
   898                     attribute and <code><a title="dom-element-localname" data-spec="DOM4" class="externalDFN">localName</a></code>
   902                     attribute and <code><a title="dom-element-localname" data-spec="DOM4" class="externalDFN">localName</a></code>
   899                     attribute, and add it to the <var>localname set</var>.
   903                     attribute, and add it to the <var>localname set</var>.
   900                 <li>Let <var>attribute namespace</var> be the <var>attr</var>'s  
   904                 <li>Let <var>attribute namespace</var> be the <var>attr</var>'s  
   901                     <a title="dom-attribute-namespaceuri" data-spec="DOM4" class="externalDFN">namespaceURI</a>
   905                     <code><a title="dom-attribute-namespaceuri" data-spec="DOM4" class="externalDFN">namespaceURI</a></code>
   902                     value.
   906                     value.
   903                 <!-- Check for an unregistered attribute namespace, and if so, serialize a definition for it -->
   907                 <!-- Check for an unregistered attribute namespace, and if so, serialize a definition for it -->
   904                 <li>Let <var>candidate prefix</var> be <code>null</code>.
   908                 <li>Let <var>candidate prefix</var> be <code>null</code>.
   905                 <li>If <var>attribute namespace</var> is not <code>null</code>, then run these sub-steps:
   909                 <li>If <var>attribute namespace</var> is not <code>null</code>, then run these sub-steps:
   906                 <ol>
   910                 <ol>
   907                     <li>If the value of <var>attribute namespace</var> is the 
   911                     <li>If the value of <var>attribute namespace</var> is the 
   908                         <a title="xmlns-ns">XMLNS namespace</a> and either the <var>attr</var>'s 
   912                         <a title="xmlns-ns">XMLNS namespace</a> and either the <var>attr</var>'s 
   909                         <a title="dom-attribute-prefix" data-spec="DOM4" class="externalDFN">prefix</a>
   913                         <code><a title="dom-attribute-prefix" data-spec="DOM4" class="externalDFN">prefix</a></code>
   910                         is <code>null</code> and the <var>ignore namespace definition 
   914                         is <code>null</code> and the <var>ignore namespace definition 
   911                         attribute</var> flag is <code>true</code> or the <var>attr</var>'s 
   915                         attribute</var> flag is <code>true</code> or the <var>attr</var>'s 
   912                         <a title="dom-attribute-prefix" data-spec="DOM4" class="externalDFN">prefix</a>
   916                         <code><a title="dom-attribute-prefix" data-spec="DOM4" class="externalDFN">prefix</a></code>
   913                         is not <code>null</code> and the <var>attr</var>'s 
   917                         is not <code>null</code> and the <var>attr</var>'s 
   914                         <a title="concept-attribute-localname" data-spec="DOM4" class="externalDFN">localName</a>
   918                         <code><a title="concept-attribute-localname" data-spec="DOM4" class="externalDFN">localName</a></code>
   915                         matches the value of <var>duplicate prefix definition</var>, then stop running 
   919                         matches the value of <var>duplicate prefix definition</var>, then stop running 
   916                         these steps and return to the loop to visit the next attribute.
   920                         these steps and return to the loop to visit the next attribute.
   917                     <li>Otherwise, if there exists a key in <var>map</var> that matches the value of <var>attribute 
   921                     <li>Otherwise, if there exists a key in <var>map</var> that matches the value of <var>attribute 
   918                         namespace</var>, then let <var>candidate prefix</var> be that key's value from the 
   922                         namespace</var>, then let <var>candidate prefix</var> be that key's value from the 
   919                         <var>map</var>.
   923                         <var>map</var>.
   951                     exception</a>; the serialization of this <var>attr</var> would not be a well-formed attribute.
   955                     exception</a>; the serialization of this <var>attr</var> would not be a well-formed attribute.
   952                 <!-- Write out the standard attribute -->
   956                 <!-- Write out the standard attribute -->
   953                 <li>Append the following strings to <var>result</var>:
   957                 <li>Append the following strings to <var>result</var>:
   954                 <ol>
   958                 <ol>
   955                     <li>The value of <var>attr</var>'s
   959                     <li>The value of <var>attr</var>'s
   956                         <a title="concept-attribute-localname" data-spec="DOM4" class="externalDFN">localName</a>;
   960                         <code><a title="concept-attribute-localname" data-spec="DOM4" class="externalDFN">localName</a></code>;
   957                     <li>"<code>="</code>" (U+003D EQUALS SIGN, U+0022 QUOTATION MARK);
   961                     <li>"<code>="</code>" (U+003D EQUALS SIGN, U+0022 QUOTATION MARK);
   958                     <li>The result of <a title="concept-serialize-attr-value">serializing an attribute value</a> 
   962                     <li>The result of <a title="concept-serialize-attr-value">serializing an attribute value</a> 
   959                         given <var>attr</var>'s
   963                         given <var>attr</var>'s
   960                         <code><a title="concept-attribute-value" data-spec="DOM4" class="externalDFN">value</a></code>
   964                         <code><a title="concept-attribute-value" data-spec="DOM4" class="externalDFN">value</a></code>
   961                         attribute and the <a title="concept-well-formed">require well-formed</a> flag as input;
   965                         attribute and the <a title="concept-well-formed">require well-formed</a> flag as input;
  1041                     <li>If the previous step didn't return an error, return the newly
  1045                     <li>If the previous step didn't return an error, return the newly
  1042                     created <a title="concept-document" data-spec="DOM4" class="externalDFN">document</a>
  1046                     created <a title="concept-document" data-spec="DOM4" class="externalDFN">document</a>
  1043                     and terminate these steps.
  1047                     and terminate these steps.
  1044 
  1048 
  1045                     <li>Otherwise, throw a 
  1049                     <li>Otherwise, throw a 
  1046                     <a data-spec="DOM4" title="domexception" class="externalDFN">DOMException</a></code> 
  1050                     <code><a data-spec="DOM4" title="domexception" class="externalDFN">DOMException</a></code> 
  1047                     with name <code>SyntaxError</code>.
  1051                     with name <code>SyntaxError</code>.
  1048                     
  1052                     
  1049                     <p class=note>Some UAs do not throw an exception, but rather return a minimal 
  1053                     <p class=note>Some UAs do not throw an exception, but rather return a minimal 
  1050                     well-formed XML document that describes the error. In these cases, the error 
  1054                     well-formed XML document that describes the error. In these cases, the error 
  1051                     document's root element will be named <code>parsererror</code> and its namespace
  1055                     document's root element will be named <code>parsererror</code> and its namespace