@@ -248,21 +248,40 @@ <h2>Parsing</h2>
248
248
249
249
< section >
250
250
< 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 > .
254
255
255
256
< ol >
256
- < li > Let < var > document</ var > be < var > node</ var > 's
257
+ < li > Let < var > context document</ var > be < var > node</ var > 's
257
258
< 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
259
260
< a title ="html-document " data-spec ="DOM4 " class ="externalDFN "> HTML document</ a > ,
260
261
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 >
263
281
< li > Let < dfn title ="concept-context-namespace "> context namespace</ dfn > be < code > null</ code > .
264
282
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.
266
285
< li > Let < dfn title ="concept-namespace-prefix-map "> namespace prefix map</ dfn > be a new map
267
286
for associating < code > namespaceURI</ code > and namespace < code > prefix</ code > pairs, where
268
287
< code > namespaceURI</ code > values are the map's keys, and < code > prefix</ code > values are
@@ -281,19 +300,16 @@ <h2>Serializing</h2>
281
300
namespace prefix is available to serialize a < var > node</ var > 's namespaceURI (or the namespaceURI
282
301
of one of < var > node</ var > 's attributes). < span class ="note "> See the
283
302
< 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 > .
289
311
</ 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
+
297
313
< p > An < a title ="concept-serialize-xml "> XML serialization</ a > differs from an
298
314
< a title ="concept-serialize-html "> HTML serialization</ a > in the following ways:
299
315
< ul >
@@ -316,29 +332,20 @@ <h2>Serializing</h2>
316
332
elements in the < a title ="html-ns "> HTML namespace</ a > that contain no child nodes are serialized
317
333
with an explicit begin and end tag rather than using the self-closing tag syntax [[XML10]].
318
334
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
-
327
335
< p class ="issue "> < a href ="https://www.w3.org/Bugs/Public/show_bug.cgi?id=25168 "> Bug: 25168</ a >
328
336
Should an XML Serialization check for these potential issues and tweak element
329
337
and attribute localNames that could cause problems? For example, replace "< code > :</ code > "
330
338
(U+003A COLON) with "< code > _</ code > " (U+005F LOW LINE) in element localNames and drop/replace
331
339
"< code > xmlns</ code > " and "< code > xmlns:</ code > " prefixes in attribute localNames? Or should
332
340
the XML Serialization fail to serialize under these scenarios?
333
341
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
+
342
349
< dl class =switch >
343
350
< dt > < code > < a title ="element " data-spec ="DOM4 " class ="externalDFN "> Element</ a > </ code >
344
351
< dd >
@@ -347,6 +354,7 @@ <h2>Serializing</h2>
347
354
<!-- "namespace" was passed via the caller, it's the default namespace scope -->
348
355
<!-- "prefix map" was passed via the caller, it's the namespace->prefix map -->
349
356
<!-- "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. -->
350
358
< li > Let < var > markup</ var > be the string "< code > <</ code > " (U+003C LESS-THAN SIGN).
351
359
< li > Let < var > qualified name</ var > be an empty string.
352
360
< li > Let a < var > skip end tag</ var > flag have the value < code > false</ code > .
@@ -518,13 +526,16 @@ <h2>Serializing</h2>
518
526
< li > If the value of < var > skip end tag</ var > is < code > true</ code > , then return
519
527
the value of < var > markup</ var > and skip the remaining steps. The
520
528
< 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
523
532
< 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 > ,
525
535
< 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.
528
539
< li > Append the following to < var > markup</ var > , in order:
529
540
< ol >
530
541
< li > "< code > </</ code > " (U+003C LESS-THAN SIGN, U+002F SOLIDUS);
@@ -543,13 +554,14 @@ <h2>Serializing</h2>
543
554
of < var > node</ var > 's
544
555
< a title ="dom-document-doctype " data-spec ="HTML5 " class ="externalDFN "> doctype</ a >
545
556
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
548
559
< 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 > ,
550
562
< 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 > .
553
565
</ ol >
554
566
555
567
< dt > < code > < a title ="comment " data-spec ="DOM4 " class ="externalDFN "> Comment</ a > </ code >
@@ -594,12 +606,13 @@ <h2>Serializing</h2>
594
606
595
607
< li > For each
596
608
< 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
598
611
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 > ,
600
613
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 > .
603
616
< li > Return < var > markup</ var > .
604
617
</ ol >
605
618
< dt > < code > < a title ="documenttype " data-spec ="DOM4 " class ="externalDFN "> DocumentType</ a > </ code >
@@ -982,7 +995,8 @@ <h1>The <code>XMLSerializer</code> interface</h1>
982
995
< dt > DOMString serializeToString(Node root)</ dt >
983
996
984
997
< 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 >
986
1000
</ dl >
987
1001
</ section >
988
1002
@@ -1033,21 +1047,13 @@ <h1>Extensions to the <code><a title="element" data-spec="DOM4" class="externalD
1033
1047
if the given string is not well-formed.
1034
1048
</ dl >
1035
1049
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).
1048
1055
1049
1056
< p > On setting, these steps must be run:
1050
-
1051
1057
< ol >
1052
1058
< li > Let < var > fragment</ var > be the result of invoking the
1053
1059
< 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
1088
1094
< code > < a title ="document " data-spec ="DOM4 " class ="externalDFN "> Document</ a > </ code > node.
1089
1095
</ dl >
1090
1096
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).
1104
1103
1105
1104
< p > On setting, the following steps must be run:
1106
1105
0 commit comments