Skip to content

Commit 08400e5

Browse files
Fix bug 25181: Enable the innerHTML and outerHTML getter calls to invoke the serialize steps directly
* https://www.w3.org/Bugs/Public/show_bug.cgi?id=25181 This does not yet implement the validation requirements, but puts the plumbing in place to catch all the cases defined in: HTML5's xml-fragment-serialization-algorithm. The remained of this work is tracked in bug 25168
1 parent 5841a0f commit 08400e5

File tree

1 file changed

+76
-77
lines changed

1 file changed

+76
-77
lines changed

index.html

Lines changed: 76 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -248,21 +248,40 @@ <h2>Parsing</h2>
248248

249249
<section>
250250
<h2>Serializing</h2>
251-
<p>To <dfn title="concept-serialize">serialize</dfn> a
252-
<a title="node" data-spec="DOM4" class="externalDFN">Node</a> <var>node</var>, the user agent
253-
must run the following steps:
251+
<p>The following steps form the
252+
<dfn title="concept-fragment-serializing-algorithm">fragment serializing algorithm</dfn>,
253+
whose arguments are a <a title="node" data-spec="DOM4" class="externalDFN">Node</a>
254+
<var>node</var> and a flag <dfn title="concept-strict-validation">strict validation</dfn>.
254255

255256
<ol>
256-
<li>Let <var>document</var> be <var>node</var>'s
257+
<li>Let <var>context document</var> be <var>node</var>'s
257258
<a title="concept-node-document" data-spec="DOM4" class="externalDFN">node document</a>.
258-
<li>If <var>document</var> is an
259+
<li>If <var>context document</var> is an
259260
<a title="html-document" data-spec="DOM4" class="externalDFN">HTML document</a>,
260261
return an <a title="concept-serialize-html">HTML serialization</a> of <var>node</var>.
261-
<li>Otherwise, <var>document</var> is an
262-
<a title="xml-document" data-spec="DOM4" class="externalDFN">XML document</a>.
262+
<li>Otherwise, <var>context document</var> is an
263+
<a title="xml-document" data-spec="DOM4" class="externalDFN">XML document</a>;
264+
return an <a title="concept-serialize-xml">XML serialization</a> of <var>node</var>
265+
passing the flag <var>strict validation</var>.
266+
<p class="note">The <a title="concept-serialize-xml">XML serialization</a> defined in this document
267+
conforms to the requirements of the <a data-spec="HTML5" title="xml-fragment-serialization-algorithm"
268+
class="externalDFN">XML fragment serialization algorithm</a> defined in [[HTML5]].</p>
269+
</ol>
270+
271+
<p>To produce an <dfn title="concept-serialize-html">HTML serialization</dfn> of a
272+
<a title="node" data-spec="DOM4" class="externalDFN">Node</a> <var>node</var>, the user agent
273+
must run the
274+
<a data-spec="HTML5" title="html-fragment-serialization-algorithm" class="externalDFN">HTML
275+
fragment serialization algorithm</a> [[!HTML5]] on <var>node</var> and return the string produced.
276+
277+
<p>To produce an <dfn title="concept-serialize-xml">XML serialization</dfn> of a
278+
<a title="node" data-spec="DOM4" class="externalDFN">Node</a> <var>node</var> given a
279+
flag <var>strict validation</var>, run the following steps:
280+
<ol>
263281
<li>Let <dfn title="concept-context-namespace">context namespace</dfn> be <code>null</code>.
264282
The <a title="concept-context-namespace">context namespace</a> is changed when a
265-
<var>node</var> serializes a different default namespace definition from its parent.
283+
<var>node</var> serializes a different default namespace definition from its parent. The
284+
algorithm assumes no namespace to start.
266285
<li>Let <dfn title="concept-namespace-prefix-map">namespace prefix map</dfn> be a new map
267286
for associating <code>namespaceURI</code> and namespace <code>prefix</code> pairs, where
268287
<code>namespaceURI</code> values are the map's keys, and <code>prefix</code> values are
@@ -281,19 +300,16 @@ <h2>Serializing</h2>
281300
namespace prefix is available to serialize a <var>node</var>'s namespaceURI (or the namespaceURI
282301
of one of <var>node</var>'s attributes). <span class="note">See the
283302
<a title="concept-generate-prefix">generate a prefix</a> algorithm.</span>
284-
<li>Return an <a title="concept-serialize-xml">XML serialization</a> of <var>node</var>
285-
providing to the algorithm a <a title="concept-context-namespace">context namespace</a>
286-
<var>namespace</var>, a <a title="concept-namespace-prefix-map">namespace prefix map</a>
287-
<var>prefix map</var>, and a <a title="concept-generated-prefix">generated namespace prefix index</a>
288-
<var>prefix index</var>.
303+
<li>Return the result of running the <a title="concept-xml-serialization-algorithm">XML serialization
304+
algorithm</a> on <var>node</var> passing the <a title="concept-context-namespace">context
305+
namespace</a>, <a title="concept-namespace-prefix-map">namespace prefix map</a>,
306+
<a title="concept-generated-prefix">generated namespace prefix index</a> reference, and the
307+
flag <var>strict validation</var>. If an <dfn title="concept-algorithm-exception">exception</dfn>
308+
occurs during the execution of the algorithm, then catch that exception and throw a
309+
<code><a data-spec="DOM4" title="domexception" class="externalDFN">DOMException</a></code> with
310+
name <code>InvalidStateError</code>.
289311
</ol>
290-
291-
<p>To produce an <dfn title="concept-serialize-html">HTML serialization</dfn> of a
292-
<a title="node" data-spec="DOM4" class="externalDFN">Node</a> <var>node</var>, the user agent
293-
must run the
294-
<a data-spec="HTML5" title="html-fragment-serialization-algorithm" class="externalDFN">HTML
295-
fragment serialization algorithm</a> [[!HTML5]] on <var>node</var> and return the string produced.
296-
312+
297313
<p>An <a title="concept-serialize-xml">XML serialization</a> differs from an
298314
<a title="concept-serialize-html">HTML serialization</a> in the following ways:
299315
<ul>
@@ -316,29 +332,20 @@ <h2>Serializing</h2>
316332
elements in the <a title="html-ns">HTML namespace</a> that contain no child nodes are serialized
317333
with an explicit begin and end tag rather than using the self-closing tag syntax [[XML10]].
318334

