forked from w3c/DOM-Parsing
-
Notifications
You must be signed in to change notification settings - Fork 0
/
LCWD-DOM-Parsing-20131205.html
1768 lines (1463 loc) · 101 KB
/
LCWD-DOM-Parsing-20131205.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html lang="en" dir="ltr" typeof="bibo:Document w3p:LastCall" about="" property="dcterms:language" content="en">
<head>
<meta charset="UTF-8">
<title>DOM Parsing and Serialization</title>
<style>
/* Make these stand-out more... */
.externalDFN {
font-style: italic;
background-color: #fff9d6;
}
/* Switch statement */
dl.switch dt::before {
content: "↪ ";
margin-left: 1em;
}
/* Better spacing around various lists (implied paragraph children) */
ol > li, section:not(#toc) ul > li, section dl > dt {
margin: 1em 0;
}
/* domintro styling */
dl.domintro {
background-color: rgb(221, 255, 221);
padding: 1em 0.5em 1em 2em;
clear: both;
}
dl.domintro dt {
color: black;
}
dl.domintro > dd {
color: green;
}
dl.domintro::before {
float: right;
background-color: white;
display: block;
border: 2px solid black;
color: green;
margin-top: -20px;
padding: 2px;
content: "This box is non-normative. Implementation requirements are given below this box.";
}
/* Fancy table stuff */
table {
border-collapse: collapse;
}
thead tr {
border-bottom: 2px solid black;
}
tbody tr:not(:last-child) {
border-bottom: 1px solid black;
}
td {
border-left: 1px solid black;
padding: 4px;
}
/* Extra IDL :-) */
.extraidl {
line-height: 120%;
padding: 1em;
border-top: 1px solid #90b8de;
border-bottom: 1px solid #90b8de;
}
.extraidl:before {
width: 150px;
color: #fff;
padding: 3px;
font-weight: bold;
font-family: initial;
margin: -1em 0 1em -1em;
display: block;
content: "WebIDL";
background-color: rgb(144, 184, 222);
}
</style>
<style>/*****************************************************************
* ReSpec 3 CSS
* Robin Berjon - http://berjon.com/
*****************************************************************/
/* --- INLINES --- */
em.rfc2119 {
text-transform: lowercase;
font-variant: small-caps;
font-style: normal;
color: #900;
}
h1 acronym, h2 acronym, h3 acronym, h4 acronym, h5 acronym, h6 acronym, a acronym,
h1 abbr, h2 abbr, h3 abbr, h4 abbr, h5 abbr, h6 abbr, a abbr {
border: none;
}
dfn {
font-weight: bold;
}
a.internalDFN {
color: inherit;
border-bottom: 1px solid #99c;
text-decoration: none;
}
a.externalDFN {
color: inherit;
border-bottom: 1px dotted #ccc;
text-decoration: none;
}
a.bibref {
text-decoration: none;
}
cite .bibref {
font-style: normal;
}
code {
color: #ff4500;
}
/* --- TOC --- */
.toc a, .tof a {
text-decoration: none;
}
a .secno, a .figno {
color: #000;
}
ul.tof, ol.tof {
list-style: none outside none;
}
.caption {
margin-top: 0.5em;
font-style: italic;
}
/* --- TABLE --- */
table.simple {
border-spacing: 0;
border-collapse: collapse;
border-bottom: 3px solid #005a9c;
}
.simple th {
background: #005a9c;
color: #fff;
padding: 3px 5px;
text-align: left;
}
.simple th[scope="row"] {
background: inherit;
color: inherit;
border-top: 1px solid #ddd;
}
.simple td {
padding: 3px 10px;
border-top: 1px solid #ddd;
}
.simple tr:nth-child(even) {
background: #f0f6ff;
}
/* --- DL --- */
.section dd > p:first-child {
margin-top: 0;
}
.section dd > p:last-child {
margin-bottom: 0;
}
.section dd {
margin-bottom: 1em;
}
.section dl.attrs dd, .section dl.eldef dd {
margin-bottom: 0;
}
</style><style>/* --- ISSUES/NOTES --- */
div.issue-title, div.note-title {
padding-right: 1em;
min-width: 7.5em;
color: #b9ab2d;
}
div.issue-title { color: #e05252; }
div.note-title { color: #2b2; }
div.issue-title span, div.note-title span {
text-transform: uppercase;
}
div.note, div.issue {
margin-top: 1em;
margin-bottom: 1em;
}
.note > p:first-child, .issue > p:first-child { margin-top: 0 }
.issue, .note {
padding: .5em;
border-left-width: .5em;
border-left-style: solid;
}
div.issue, div.note {
padding: 1em 1.2em 0.5em;
margin: 1em 0;
position: relative;
clear: both;
}
span.note, span.issue { padding: .1em .5em .15em; }
.issue {
border-color: #e05252;
background: #fbe9e9;
}
.note {
border-color: #52e052;
background: #e9fbe9;
}
</style><style>/* --- WEB IDL --- */
pre.idl {
border-top: 1px solid #90b8de;
border-bottom: 1px solid #90b8de;
padding: 1em;
line-height: 120%;
}
pre.idl::before {
content: "WebIDL";
display: block;
width: 150px;
background: #90b8de;
color: #fff;
font-family: initial;
padding: 3px;
font-weight: bold;
margin: -1em 0 1em -1em;
}
.idlType {
color: #ff4500;
font-weight: bold;
text-decoration: none;
}
/*.idlModule*/
/*.idlModuleID*/
/*.idlInterface*/
.idlInterfaceID, .idlDictionaryID, .idlCallbackID, .idlEnumID {
font-weight: bold;
color: #005a9c;
}
a.idlEnumItem {
color: #000;
border-bottom: 1px dotted #ccc;
text-decoration: none;
}
.idlSuperclass {
font-style: italic;
color: #005a9c;
}
/*.idlAttribute*/
.idlAttrType, .idlFieldType, .idlMemberType {
color: #005a9c;
}
.idlAttrName, .idlFieldName, .idlMemberName {
color: #ff4500;
}
.idlAttrName a, .idlFieldName a, .idlMemberName a {
color: #ff4500;
border-bottom: 1px dotted #ff4500;
text-decoration: none;
}
/*.idlMethod*/
.idlMethType, .idlCallbackType {
color: #005a9c;
}
.idlMethName {
color: #ff4500;
}
.idlMethName a {
color: #ff4500;
border-bottom: 1px dotted #ff4500;
text-decoration: none;
}
/*.idlCtor*/
.idlCtorName {
color: #ff4500;
}
.idlCtorName a {
color: #ff4500;
border-bottom: 1px dotted #ff4500;
text-decoration: none;
}
/*.idlParam*/
.idlParamType {
color: #005a9c;
}
.idlParamName, .idlDefaultValue {
font-style: italic;
}
.extAttr {
color: #666;
}
/*.idlSectionComment*/
.idlSectionComment {
color: gray;
}
/*.idlConst*/
.idlConstType {
color: #005a9c;
}
.idlConstName {
color: #ff4500;
}
.idlConstName a {
color: #ff4500;
border-bottom: 1px dotted #ff4500;
text-decoration: none;
}
/*.idlException*/
.idlExceptionID {
font-weight: bold;
color: #c00;
}
.idlTypedefID, .idlTypedefType {
color: #005a9c;
}
.idlRaises, .idlRaises a.idlType, .idlRaises a.idlType code, .excName a, .excName a code {
color: #c00;
font-weight: normal;
}
.excName a {
font-family: monospace;
}
.idlRaises a.idlType, .excName a.idlType {
border-bottom: 1px dotted #c00;
}
.excGetSetTrue, .excGetSetFalse, .prmNullTrue, .prmNullFalse, .prmOptTrue, .prmOptFalse {
width: 45px;
text-align: center;
}
.excGetSetTrue, .prmNullTrue, .prmOptTrue { color: #0c0; }
.excGetSetFalse, .prmNullFalse, .prmOptFalse { color: #c00; }
.idlImplements a {
font-weight: bold;
}
dl.attributes, dl.methods, dl.constants, dl.constructors, dl.fields, dl.dictionary-members {
margin-left: 2em;
}
.attributes dt, .methods dt, .constants dt, .constructors dt, .fields dt, .dictionary-members dt {
font-weight: normal;
}
.attributes dt code, .methods dt code, .constants dt code, .constructors dt code, .fields dt code, .dictionary-members dt code {
font-weight: bold;
color: #000;
font-family: monospace;
}
.attributes dt code, .fields dt code, .dictionary-members dt code {
background: #ffffd2;
}
.attributes dt .idlAttrType code, .fields dt .idlFieldType code, .dictionary-members dt .idlMemberType code {
color: #005a9c;
background: transparent;
font-family: inherit;
font-weight: normal;
font-style: italic;
}
.methods dt code {
background: #d9e6f8;
}
.constants dt code {
background: #ddffd2;
}
.constructors dt code {
background: #cfc;
}
.attributes dd, .methods dd, .constants dd, .constructors dd, .fields dd, .dictionary-members dd {
margin-bottom: 1em;
}
table.parameters, table.exceptions {
border-spacing: 0;
border-collapse: collapse;
margin: 0.5em 0;
width: 100%;
}
table.parameters { border-bottom: 1px solid #90b8de; }
table.exceptions { border-bottom: 1px solid #deb890; }
.parameters th, .exceptions th {
color: #fff;
padding: 3px 5px;
text-align: left;
font-family: initial;
font-weight: normal;
text-shadow: #666 1px 1px 0;
}
.parameters th { background: #90b8de; }
.exceptions th { background: #deb890; }
.parameters td, .exceptions td {
padding: 3px 10px;
border-top: 1px solid #ddd;
vertical-align: top;
}
.parameters tr:first-child td, .exceptions tr:first-child td {
border-top: none;
}
.parameters td.prmName, .exceptions td.excName, .exceptions td.excCodeName {
width: 100px;
}
.parameters td.prmType {
width: 120px;
}
table.exceptions table {
border-spacing: 0;
border-collapse: collapse;
width: 100%;
}
</style><link href="https://www.w3.org/StyleSheets/TR/W3C-WD" rel="stylesheet"><!--[if lt IE 9]><script src='https://www.w3.org/2008/site/js/html5shiv.js'></script><![endif]--></head>
<body id="respecDocument" role="document" class="h-entry"><div id="respecHeader" role="contentinfo" class="head">
<p>
<a href="http://www.w3.org/"><img src="https://www.w3.org/Icons/w3c_home" alt="W3C" height="48" width="72"></a>
</p>
<h1 class="title p-name" id="title" property="dcterms:title">DOM Parsing and Serialization</h1>
<h2 property="bibo:subtitle" id="subtitle">DOMParser, XMLSerializer, innerHTML, and similar APIs</h2>
<h2 id="w3c-last-call-working-draft-10-december-2013" property="dcterms:issued" datatype="xsd:dateTime" content="2013-12-04T02:16:56.000Z"><abbr title="World Wide Web Consortium">W3C</abbr> Last Call Working Draft <time class="dt-published" datetime="2013-12-10">10 December 2013</time></h2>
<dl>
<dt>This version:</dt>
<dd><a class="u-url" href="http://www.w3.org/TR/2013/WD-DOM-Parsing-20131210/">http://www.w3.org/TR/2013/WD-DOM-Parsing-20131210/</a></dd>
<dt>Latest published version:</dt>
<dd><a href="http://www.w3.org/TR/DOM-Parsing/">http://www.w3.org/TR/DOM-Parsing/</a></dd>
<dt>Latest editor's draft:</dt>
<dd><a href="https://dvcs.w3.org/hg/innerhtml/raw-file/tip/index.html">https://dvcs.w3.org/hg/innerhtml/raw-file/tip/index.html</a></dd>
<dt>Test suite:</dt>
<dd><a href="https://github.com/whatwg/domparsing/tree/master/tests">https://github.com/whatwg/domparsing/tree/master/tests</a></dd>
<dt>Previous version:</dt>
<dd><a rel="dcterms:replaces" href="http://www.w3.org/TR/2012/WD-DOM-Parsing-20120920/">http://www.w3.org/TR/2012/WD-DOM-Parsing-20120920/</a></dd>
<dt>Editor:</dt>
<dd class="p-author h-card vcard" rel="bibo:editor" inlist=""><span typeof="foaf:Person"><span property="foaf:name" class="p-name fn">Travis Leithead</span>, <a rel="foaf:workplaceHomepage" class="p-org org h-org h-card" href="http://www.microsoft.com">Microsoft</a>, <span class="ed_mailto"><a class="u-email email" rel="foaf:mbox" href="mailto:travis.leithead@microsoft.com">travis.leithead@microsoft.com</a></span></span>
</dd>
<!-- <dd class="p-author h-card vcard" rel="bibo:editor" inlist=""><span typeof="foaf:Person"><span property="foaf:name" class="p-name fn">Ms2ger</span>, <a rel="foaf:workplaceHomepage" class="p-org org h-org h-card" href="http://www.mozilla.org/">Mozilla</a> (Upstream WHATWG version)</span>
</dd> -->
<!-- <dt>WHATWG Living Standard:</dt>
<dd>
<a href="http://domparsing.spec.whatwg.org/">
http://domparsing.spec.whatwg.org/
</a>
</dd> -->
</dl>
<p class="copyright">
<a href="http://www.w3.org/Consortium/Legal/ipr-notice#Copyright">Copyright</a> ©
2013
<a href="http://www.w3.org/"><abbr title="World Wide Web Consortium">W3C</abbr></a><sup>®</sup>
(<a href="http://www.csail.mit.edu/"><abbr title="Massachusetts Institute of Technology">MIT</abbr></a>,
<a href="http://www.ercim.eu/"><abbr title="European Research Consortium for Informatics and Mathematics">ERCIM</abbr></a>,
<a href="http://www.keio.ac.jp/">Keio</a>, <a href="http://ev.buaa.edu.cn/">Beihang</a>),
All Rights Reserved.
<abbr title="World Wide Web Consortium">W3C</abbr> <a href="http://www.w3.org/Consortium/Legal/ipr-notice#Legal_Disclaimer">liability</a>,
<a href="http://www.w3.org/Consortium/Legal/ipr-notice#W3C_Trademarks">trademark</a> and
<a href="http://www.w3.org/Consortium/Legal/copyright-documents">document use</a>
rules apply.
</p>
<hr>
</div>
<section rel="bibo:Chapter" resource="#ref" typeof="bibo:Chapter" datatype="" property="dcterms:abstract" class="introductory" id="abstract"><h2 id="h2_abstract" role="heading" aria-level="1">Abstract</h2>
<p>This specification defines various APIs for programmatic access to
HTML and generic XML parsers by web applications for use in parsing
and serializing DOM nodes.</p>
</section><section rel="bibo:Chapter" resource="#ref" typeof="bibo:Chapter" id="sotd" class="introductory"><h2 id="h2_sotd" role="heading" aria-level="1">Status of This Document</h2>
<p>
<em>This section describes the status of this document at the time of its publication.
Other documents may supersede this document. A list of current <abbr title="World Wide Web Consortium">W3C</abbr> publications and the
latest revision of this technical report can be found in the <a href="http://www.w3.org/TR/"><abbr title="World Wide Web Consortium">W3C</abbr> technical reports index</a> at
http://www.w3.org/TR/.</em>
</p>
<p>This specification is based on the original work of the <a href="http://domparsing.spec.whatwg.org/">
DOM Parsing and Serialization</a> Living Specification, though it has diverged in terms of
supported features, normative requirements, and algorithm specificity. As appropriate,
relevant fixes from the living standard are incorporated into this document.
</p>
<p>
This document was published by the <a href="http://www.w3.org/2008/webapps/">Web Applications Working Group</a> as a Last Call Working Draft.
This document is intended to become a <abbr title="World Wide Web Consortium">W3C</abbr> Recommendation.
If you wish to make comments regarding this document, please send them to
<a href="mailto:www-dom@w3.org?subject=DOM-Parsing">www-dom@w3.org</a>
(<a href="mailto:www-dom-request@w3.org?subject=subscribe">subscribe</a>,
<a href="http://lists.w3.org/Archives/Public/www-dom/">archives</a>)
with <code>DOM-Parsing</code> at the start of your email's subject.
The Last Call comment period ends 07 January 2014.
All comments are welcome.
</p>
<p>
Publication as a Last Call Working Draft does not imply endorsement by the <abbr title="World Wide Web Consortium">W3C</abbr>
Membership. This is a draft document and may be updated, replaced or obsoleted by other
documents at any time. It is inappropriate to cite this document as other than work in
progress.
</p>
<p>
This is a Last Call Working Draft and thus the Working Group has determined that this
document has satisfied the relevant technical requirements and is sufficiently stable to
advance through the Technical Recommendation process.
</p>
<p>
This document was produced by a group operating under the
<a id="sotd_patent" about="" rel="w3p:patentRules" href="http://www.w3.org/Consortium/Patent-Policy-20040205/">5 February 2004 <abbr title="World Wide Web Consortium">W3C</abbr> Patent
Policy</a>.
<abbr title="World Wide Web Consortium">W3C</abbr> maintains a <a href="http://www.w3.org/2004/01/pp-impl/42538/status" rel="disclosure">public list of any patent
disclosures</a>
made in connection with the deliverables of the group; that page also includes
instructions for disclosing a patent. An individual who has actual knowledge of a patent
which the individual believes contains
<a href="http://www.w3.org/Consortium/Patent-Policy-20040205/#def-essential">Essential
Claim(s)</a> must disclose the information in accordance with
<a href="http://www.w3.org/Consortium/Patent-Policy-20040205/#sec-Disclosure">section
6 of the <abbr title="World Wide Web Consortium">W3C</abbr> Patent Policy</a>.
</p>
</section><section id="toc"><h2 id="h2_toc" role="heading" aria-level="1" class="introductory">Table of Contents</h2><ul id="respecContents" role="directory" class="toc"><li class="tocline"><a class="tocxref" href="#conformance"><span class="secno">1. </span>Conformance</a><ul class="toc"><li class="tocline"><a class="tocxref" href="#dependencies"><span class="secno">1.1 </span>Dependencies</a></li><li class="tocline"><a class="tocxref" href="#extensibility"><span class="secno">1.2 </span>Extensibility</a></li></ul></li><li class="tocline"><a class="tocxref" href="#terminology"><span class="secno">2. </span>Terminology</a></li><li class="tocline"><a class="tocxref" href="#parsing-and-serializing-nodes"><span class="secno">3. </span>Parsing and serializing <span title="node" data-spec="DOM4" class="formerLink">Node</span>s</a><ul class="toc"><li class="tocline"><a class="tocxref" href="#parsing"><span class="secno">3.1 </span>Parsing</a></li><li class="tocline"><a class="tocxref" href="#serializing"><span class="secno">3.2 </span>Serializing</a></li></ul></li><li class="tocline"><a class="tocxref" href="#the-domparser-interface"><span class="secno">4. </span>The <code>DOMParser</code> interface</a><ul class="toc"><li class="tocline"><a class="tocxref" href="#methods"><span class="secno">4.1 </span>Methods</a></li></ul></li><li class="tocline"><a class="tocxref" href="#the-xmlserializer-interface"><span class="secno">5. </span>The <code>XMLSerializer</code> interface</a><ul class="toc"><li class="tocline"><a class="tocxref" href="#methods-1"><span class="secno">5.1 </span>Methods</a></li></ul></li><li class="tocline"><a class="tocxref" href="#extensions-to-the-element-interface"><span class="secno">6. </span>Extensions to the <code><span title="element" data-spec="DOM4" class="formerLink">Element</span></code> interface</a><ul class="toc"><li class="tocline"><a class="tocxref" href="#attributes"><span class="secno">6.1 </span>Attributes</a></li><li class="tocline"><a class="tocxref" href="#methods-2"><span class="secno">6.2 </span>Methods</a></li></ul></li><li class="tocline"><a class="tocxref" href="#extensions-to-the-range-interface"><span class="secno">7. </span>Extensions to the <code><span data-spec="DOM4" title="range" class="formerLink">Range</span></code> interface</a><ul class="toc"><li class="tocline"><a class="tocxref" href="#methods-3"><span class="secno">7.1 </span>Methods</a></li></ul></li><li class="tocline"><a class="tocxref" href="#acknowledgements"><span class="secno">A. </span>Acknowledgements</a></li><li class="tocline"><a class="tocxref" href="#references"><span class="secno">B. </span>References</a><ul class="toc"><li class="tocline"><a class="tocxref" href="#normative-references"><span class="secno">B.1 </span>Normative references</a></li><li class="tocline"><a class="tocxref" href="#informative-references"><span class="secno">B.2 </span>Informative references</a></li></ul></li></ul></section>
<section rel="bibo:Chapter" resource="#ref" typeof="bibo:Chapter" id="issues" class="introductory">
<h1 id="h1_issues" role="heading" aria-level="1">Issues</h1>
<div class="issue"><div id="h_issue_1" role="heading" aria-level="2" class="issue-title"><span>Issue 1</span></div><p class="">Open issues that appear throughout the remainder of this
document will be highlighted like this.</p></div>
<!-- I don't believe this is a point of contention anymore...
<p class="issue">This specification currently requires using the XML
Parser for some APIs, when in an XML document. It is unclear whether
consensus can be found for this approach.</p>
-->
</section>
<section rel="bibo:Chapter" resource="#ref" typeof="bibo:Chapter" id="conformance"><!--OddPage--><h2 id="h2_conformance" role="heading" aria-level="1"><span class="secno">1. </span>Conformance</h2>
<p>
As well as sections marked as non-normative, all authoring guidelines, diagrams, examples,
and notes in this specification are non-normative. Everything else in this specification is
normative.
</p>
<p>
The key words <em title="MUST" class="rfc2119">MUST</em>, <em title="MUST NOT" class="rfc2119">MUST NOT</em>, <em title="REQUIRED" class="rfc2119">REQUIRED</em>, <em title="SHOULD" class="rfc2119">SHOULD</em>, <em title="SHOULD NOT" class="rfc2119">SHOULD NOT</em>, <em title="RECOMMENDED" class="rfc2119">RECOMMENDED</em>, <em title="MAY" class="rfc2119">MAY</em>,
and <em title="OPTIONAL" class="rfc2119">OPTIONAL</em> in this specification are to be interpreted as described in [<cite><a href="#bib-RFC2119" class="bibref">RFC2119</a></cite>].
</p>
<p>Requirements phrased in the imperative as part of algorithms
(such as "strip any leading space characters" or "return false and
terminate these steps") are to be interpreted with the meaning of the
key word ("must", "should", "may", etc) used in introducing the
algorithm.</p>
<p>Conformance requirements phrased as algorithms or specific steps
may be implemented in any manner, so long as the end result is
equivalent. (In particular, the algorithms defined in this
specification are intended to be easy to follow, and not intended to
be performant.)</p>
<p id="hardwareLimitations">User agents may impose
implementation-specific limits on otherwise unconstrained inputs,
e.g. to prevent denial of service attacks, to guard against running
out of memory, or to work around platform-specific limitations.</p>
<p>When a method or an attribute is said to call another method or
attribute, the user agent must invoke its internal API for that
attribute or method so that e.g. the author can't change the behavior
by overriding attributes or methods with custom properties or functions
in ECMAScript.</p>
<p>Unless otherwise stated, string comparisons are done in a <a data-spec="DOM4" class="externalDFN" title="case-sensitive">
case-sensitive</a> manner.</p>
<p>If an algorithm calls into another algorithm, any exception that is
thrown by the latter (unless it is explicitly caught), must cause the
former to terminate, and the exception to be propagated up to
<em>its</em> caller.</p>
<section id="dependencies">
<h3 id="h3_dependencies" role="heading" aria-level="2"><span class="secno">1.1 </span>Dependencies</h3>
<p>The IDL fragments in this specification must be interpreted as
required for conforming IDL fragments, as described in the Web IDL
specification. [<cite><a href="#bib-WEBIDL" class="bibref">WEBIDL</a></cite>]</p>
<p>Some of the terms used in this specification are defined in
[<cite><a href="#bib-DOM4" class="bibref">DOM4</a></cite>], [<cite><a href="#bib-HTML5" class="bibref">HTML5</a></cite>], and [<cite><a href="#bib-XML10" class="bibref">XML10</a></cite>].
</p></section>
<section id="extensibility">
<h3 id="h3_extensibility" role="heading" aria-level="2"><span class="secno">1.2 </span>Extensibility</h3>
<p>Vendor-specific proprietary extensions to this specification are
strongly discouraged. Authors must not use such extensions, as
doing so reduces interoperability and fragments the user base,
allowing only users of specific user agents to access the content in
question.</p>
<p>If vendor-specific extensions are needed, the members should be
prefixed by vendor-specific strings to prevent clashes with future
versions of this specification. Extensions must be defined so that
the use of extensions neither contradicts nor causes the
non-conformance of functionality defined in the specification.</p>
<p>When vendor-neutral extensions to this specification are needed,
either this specification can be updated accordingly, or an
extension specification can be written that overrides the
requirements in this specification. When someone applying this
specification to their activities decides that they will recognise
the requirements of such an extension specification, it becomes an
<dfn id="dfn-other-applicable-specifications" title="other applicable specifications">applicable
specification</dfn> for the purposes of conformance requirements in
this specification.</p>
<!-- http://www.w3.org/mid/17E341CD-E790-422C-9F9A-69347EE01CEB@iki.fi -->
</section>
</section>
<section id="terminology">
<!--OddPage--><h2 id="h2_terminology" role="heading" aria-level="1"><span class="secno">2. </span>Terminology</h2>
<p>The term <dfn id="dfn-context-object">context object</dfn> means the object on which the method or
attribute being discussed was called.
</p></section>
<section id="parsing-and-serializing-nodes">
<!--OddPage--><h2 id="h2_parsing-and-serializing-nodes" role="heading" aria-level="1"><span class="secno">3. </span>Parsing and serializing <a title="node" data-spec="DOM4" class="externalDFN">Node</a>s</h2>
<section id="parsing">
<h3 id="h3_parsing" role="heading" aria-level="2"><span class="secno">3.1 </span>Parsing</h3>
<p>The following steps form the
<dfn id="dfn-concept-parse-fragment" title="concept-parse-fragment">fragment parsing algorithm</dfn>, whose
arguments are a <var>markup</var> string and a
<var>context element</var>.
</p><ol>
<li>
<p>If the <var>context element</var>'s
<a title="concept-node-document" data-spec="DOM4" class="externalDFN">node document</a>
is an <a title="html-document" data-spec="DOM4" class="externalDFN">HTML document</a>: let
<var>algorithm</var> be the
<a title="html-fragment-parsing-algorithm" data-spec="HTML5" class="externalDFN">HTML
fragment parsing algorithm</a>.</p>
<p>If the <var>context element</var>'s
<a title="concept-node-document" data-spec="DOM4" class="externalDFN">node document</a>
is an <a title="xml-document" data-spec="DOM4" class="externalDFN">XML document</a>: let
<var>algorithm</var> be the
<a title="xml-fragment-parsing-algorithm" data-spec="HTML5" class="externalDFN">XML
fragment parsing algorithm</a>.</p>
</li>
<li>Invoke <var>algorithm</var> with <var>markup</var> as
the <var>input</var>, and <var>context element</var> as the
<var><a data-spec="HTML5" title="concept-frag-parse-context" class="externalDFN">context</a></var>
element.</li>
<li>Let <var>new children</var> be the nodes returned.</li>
<li>Let <var>fragment</var> be a new
<code><a title="documentfragment" data-spec="DOM4" class="externalDFN">DocumentFragment</a></code> whose
<a title="concept-node-document" data-spec="DOM4" class="externalDFN">node document</a>
is <var>context element</var>'s
<a title="concept-node-document" data-spec="DOM4" class="externalDFN">node document</a>.
</li><li><a data-spec="DOM4" title="concept-node-append" class="externalDFN">Append</a>
each <a data-spec="DOM4" title="concept-node" class="externalDFN">node</a> in
<var>new children</var> to <var>fragment</var> (in order).
<div class="note"><div id="h_note_1" role="heading" aria-level="3" class="note-title"><span>Note</span></div><p class="">This ensures the
<a title="concept-node-document" data-spec="DOM4" class="externalDFN">node document</a>
for the new <a data-spec="DOM4" title="concept-node" class="externalDFN">nodes</a> is correct.
</p></div></li><li>Return <var>fragment</var>.
</li></ol>
</section>
<section id="serializing">
<h3 id="h3_serializing" role="heading" aria-level="2"><span class="secno">3.2 </span>Serializing</h3>
<p>To <dfn id="dfn-concept-serialize" title="concept-serialize">serialize</dfn> a
<a title="node" data-spec="DOM4" class="externalDFN">Node</a> <var>node</var>, the user agent
must run the following steps:
</p><ol>
<li>Let <var>document</var> be <var>node</var>'s
<a title="concept-node-document" data-spec="DOM4" class="externalDFN">node document</a>.
</li><li>If <var>document</var> is an
<a title="html-document" data-spec="DOM4" class="externalDFN">HTML document</a>,
return an <a class="internalDFN" href="#dfn-concept-serialize-html" title="concept-serialize-html">HTML serialization</a> of <var>node</var>.
</li><li>Otherwise, <var>document</var> is an
<a title="xml-document" data-spec="DOM4" class="externalDFN">XML document</a>.
</li><li>Let <var>context namespace</var> be <code>null</code>.
</li><li>Let <var>prefix list</var> be an empty list. The <var>prefix list</var> will
contain strings that represent a history of namespace prefixes [<cite><a href="#bib-XML-NAMES" class="bibref">XML-NAMES</a></cite>]
that have been serialized by the <a class="internalDFN" href="#dfn-concept-serialize-xml" title="concept-serialize-xml">XML serialization</a>
algorithm for a subtree.
</li><li>Return an <a class="internalDFN" href="#dfn-concept-serialize-xml" title="concept-serialize-xml">XML serialization</a> of <var>node</var>
providing to the algorithm <var>context namespace</var> as the <var>namespace</var>
and <var>prefix list</var> as <var>prefixes</var>.
</li></ol>
<p>To produce an <dfn id="dfn-concept-serialize-html" title="concept-serialize-html">HTML serialization</dfn> of a
<a title="node" data-spec="DOM4" class="externalDFN">Node</a> <var>node</var>, the user agent
must run the
<a data-spec="HTML5" title="html-fragment-serialization-algorithm" class="externalDFN">HTML
fragment serialization algorithm</a> [<cite><a href="#bib-HTML5" class="bibref">HTML5</a></cite>] on <var>node</var> and return the string produced.
</p><p>To produce an <dfn id="dfn-concept-serialize-xml" title="concept-serialize-xml">XML serialization</dfn> of a
<a title="node" data-spec="DOM4" class="externalDFN">Node</a> <var>node</var> given a
context namespace <var>namespace</var> and prefix list <var>prefixes</var>, the user
agent must run the appropriate steps, depending on <var>node</var>'s interface:</p>
<div class="note"><div id="h_note_2" role="heading" aria-level="3" class="note-title"><span>Note</span></div><p class="">The following steps for serializing a <var>node</var> belonging to an
<a title="xml-document" data-spec="DOM4" class="externalDFN">XML document</a> are
designed to produce a serialization that is compatible with the
<a title="html-parser" data-spec="HTML5" class="externalDFN">HTML parser</a>. For example,
elements in the XHTML namespace that contain no child nodes are serialized with
an explicit begin and end tag rather than using the XML self-closing syntax. Exceptions
to this rule occur when an XHTML element's equivalent HTML element is a
<a title="void-elements" data-spec="HTML5" class="externalDFN">void element</a> that
would be auto-closed by the
<a title="html-parser" data-spec="HTML5" class="externalDFN">HTML parser</a>.
</p></div><dl class="switch">
<dt><code><a title="element" data-spec="DOM4" class="externalDFN">Element</a></code>
</dt><dd>
<p>Run the following algorithm:
</p><ol>
<!-- "namespace" was passed via the caller -->
<li>Let <var>markup</var> be an empty string.
</li><li>Let <var>list</var> be a copy of the <var>prefixes</var> array.
</li><li>Let <var>prefix</var> be the value of <var>node</var>'s
<code><a title="dom-Element-prefix" data-spec="DOM4" class="externalDFN">prefix</a></code>
attribute.
</li><li>Let <var>ns</var> be the value of <var>node</var>'s
<code><a title="dom-Element-namespaceURI" data-spec="DOM4" class="externalDFN">namespaceURI</a></code>
attribute.
</li><li>Let a <var>skip end tag</var> flag have the value <code>false</code>.
</li><li>Append "<code><</code>" (U+003C LESS-THAN SIGN) to <var>markup</var>.
</li><li>If <var>prefix</var> is not <code>null</code> then append the following to
<var>markup</var>:
<ol>
<li>The value of <var>prefix</var>;
</li><li>"<code>:</code>" (U+003A COLON).
</li></ol>
</li><li>Append the value of <var>node</var>'s
<code><a title="dom-Element-localName" data-spec="DOM4" class="externalDFN">localName</a></code>
attribute to <var>markup</var>.
<!-- Tried ":" in names, but this doesn't trick the serializer-it just produces
a serialization that is not round-trippable
<p class="issue">escaping / throwing -->
</li><li>If <var>namespace</var> is not equal to <var>ns</var> (the <var>node</var>'s
own namespace is different from its parent), and <var>prefix</var> is not
<code>null</code>, then run these sub-steps:
<div class="note"><div id="h_note_3" role="heading" aria-level="3" class="note-title"><span>Note</span></div><p class="">These steps determine whether a namespace prefix is
serialized for this node.
</p></div><ol>
<li>If <var>list</var> contains the value of <var>prefix</var>, then
abort these sub-steps. This namespace prefix
was already serialized.
</li><li>Add the value of <var>prefix</var> to <var>list</var>.
</li><li>If <var>node</var> has an attribute whose
<a title="concept-attribute-name" data-spec="DOM4" class="externalDFN">name</a>
attribute value is equal to the concatenation of the string
"<code>xmlns:</code>" with the value of <var>prefix</var>, abort
these sub-steps. The <var>prefix</var> namespace definition will be
serialized later as part of the <a class="internalDFN" href="#dfn-concept-serialize-xml-attributes" title="concept-serialize-xml-attributes">XML
serialization of <var>node</var>'s attributes</a>.
</li><li>Append the following to <var>markup</var>, in order:
<ol>
<li>"<code> </code>" (U+0020 SPACE);
</li><li>The string "<code>xmlns:</code>";
</li><li>The value of <var>prefix</var>;
</li><li>"<code>="</code>" (U+003D EQUALS SIGN, U+0022 QUOTATION MARK);
</li><li>The value of <var>ns</var>;
</li><li>"<code>"</code>" (U+0022 QUOTATION MARK);
</li></ol>
</li></ol>
</li><li>If <var>namespace</var> is not equal to <var>ns</var>, and <var>prefix</var>
is <code>null</code>, then run these sub-steps:
<div class="note"><div id="h_note_4" role="heading" aria-level="3" class="note-title"><span>Note</span></div><p class="">These steps determine whether a default namespace is
serialized for this node.
</p></div><ol>
<li>If <var>node</var> has an attribute whose
<a title="concept-attribute-name" data-spec="DOM4" class="externalDFN">name</a>
attribute value is equal to "<code>xmlns</code>", abort
these sub-steps. The default namespace will be
serialized later as part of the <a class="internalDFN" href="#dfn-concept-serialize-xml-attributes" title="concept-serialize-xml-attributes">XML
serialization of <var>node</var>'s attributes</a>.
</li><li>Append the following to <var>markup</var>, in order:
<ol>
<li>"<code> </code>" (U+0020 SPACE);
</li><li>The string "<code>xmlns</code>";
</li><li>"<code>="</code>" (U+003D EQUALS SIGN, U+0022 QUOTATION MARK);
</li><li>The value of <var>ns</var>;
</li><li>"<code>"</code>" (U+0022 QUOTATION MARK);
</li></ol>
</li></ol>
</li><li>Append to <var>markup</var> the result of the
<a class="internalDFN" href="#dfn-concept-serialize-xml-attributes" title="concept-serialize-xml-attributes">XML
serialization of <var>node</var>'s attributes</a>, passing <var>list</var>
as the <var>prefixes</var>.
</li><li>If the value of <var>ns</var> is the string "<code>http://www.w3.org/1999/xhtml</code>",
and the <var>node</var>'s list of
<a title="concept-tree-child" data-spec="DOM4" class="externalDFN">children</a>
is empty, and the <var>node</var>'s
<code><a title="dom-Element-tagName" data-spec="DOM4" class="externalDFN">tagName</a></code>
matches any one of the following
<a title="void-elements" data-spec="HTML5" class="externalDFN">void elements</a>:
"<code>area</code>",
"<code>base</code>",
"<code>br</code>",
"<code>col</code>",
"<code>embed</code>",
"<code>hr</code>",
"<code>img</code>",
"<code>input</code>",
"<code>keygen</code>",
"<code>link</code>",
"<code>menuitem</code>",
"<code>meta</code>",
"<code>param</code>",
"<code>source</code>",
"<code>track</code>",
"<code>wbr</code>";
then append the following to <var>markup</var>, in order:
<ol>
<li>"<code> </code>" (U+0020 SPACE);
</li><li>"<code>/</code>" (U+002F SOLIDUS);
</li></ol>
and set the <var>skip end tag</var> flag to <code>true</code>.
</li><li>If the value of <var>ns</var> is not the string "<code>http://www.w3.org/1999/xhtml</code>",
and the <var>node</var>'s list of
<a title="concept-tree-child" data-spec="DOM4" class="externalDFN">children</a>
is empty, then append "<code>/</code>" (U+002F SOLIDUS) to <var>markup</var>
and set the <var>skip end tag</var> flag to <code>true</code>.
</li><li>Append "<code>></code>" (U+003E GREATER-THAN SIGN) to <var>markup</var>.
</li><li>If the value of <var>skip end tag</var> is <code>true</code>, then return
the value of <var>markup</var> and skip the remaining steps. The
<var>node</var> is a leaf-node.
</li><li>Append to <var>markup</var> the result of performing an
<a class="internalDFN" href="#dfn-concept-serialize-xml" title="concept-serialize-xml">XML serialization</a> of each of
<var>node</var>'s
<a title="concept-tree-child" data-spec="DOM4" class="externalDFN">children</a>,
in order, providing the value of <var>ns</var> for the <var>namespace</var>
and <var>list</var> for the <var>prefixes</var>.
</li><li>Append "<code></</code>" (U+003C LESS-THAN SIGN, U+002F SOLIDUS) to
<var>markup</var>.
</li><li>If the value of <var>prefix</var> is not <code>null</code>, then append the
following to <var>markup</var>, in order:
<ol>
<li>The value of <var>prefix</var>;
</li><li>"<code>:</code>" (U+003A COLON).
</li></ol>
</li><li>Append the value of <var>node</var>'s
<code><a title="dom-Element-localName" data-spec="DOM4" class="externalDFN">localName</a></code>
attribute to <var>markup</var>.
</li><li>Append "<code>></code>" (U+003E GREATER-THAN SIGN) to <var>markup</var>.
</li><li>Return the value of <var>markup</var>.
</li></ol>
</dd><dt><code><a title="document" data-spec="DOM4" class="externalDFN">Document</a></code>
</dt><dd>
<p>Return the result of concatenating the following, in order:
</p><ol>
<li>The string produced by running the steps to
<a class="internalDFN" href="#dfn-concept-serialize-doctype" title="concept-serialize-doctype">produce a DocumentType serialization</a>
of <var>node</var>'s
<a title="dom-Document-doctype" data-spec="HTML5" class="externalDFN">doctype</a>
attribute;
</li><li>The string produced by an <a class="internalDFN" href="#dfn-concept-serialize-xml" title="concept-serialize-xml">XML serialization</a>
of <var>node</var>'s
<a title="dom-Document-documentElement" data-spec="HTML5" class="externalDFN">documentElement</a>
attribute, providing <code>null</code> as the <var>namespace</var> and an
empty list as <var>prefixes</var>.
</li></ol>
</dd><dt><code><a title="comment" data-spec="DOM4" class="externalDFN">Comment</a></code>
</dt><dd><ol>
<li>Let <var>markup</var> be the concatenation of "<code><!--</code>", <var>node</var>'s
<code><a title="dom-characterdata-data" data-spec="DOM4" class="externalDFN">data</a></code>, and
"<code>--></code>".
</li><li>If <var>markup</var> matches the
<code><a data-spec="XML10" title="comment" class="externalDFN">Comment</a></code> production, return
<var>markup</var>. Otherwise, throw a
<code><a title="domexception" data-spec="DOM4" class="externalDFN">DOMException</a></code>
with name <code>InvalidStateError</code>.
</li></ol>
</dd><dt><code><a title="cdata" data-spec="DOML2" class="externalDFN">CDATASection</a></code>
</dt><dd><ol>
<li>Let <var>markup</var> be the concatenation of "<code><![CDATA[</code>",
<var>node</var>'s
<code><a title="dom-characterdata-data" data-spec="DOM4" class="externalDFN">data</a></code>,
and "<code>]]></code>".