319-
<p class="note">An <a title="concept-serialize-xml">XML serialization</a> might not always
320-
produce a <a data-spec="XML10" title="sec-well-formed" class="externalDFN">well-formed</a>
321-
serialization. For example, the <a title="dom-element-setattribute" data-spec="DOM4"
322-
class="externalDFN">setAttribute</a> method does not enforce XML validity constraints,
323-
like disallowing use of attribute names that resemble namespace declarations or prefix
324-
definitions. The <a title="concept-serialize-xml">XML serialization</a> algorithm defined
325-
in this document does not escape, encode, or fail to serialize such attribute names.
326-
327335
<p class="issue"><a href="https://www.w3.org/Bugs/Public/show_bug.cgi?id=25168">Bug: 25168</a>
328336
Should an XML Serialization check for these potential issues and tweak element
329337
and attribute localNames that could cause problems? For example, replace "<code>:</code>"
330338
(U+003A COLON) with "<code>_</code>" (U+005F LOW LINE) in element localNames and drop/replace
331339
"<code>xmlns</code>" and "<code>xmlns:</code>" prefixes in attribute localNames? Or should
332340
the XML Serialization fail to serialize under these scenarios?
333341

334-
<p>To produce an <dfn title="concept-serialize-xml">XML serialization</dfn> of a
335-
<a title="node" data-spec="DOM4" class="externalDFN">Node</a> <var>node</var> given a
336-
<a title="concept-context-namespace">context namespace</a> <var>namespace</var>, a
337-
<a title="concept-namespace-prefix-map">namespace prefix map</a> <var>prefix map</var> and
338-
a reference to a <a title="concept-generated-prefix">generated namespace prefix index</a>
339-
<var>prefix index</var>, the user agent must run the appropriate steps, depending on
340-
<var>node</var>'s interface:</p>
341-
342+
<p>To run the <dfn title="concept-xml-serialization-algorithm">XML serialization algorithm</dfn> on
343+
a <var>node</var> given a <a title="concept-context-namespace">context namespace</a>
344+
<var>namespace</var>, a <a title="concept-namespace-prefix-map">namespace prefix map</a>
345+
<var>prefix map</var>, a <a title="concept-generated-prefix">generated namespace prefix index</a>
346+
<var>prefix index</var>, and a flag <var>strict validation</var>, the user agent must run the
347+
appropriate steps, depending on <var>node</var>'s interface:</p>
348+
342349
<dl class=switch>
343350
<dt><code><a title="element" data-spec="DOM4" class="externalDFN">Element</a></code>
344351
<dd>
@@ -347,6 +354,7 @@ <h2>Serializing</h2>
347354
<!-- "namespace" was passed via the caller, it's the default namespace scope -->
348355
<!-- "prefix map" was passed via the caller, it's the namespace->prefix map -->
349356
<!-- "prefix index" was passed via the caller, it's a number for generating prefixes if necessary -->
357+
<!-- "strict validation" was passed via the caller, it's a flag (true/false) for whether certain validation steps should be taken during serialization. -->
350358
<li>Let <var>markup</var> be the string "<code>&lt;</code>" (U+003C LESS-THAN SIGN).
351359
<li>Let <var>qualified name</var> be an empty string.
352360
<li>Let a <var>skip end tag</var> flag have the value <code>false</code>.
@@ -518,13 +526,16 @@ <h2>Serializing</h2>
518526
<li>If the value of <var>skip end tag</var> is <code>true</code>, then return
519527
the value of <var>markup</var> and skip the remaining steps. The
520528
<var>node</var> is a leaf-node.
521-
<li>Append to <var>markup</var> the result of performing an
522-
<a title="concept-serialize-xml">XML serialization</a> of each of <var>node</var>'s
529+
<li>Append to <var>markup</var> the result of running the
530+
<a title="concept-xml-serialization-algorithm">XML serialization algorithm</a> on each
531+
of <var>node</var>'s
523532
<a title="concept-tree-child" data-spec="DOM4" class="externalDFN">children</a>,
524-
in order, providing the value of <var>inherited ns</var> for the <var>namespace</var>,
533+
in order, providing the value of <var>inherited ns</var> for the
534+
<a title="concept-context-namespace">context namespace</a>,
525535
<var>map</var> for the <a title="concept-namespace-prefix-map">namespace prefix map</a>,
526-
and <var>prefix index</var> for the
527-
<a title="concept-generated-prefix">generated namespace prefix index</a>.
536+
<var>prefix index</var> for the
537+
<a title="concept-generated-prefix">generated namespace prefix index</a>, and the value
538+
of the <var>strict validation</var> flag.
528539
<li>Append the following to <var>markup</var>, in order:
529540
<ol>
530541
<li>"<code>&lt;/</code>" (U+003C LESS-THAN SIGN, U+002F SOLIDUS);
@@ -543,13 +554,14 @@ <h2>Serializing</h2>
543554
of <var>node</var>'s
544555
<a title="dom-document-doctype" data-spec="HTML5" class="externalDFN">doctype</a>
545556
attribute;
546-
<li>The string produced by an <a title="concept-serialize-xml">XML serialization</a>
547-
of <var>node</var>'s
557+
<li>The string produced by running the <a title="concept-xml-serialization-algorithm">XML
558+
serialization algorithm</a> on <var>node</var>'s
548559
<a title="dom-document-documentelement" data-spec="HTML5" class="externalDFN">documentElement</a>
549-
attribute, given <code>null</code> as the <var>namespace</var>, the
560+
attribute, given <code>null</code> as the <a title="concept-context-namespace">context
561+
namespace</a>,
550562
<a title="concept-namespace-prefix-map">namespace prefix map</a> <var>prefix map</var>,
551-
and a reference to the <a title="concept-generated-prefix">generated namespace
552-
prefix index</a> <var>prefix index</var>.
563+
a reference to the <a title="concept-generated-prefix">generated namespace
564+
prefix index</a> <var>prefix index</var>, and flag <var>strict validation</var>.
553565
</ol>
554566

555567
<dt><code><a title="comment" data-spec="DOM4" class="externalDFN">Comment</a></code>
@@ -594,12 +606,13 @@ <h2>Serializing</h2>
594606

595607
<li>For each
596608
<a title="concept-tree-child" data-spec="DOM4" class="externalDFN">child</a> of <var>node</var>,
597-
in order, <a title="concept-serialize-xml">produce an XML serialization</a> of the child given
609+
in order, run the <a title="concept-xml-serialization-algorithm">XML serialization algorithm</a>
610+
on the <var>child</var> given
598611
a <a title="concept-context-namespace">context namespace</a> <var>namespace</var>, a
599-
<a title="concept-namespace-prefix-map">namespace prefix map</a> <var>prefix map</var> and
612+
<a title="concept-namespace-prefix-map">namespace prefix map</a> <var>prefix map</var>,
600613
a reference to a <a title="concept-generated-prefix">generated namespace prefix index</a>
601-
<var>prefix index</var>. Concatenate the result to <var>markup</var>.
602-
614+
<var>prefix index</var>, and flag <var>strict validation</var>. Concatenate the result
615+
to <var>markup</var>.
603616
<li>Return <var>markup</var>.
604617
</ol>
605618
<dt><code><a title="documenttype" data-spec="DOM4" class="externalDFN">DocumentType</a></code>
@@ -982,7 +995,8 @@ <h1>The <code>XMLSerializer</code> interface</h1>
982995
<dt>DOMString serializeToString(Node root)</dt>
983996

984997
<dd>The <code>serializeToString(<var>root</var>)</code>
985-
method must <a title="concept-serialize-xml">produce an XML serialization</a> of <var>root</var> and return the result.</dd>
998+
method must <a title="concept-serialize-xml">produce an XML serialization</a> of <var>root</var> passing
999+
a value of <code>false</code> for the <a title="concept-strict-validation">strict validation</a> parameter, and return the result.</dd>
9861000
</dl>
9871001
</section>
9881002

@@ -1033,21 +1047,13 @@ <h1>Extensions to the <code><a title="element" data-spec="DOM4" class="externalD
10331047
if the given string is not well-formed.
10341048
</dl>
10351049

1036-
<p>On getting, if the <a title="context object">context object</a>'s
1037-
<a title="concept-node-document" data-spec="DOM4" class="externalDFN">node document</a>
1038-
is an <a title="html-document" data-spec="DOM4" class="externalDFN">HTML document</a>, then the attribute
1039-
must return the result of running the
1040-
<a data-spec="HTML5" title="html-fragment-serialization-algorithm" class="externalDFN">HTML fragment serialization algorithm</a> on the
1041-
<a title="context object">context object</a>; otherwise, the <a title="context object">context object</a>'s
1042-
<a title="concept-node-document" data-spec="DOM4" class="externalDFN">node document</a>
1043-
is an <a title="xml-document" data-spec="DOM4" class="externalDFN">XML document</a>, and the attribute must
1044-
return the result of running the
1045-
<a data-spec="HTML5" title="xml-fragment-serialization-algorithm" class="externalDFN">XML fragment serialization algorithm</a> on the
1046-
<a title="context object">context object</a> instead (this might throw an
1047-
exception instead of returning a string).
1050+
<p>On getting, return the result of invoking the
1051+
<a title="concept-fragment-serializing-algorithm">fragment serializing algorithm</a> on the
1052+
<a title="context object">context object</a> providing <code>true</code> for the
1053+
<a title="concept-strict-validation">strict validation</a> flag (this might throw an exception
1054+
instead of returning a string).
10481055

10491056
<p>On setting, these steps must be run:
1050-
10511057
<ol>
10521058
<li>Let <var>fragment</var> be the result of invoking the
10531059
<a title="concept-parse-fragment">fragment parsing algorithm</a> with
@@ -1088,19 +1094,12 @@ <h1>Extensions to the <code><a title="element" data-spec="DOM4" class="externalD
10881094
<code><a title="document" data-spec="DOM4" class="externalDFN">Document</a></code> node.
10891095
</dl>
10901096

1091-
<p>On getting, if the <a title="context object">context object</a>'s
1092-
<a title="concept-node-document" data-spec="DOM4" class="externalDFN">node document</a>
1093-
is an <a title="html-document" data-spec="DOM4" class="externalDFN">HTML document</a>, then the attribute
1094-
must return the result of running the
1095-
<a data-spec="HTML5" title="html-fragment-serialization-algorithm" class="externalDFN">HTML fragment serialization algorithm</a> on a
1096-
fictional node whose only child is <a title="context object">context object</a>; otherwise, the
1097-
<a title="context object">context object</a>'s
1098-
<a title="concept-node-document" data-spec="DOM4" class="externalDFN">node document</a>
1099-
is an <a title="xml-document" data-spec="DOM4" class="externalDFN">XML document</a>, and the attribute must
1100-
return the result of running the
1101-
<a data-spec="HTML5" title="xml-fragment-serialization-algorithm" class="externalDFN">XML fragment serialization algorithm</a> on that
1102-
fictional node instead (this might throw an exception instead of returning a
1103-
string).
1097+
<p>On getting, return the result of invoking the
1098+
<a title="concept-fragment-serializing-algorithm">fragment serializing algorithm</a> on a
1099+
fictional node whose only child is the <a title="context object">context object</a>
1100+
<a title="context object">context object</a> providing <code>true</code> for the
1101+
<a title="concept-strict-validation">strict validation</a> flag (this might throw an exception
1102+
instead of returning a string).
11041103

11051104
<p>On setting, the following steps must be run:
11061105

0 commit comments

Comments
 (0)