CR-DOM-Parsing-20140624.html
changeset 72 e14bd5590323
child 73 d69286304cc3
equal deleted inserted replaced
71:d86d21f30860 72:e14bd5590323
       
     1 <!DOCTYPE html>
       
     2 <html lang="en" dir="ltr" typeof="bibo:Document w3p:CR" about="" property="dcterms:language" content="en">
       
     3 <head>
       
     4     <meta charset="UTF-8">
       
     5     <title>DOM Parsing and Serialization</title>
       
     6     <style>
       
     7         /* Make these stand-out more... */
       
     8         .externalDFN {
       
     9             font-style: italic;
       
    10             background-color: #fff9d6;
       
    11         }
       
    12         /* Switch statement */
       
    13         dl.switch dt::before {
       
    14             content: "↪ ";
       
    15             margin-left: 1em;
       
    16         }
       
    17         /* Better spacing around various lists (implied paragraph children) */
       
    18         ol > li, section:not(#toc) ul > li, section dl > dt {
       
    19             margin: 1em 0;
       
    20         }
       
    21         var { color: maroon; }
       
    22         /* domintro styling */
       
    23         dl.domintro {
       
    24             background-color: rgb(221, 255, 221);
       
    25             padding: 1em 0.5em 1em 2em;
       
    26             clear: both;
       
    27         }
       
    28         dl.domintro dt {
       
    29             color: black;
       
    30         }
       
    31         dl.domintro > dd {
       
    32             color: green;
       
    33         }
       
    34         dl.domintro::before {
       
    35             float: right;
       
    36             background-color: white;
       
    37             display: block;
       
    38             border: 2px solid black;
       
    39             color: green;
       
    40             margin-top: -20px;
       
    41             padding: 2px;
       
    42             content: "This box is non-normative. Implementation requirements are given below this box.";
       
    43         }
       
    44         /* Fancy table stuff */
       
    45         table {
       
    46             border-collapse: collapse;
       
    47         }
       
    48         thead tr {
       
    49             border-bottom: 2px solid black;
       
    50         }
       
    51         tbody tr:not(:last-child) {
       
    52             border-bottom: 1px solid black;
       
    53         }
       
    54         td {
       
    55             border-left: 1px solid black;
       
    56             padding: 4px;
       
    57         }
       
    58         /* Extra IDL :-) */
       
    59         .extraidl {
       
    60             line-height: 120%;
       
    61             padding: 1em;
       
    62             border-top: 1px solid #90b8de;
       
    63             border-bottom: 1px solid #90b8de;
       
    64         }
       
    65         .extraidl:before {
       
    66             width: 150px;
       
    67             color: #fff;
       
    68             padding: 3px;
       
    69             font-weight: bold;
       
    70             font-family: initial;
       
    71             margin: -1em 0 1em -1em;
       
    72             display: block;
       
    73             content: "WebIDL";
       
    74             background-color: rgb(144, 184, 222);
       
    75         }
       
    76     </style>
       
    77     
       
    78     
       
    79 <style>/*****************************************************************
       
    80  * ReSpec 3 CSS
       
    81  * Robin Berjon - http://berjon.com/
       
    82  *****************************************************************/
       
    83 
       
    84 /* --- INLINES --- */
       
    85 em.rfc2119 { 
       
    86     text-transform:     lowercase;
       
    87     font-variant:       small-caps;
       
    88     font-style:         normal;
       
    89     color:              #900;
       
    90 }
       
    91 
       
    92 h1 acronym, h2 acronym, h3 acronym, h4 acronym, h5 acronym, h6 acronym, a acronym,
       
    93 h1 abbr, h2 abbr, h3 abbr, h4 abbr, h5 abbr, h6 abbr, a abbr {
       
    94     border: none;
       
    95 }
       
    96 
       
    97 dfn {
       
    98     font-weight:    bold;
       
    99 }
       
   100 
       
   101 a.internalDFN {
       
   102     color:  inherit;
       
   103     border-bottom:  1px solid #99c;
       
   104     text-decoration:    none;
       
   105 }
       
   106 
       
   107 a.externalDFN {
       
   108     color:  inherit;
       
   109     border-bottom:  1px dotted #ccc;
       
   110     text-decoration:    none;
       
   111 }
       
   112 
       
   113 a.bibref {
       
   114     text-decoration:    none;
       
   115 }
       
   116 
       
   117 cite .bibref {
       
   118     font-style: normal;
       
   119 }
       
   120 
       
   121 code {
       
   122     color:  #ff4500;
       
   123 }
       
   124 
       
   125 /* --- TOC --- */
       
   126 .toc a, .tof a {
       
   127     text-decoration:    none;
       
   128 }
       
   129 
       
   130 a .secno, a .figno {
       
   131     color:  #000;
       
   132 }
       
   133 
       
   134 ul.tof, ol.tof {
       
   135     list-style: none outside none;
       
   136 }
       
   137 
       
   138 .caption {
       
   139     margin-top: 0.5em;
       
   140     font-style:   italic;
       
   141 }
       
   142 
       
   143 /* --- TABLE --- */
       
   144 table.simple {
       
   145     border-spacing: 0;
       
   146     border-collapse:    collapse;
       
   147     border-bottom:  3px solid #005a9c;
       
   148 }
       
   149 
       
   150 .simple th {
       
   151     background: #005a9c;
       
   152     color:  #fff;
       
   153     padding:    3px 5px;
       
   154     text-align: left;
       
   155 }
       
   156 
       
   157 .simple th[scope="row"] {
       
   158     background: inherit;
       
   159     color:  inherit;
       
   160     border-top: 1px solid #ddd;
       
   161 }
       
   162 
       
   163 .simple td {
       
   164     padding:    3px 10px;
       
   165     border-top: 1px solid #ddd;
       
   166 }
       
   167 
       
   168 .simple tr:nth-child(even) {
       
   169     background: #f0f6ff;
       
   170 }
       
   171 
       
   172 /* --- DL --- */
       
   173 .section dd > p:first-child {
       
   174     margin-top: 0;
       
   175 }
       
   176 
       
   177 .section dd > p:last-child {
       
   178     margin-bottom: 0;
       
   179 }
       
   180 
       
   181 .section dd {
       
   182     margin-bottom:  1em;
       
   183 }
       
   184 
       
   185 .section dl.attrs dd, .section dl.eldef dd {
       
   186     margin-bottom:  0;
       
   187 }
       
   188 
       
   189 @media print {
       
   190     .removeOnSave {
       
   191         display: none;
       
   192     }
       
   193 }
       
   194 </style><style>/* --- ISSUES/NOTES --- */
       
   195 div.issue-title, div.note-title {
       
   196     padding-right:  1em;
       
   197     min-width: 7.5em;
       
   198     color: #b9ab2d;
       
   199 }
       
   200 div.issue-title { color: #e05252; }
       
   201 div.note-title { color: #2b2; }
       
   202 div.issue-title span, div.note-title span {
       
   203     text-transform: uppercase;
       
   204 }
       
   205 div.note, div.issue {
       
   206     margin-top: 1em;
       
   207     margin-bottom: 1em;
       
   208 }
       
   209 .note > p:first-child, .issue > p:first-child { margin-top: 0 }
       
   210 .issue, .note {
       
   211     padding: .5em;
       
   212     border-left-width: .5em;
       
   213     border-left-style: solid;
       
   214 }
       
   215 div.issue, div.note {
       
   216     padding: 1em 1.2em 0.5em;
       
   217     margin: 1em 0;
       
   218     position: relative;
       
   219     clear: both;
       
   220 }
       
   221 span.note, span.issue { padding: .1em .5em .15em; }
       
   222 
       
   223 .issue {
       
   224     border-color: #e05252;
       
   225     background: #fbe9e9;
       
   226 }
       
   227 .note {
       
   228     border-color: #52e052;
       
   229     background: #e9fbe9;
       
   230 }
       
   231 
       
   232 
       
   233 </style><style>/* --- WEB IDL --- */
       
   234 pre.idl {
       
   235     border-top: 1px solid #90b8de;
       
   236     border-bottom: 1px solid #90b8de;
       
   237     padding:    1em;
       
   238     line-height:    120%;
       
   239 }
       
   240 
       
   241 pre.idl::before {
       
   242     content:    "WebIDL";
       
   243     display:    block;
       
   244     width:      150px;
       
   245     background: #90b8de;
       
   246     color:  #fff;
       
   247     font-family:    initial;
       
   248     padding:    3px;
       
   249     font-weight:    bold;
       
   250     margin: -1em 0 1em -1em;
       
   251 }
       
   252 
       
   253 .idlType {
       
   254     color:  #ff4500;
       
   255     font-weight:    bold;
       
   256     text-decoration:    none;
       
   257 }
       
   258 
       
   259 /*.idlModule*/
       
   260 /*.idlModuleID*/
       
   261 /*.idlInterface*/
       
   262 .idlInterfaceID, .idlDictionaryID, .idlCallbackID, .idlEnumID {
       
   263     font-weight:    bold;
       
   264     color:  #005a9c;
       
   265 }
       
   266 a.idlEnumItem {
       
   267     color:  #000;
       
   268     border-bottom:  1px dotted #ccc;
       
   269     text-decoration: none;
       
   270 }
       
   271 
       
   272 .idlSuperclass {
       
   273     font-style: italic;
       
   274     color:  #005a9c;
       
   275 }
       
   276 
       
   277 /*.idlAttribute*/
       
   278 .idlAttrType, .idlFieldType, .idlMemberType {
       
   279     color:  #005a9c;
       
   280 }
       
   281 .idlAttrName, .idlFieldName, .idlMemberName {
       
   282     color:  #ff4500;
       
   283 }
       
   284 .idlAttrName a, .idlFieldName a, .idlMemberName a {
       
   285     color:  #ff4500;
       
   286     border-bottom:  1px dotted #ff4500;
       
   287     text-decoration: none;
       
   288 }
       
   289 
       
   290 /*.idlMethod*/
       
   291 .idlMethType, .idlCallbackType {
       
   292     color:  #005a9c;
       
   293 }
       
   294 .idlMethName {
       
   295     color:  #ff4500;
       
   296 }
       
   297 .idlMethName a {
       
   298     color:  #ff4500;
       
   299     border-bottom:  1px dotted #ff4500;
       
   300     text-decoration: none;
       
   301 }
       
   302 
       
   303 /*.idlCtor*/
       
   304 .idlCtorName {
       
   305     color:  #ff4500;
       
   306 }
       
   307 .idlCtorName a {
       
   308     color:  #ff4500;
       
   309     border-bottom:  1px dotted #ff4500;
       
   310     text-decoration: none;
       
   311 }
       
   312 
       
   313 /*.idlParam*/
       
   314 .idlParamType {
       
   315     color:  #005a9c;
       
   316 }
       
   317 .idlParamName, .idlDefaultValue {
       
   318     font-style: italic;
       
   319 }
       
   320 
       
   321 .extAttr {
       
   322     color:  #666;
       
   323 }
       
   324 
       
   325 /*.idlSectionComment*/
       
   326 .idlSectionComment {
       
   327     color: gray;
       
   328 }
       
   329 
       
   330 /*.idlConst*/
       
   331 .idlConstType {
       
   332     color:  #005a9c;
       
   333 }
       
   334 .idlConstName {
       
   335     color:  #ff4500;
       
   336 }
       
   337 .idlConstName a {
       
   338     color:  #ff4500;
       
   339     border-bottom:  1px dotted #ff4500;
       
   340     text-decoration: none;
       
   341 }
       
   342 
       
   343 /*.idlException*/
       
   344 .idlExceptionID {
       
   345     font-weight:    bold;
       
   346     color:  #c00;
       
   347 }
       
   348 
       
   349 .idlTypedefID, .idlTypedefType {
       
   350     color:  #005a9c;
       
   351 }
       
   352 
       
   353 .idlRaises, .idlRaises a.idlType, .idlRaises a.idlType code, .excName a, .excName a code {
       
   354     color:  #c00;
       
   355     font-weight:    normal;
       
   356 }
       
   357 
       
   358 .excName a {
       
   359     font-family:    monospace;
       
   360 }
       
   361 
       
   362 .idlRaises a.idlType, .excName a.idlType {
       
   363     border-bottom:  1px dotted #c00;
       
   364 }
       
   365 
       
   366 .excGetSetTrue, .excGetSetFalse, .prmNullTrue, .prmNullFalse, .prmOptTrue, .prmOptFalse {
       
   367     width:  45px;
       
   368     text-align: center;
       
   369 }
       
   370 .excGetSetTrue, .prmNullTrue, .prmOptTrue { color:  #0c0; }
       
   371 .excGetSetFalse, .prmNullFalse, .prmOptFalse { color:  #c00; }
       
   372 
       
   373 .idlImplements a {
       
   374     font-weight:    bold;
       
   375 }
       
   376 
       
   377 dl.attributes, dl.methods, dl.constants, dl.constructors, dl.fields, dl.dictionary-members {
       
   378     margin-left:    2em;
       
   379 }
       
   380 
       
   381 .attributes dt, .methods dt, .constants dt, .constructors dt, .fields dt, .dictionary-members dt {
       
   382     font-weight:    normal;
       
   383 }
       
   384 
       
   385 .attributes dt code, .methods dt code, .constants dt code, .constructors dt code, .fields dt code, .dictionary-members dt code {
       
   386     font-weight:    bold;
       
   387     color:  #000;
       
   388     font-family:    monospace;
       
   389 }
       
   390 
       
   391 .attributes dt code, .fields dt code, .dictionary-members dt code {
       
   392     background:  #ffffd2;
       
   393 }
       
   394 
       
   395 .attributes dt .idlAttrType code, .fields dt .idlFieldType code, .dictionary-members dt .idlMemberType code {
       
   396     color:  #005a9c;
       
   397     background:  transparent;
       
   398     font-family:    inherit;
       
   399     font-weight:    normal;
       
   400     font-style: italic;
       
   401 }
       
   402 
       
   403 .methods dt code {
       
   404     background:  #d9e6f8;
       
   405 }
       
   406 
       
   407 .constants dt code {
       
   408     background:  #ddffd2;
       
   409 }
       
   410 
       
   411 .constructors dt code {
       
   412     background:  #cfc;
       
   413 }
       
   414 
       
   415 .attributes dd, .methods dd, .constants dd, .constructors dd, .fields dd, .dictionary-members dd {
       
   416     margin-bottom:  1em;
       
   417 }
       
   418 
       
   419 table.parameters, table.exceptions {
       
   420     border-spacing: 0;
       
   421     border-collapse:    collapse;
       
   422     margin: 0.5em 0;
       
   423     width:  100%;
       
   424 }
       
   425 table.parameters { border-bottom:  1px solid #90b8de; }
       
   426 table.exceptions { border-bottom:  1px solid #deb890; }
       
   427 
       
   428 .parameters th, .exceptions th {
       
   429     color:  #fff;
       
   430     padding:    3px 5px;
       
   431     text-align: left;
       
   432     font-family:    initial;
       
   433     font-weight:    normal;
       
   434     text-shadow:    #666 1px 1px 0;
       
   435 }
       
   436 .parameters th { background: #90b8de; }
       
   437 .exceptions th { background: #deb890; }
       
   438 
       
   439 .parameters td, .exceptions td {
       
   440     padding:    3px 10px;
       
   441     border-top: 1px solid #ddd;
       
   442     vertical-align: top;
       
   443 }
       
   444 
       
   445 .parameters tr:first-child td, .exceptions tr:first-child td {
       
   446     border-top: none;
       
   447 }
       
   448 
       
   449 .parameters td.prmName, .exceptions td.excName, .exceptions td.excCodeName {
       
   450     width:  100px;
       
   451 }
       
   452 
       
   453 .parameters td.prmType {
       
   454     width:  120px;
       
   455 }
       
   456 
       
   457 table.exceptions table {
       
   458     border-spacing: 0;
       
   459     border-collapse:    collapse;
       
   460     width:  100%;
       
   461 }
       
   462 </style><link href="https://www.w3.org/StyleSheets/TR/W3C-CR" rel="stylesheet"><!--[if lt IE 9]><script src='https://www.w3.org/2008/site/js/html5shiv.js'></script><![endif]--></head>
       
   463 <body class="h-entry" id="respecDocument" role="document"><div class="head" id="respecHeader" role="contentinfo">
       
   464   <p>
       
   465     
       
   466       <a href="http://www.w3.org/"><img width="72" height="48" alt="W3C" src="https://www.w3.org/Icons/w3c_home"></a>
       
   467     
       
   468   </p>
       
   469   <h1 class="title p-name" id="title" property="dcterms:title">DOM Parsing and Serialization</h1>
       
   470   
       
   471     <h2 id="subtitle" property="bibo:subtitle">DOMParser, XMLSerializer, innerHTML, and similar APIs</h2>
       
   472   
       
   473   <h2 id="w3c-candidate-recommendation-24-june-2014" property="dcterms:issued" content="2014-06-24T07:00:00.000Z" datatype="xsd:dateTime"><abbr title="World Wide Web Consortium">W3C</abbr> Candidate Recommendation <time class="dt-published" datetime="2014-06-24">24 June 2014</time></h2>
       
   474   <dl>
       
   475     
       
   476       <dt>This version:</dt>
       
   477       <dd><a class="u-url" href="http://www.w3.org/TR/2014/CR-DOM-Parsing-20140624/">http://www.w3.org/TR/2014/CR-DOM-Parsing-20140624/</a></dd>
       
   478       <dt>Latest published version:</dt>
       
   479       <dd><a href="http://www.w3.org/TR/DOM-Parsing/">http://www.w3.org/TR/DOM-Parsing/</a></dd>
       
   480     
       
   481     
       
   482       <dt>Latest editor's draft:</dt>
       
   483       <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>
       
   484     
       
   485     
       
   486       <dt>Test suite:</dt>
       
   487       <dd><a href="http://w3c-test.org/domparsing/">http://w3c-test.org/domparsing/</a></dd>
       
   488     
       
   489     
       
   490       <dt>Implementation report:</dt>
       
   491       <dd><a href="https://dvcs.w3.org/hg/innerhtml/raw-file/tip/implementationReport.html">https://dvcs.w3.org/hg/innerhtml/raw-file/tip/implementationReport.html</a></dd>
       
   492     
       
   493     
       
   494     
       
   495     
       
   496       <dt>Previous version:</dt>
       
   497       <dd><a href="http://www.w3.org/TR/2014/WD-DOM-Parsing-20140501/" rel="dcterms:replaces">http://www.w3.org/TR/2014/WD-DOM-Parsing-20140501/</a></dd>
       
   498     
       
   499     
       
   500     <dt>Editor:</dt>
       
   501     <dd class="p-author h-card vcard" inlist="" rel="bibo:editor"><span typeof="foaf:Person"><span class="p-name fn" property="foaf:name">Travis Leithead</span>, <a class="p-org org h-org h-card" href="http://www.microsoft.com" rel="foaf:workplaceHomepage">Microsoft</a>, <span class="ed_mailto"><a class="u-email email" href="mailto:travis.leithead@microsoft.com" rel="foaf:mbox">travis.leithead@microsoft.com</a></span></span>
       
   502 </dd>
       
   503 
       
   504     
       
   505     
       
   506   </dl>
       
   507   
       
   508   
       
   509   
       
   510   
       
   511     
       
   512       <p class="copyright">
       
   513         <a href="http://www.w3.org/Consortium/Legal/ipr-notice#Copyright">Copyright</a> ©
       
   514         2014
       
   515         
       
   516         <a href="http://www.w3.org/"><abbr title="World Wide Web Consortium">W3C</abbr></a><sup>®</sup>
       
   517         (<a href="http://www.csail.mit.edu/"><abbr title="Massachusetts Institute of Technology">MIT</abbr></a>,
       
   518         <a href="http://www.ercim.eu/"><abbr title="European Research Consortium for Informatics and Mathematics">ERCIM</abbr></a>,
       
   519         <a href="http://www.keio.ac.jp/">Keio</a>, <a href="http://ev.buaa.edu.cn/">Beihang</a>), 
       
   520         
       
   521         All Rights Reserved.
       
   522         
       
   523         <abbr title="World Wide Web Consortium">W3C</abbr> <a href="http://www.w3.org/Consortium/Legal/ipr-notice#Legal_Disclaimer">liability</a>,
       
   524         <a href="http://www.w3.org/Consortium/Legal/ipr-notice#W3C_Trademarks">trademark</a> and
       
   525         
       
   526           <a href="http://www.w3.org/Consortium/Legal/copyright-documents">document use</a>
       
   527         
       
   528         rules apply.
       
   529       </p>
       
   530     
       
   531   
       
   532   <hr>
       
   533 </div>
       
   534 
       
   535     <section class="introductory" id="abstract" typeof="bibo:Chapter" property="dcterms:abstract" datatype="" rel="bibo:Chapter" resource="#abstract"><h2 id="h2_abstract" role="heading" aria-level="1">Abstract</h2>
       
   536        <p>This specification defines various APIs for programmatic access to
       
   537           HTML and generic XML parsers by web applications for use in parsing
       
   538           and serializing DOM nodes.</p>
       
   539     </section><section class="introductory" id="sotd" typeof="bibo:Chapter" rel="bibo:Chapter" resource="#sotd"><h2 id="h2_sotd" role="heading" aria-level="1">Status of This Document</h2>
       
   540   
       
   541     
       
   542       
       
   543         <p>
       
   544           <em>This section describes the status of this document at the time of its publication.
       
   545           Other documents may supersede this document. A list of current <abbr title="World Wide Web Consortium">W3C</abbr> publications and the
       
   546           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
       
   547           http://www.w3.org/TR/.</em>
       
   548         </p>
       
   549         
       
   550         <p>This specification is based on the original work of the <a href="http://domparsing.spec.whatwg.org/">
       
   551             DOM Parsing and Serialization</a> Living Specification, though it has diverged in terms of
       
   552             supported features, normative requirements, and algorithm specificity. As appropriate,
       
   553             relevant fixes from the living specification are incorporated into this document.
       
   554     </p>
       
   555         <p>
       
   556           This document was published by the <a href="http://www.w3.org/2008/webapps/">Web Applications Working Group</a> as a Candidate Recommendation.
       
   557           
       
   558             This document is intended to become a <abbr title="World Wide Web Consortium">W3C</abbr> Recommendation.
       
   559           
       
   560           
       
   561             If you wish to make comments regarding this document, please send them to 
       
   562             <a href="mailto:www-dom@w3.org?subject=DOM-Parsing">www-dom@w3.org</a> 
       
   563             (<a href="mailto:www-dom-request@w3.org?subject=subscribe">subscribe</a>,
       
   564             <a href="http://lists.w3.org/Archives/Public/www-dom/">archives</a>)
       
   565               with <code>DOM-Parsing</code> at the start of your email's subject.
       
   566           
       
   567           
       
   568           
       
   569             <abbr title="World Wide Web Consortium">W3C</abbr> publishes a Candidate Recommendation to indicate that the document is believed to be
       
   570             stable and to encourage implementation by the developer community. This Candidate
       
   571             Recommendation is expected to advance to Proposed Recommendation no earlier than
       
   572             24 October 2014.
       
   573           
       
   574           
       
   575             All comments are welcome.
       
   576           
       
   577         </p>
       
   578         
       
   579           <p>
       
   580             Please see the Working Group's  <a href="https://dvcs.w3.org/hg/innerhtml/raw-file/tip/implementationReport.html">implementation
       
   581             report</a>.
       
   582           </p>
       
   583         
       
   584         
       
   585           <p>
       
   586             Publication as a Candidate Recommendation does not imply endorsement by the <abbr title="World Wide Web Consortium">W3C</abbr>
       
   587             Membership. This is a draft document and may be updated, replaced or obsoleted by other
       
   588             documents at any time. It is inappropriate to cite this document as other than work in
       
   589             progress.
       
   590           </p>
       
   591         
       
   592         
       
   593         
       
   594         <p>
       
   595           
       
   596             This document was produced by a group operating under the 
       
   597             <a id="sotd_patent" href="http://www.w3.org/Consortium/Patent-Policy-20040205/" rel="w3p:patentRules" about="">5 February 2004 <abbr title="World Wide Web Consortium">W3C</abbr> Patent
       
   598             Policy</a>.
       
   599           
       
   600           
       
   601           
       
   602             
       
   603               <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
       
   604               disclosures</a> 
       
   605             
       
   606             made in connection with the deliverables of the group; that page also includes
       
   607             instructions for disclosing a patent. An individual who has actual knowledge of a patent
       
   608             which the individual believes contains
       
   609             <a href="http://www.w3.org/Consortium/Patent-Policy-20040205/#def-essential">Essential
       
   610             Claim(s)</a> must disclose the information in accordance with
       
   611             <a href="http://www.w3.org/Consortium/Patent-Policy-20040205/#sec-Disclosure">section
       
   612             6 of the <abbr title="World Wide Web Consortium">W3C</abbr> Patent Policy</a>.
       
   613           
       
   614           
       
   615         </p>
       
   616         
       
   617       
       
   618     
       
   619   
       
   620 </section><section id="toc"><h2 class="introductory" id="h2_toc" role="heading" aria-level="1">Table of Contents</h2><ul class="toc" id="respecContents" role="directory"><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="#namespaces"><span class="secno">3. </span>Namespaces</a></li><li class="tocline"><a class="tocxref" href="#parsing-and-serializing-nodes"><span class="secno">4. </span>Parsing and serializing <span title="node" class="formerLink">Node</span>s</a><ul class="toc"><li class="tocline"><a class="tocxref" href="#parsing"><span class="secno">4.1 </span>Parsing</a></li><li class="tocline"><a class="tocxref" href="#serializing"><span class="secno">4.2 </span>Serializing</a></li></ul></li><li class="tocline"><a class="tocxref" href="#the-domparser-interface"><span class="secno">5. </span>The <code>DOMParser</code> interface</a><ul class="toc"><li class="tocline"><a class="tocxref" href="#methods"><span class="secno">5.1 </span>Methods</a></li></ul></li><li class="tocline"><a class="tocxref" href="#the-xmlserializer-interface"><span class="secno">6. </span>The <code>XMLSerializer</code> interface</a><ul class="toc"><li class="tocline"><a class="tocxref" href="#methods-1"><span class="secno">6.1 </span>Methods</a></li></ul></li><li class="tocline"><a class="tocxref" href="#extensions-to-the-element-interface"><span class="secno">7. </span>Extensions to the <code><span title="element" class="formerLink">Element</span></code> interface</a><ul class="toc"><li class="tocline"><a class="tocxref" href="#attributes"><span class="secno">7.1 </span>Attributes</a></li><li class="tocline"><a class="tocxref" href="#methods-2"><span class="secno">7.2 </span>Methods</a></li></ul></li><li class="tocline"><a class="tocxref" href="#extensions-to-the-range-interface"><span class="secno">8. </span>Extensions to the <code><span title="range" class="formerLink">Range</span></code> interface</a><ul class="toc"><li class="tocline"><a class="tocxref" href="#methods-3"><span class="secno">8.1 </span>Methods</a></li></ul></li><li class="tocline"><a class="tocxref" href="#revision-history"><span class="secno">A. </span>Revision History</a></li><li class="tocline"><a class="tocxref" href="#acknowledgements"><span class="secno">B. </span>Acknowledgements</a></li><li class="tocline"><a class="tocxref" href="#references"><span class="secno">C. </span>References</a><ul class="toc"><li class="tocline"><a class="tocxref" href="#normative-references"><span class="secno">C.1 </span>Normative references</a></li><li class="tocline"><a class="tocxref" href="#informative-references"><span class="secno">C.2 </span>Informative references</a></li></ul></li></ul></section>
       
   621 
       
   622     
       
   623 
       
   624     <section class="introductory" id="crec" typeof="bibo:Chapter" rel="bibo:Chapter" resource="#crec">
       
   625         <h2 id="h2_crec" role="heading" aria-level="1">Candidate Recommendation Exit Criteria</h2>
       
   626         <p>This specification will not advance to Proposed Recommendation before the spec's 
       
   627             <a href="http://w3c-test.org/domparsing/">test suite</a> is completed and two or 
       
   628             more independent implementations pass each test, although no single implementation 
       
   629             must pass each test. We expect to meet this criteria no sooner than 24 October 2014.
       
   630             The group will also create an 
       
   631             <a href="https://dvcs.w3.org/hg/innerhtml/raw-file/tip/implementationReport.html">Implementation Report</a>.
       
   632     </p></section>
       
   633     
       
   634     <!-- <section id="issues" class="introductory">
       
   635         <h1>Issues</h1>
       
   636 
       
   637         <p class=issue>Open issues that appear throughout the remainder of this
       
   638         document will be highlighted like this.</p>
       
   639     </section> -->
       
   640 
       
   641     <section id="conformance" typeof="bibo:Chapter" rel="bibo:Chapter" resource="#conformance"><!--OddPage--><h2 id="h2_conformance" role="heading" aria-level="1"><span class="secno">1. </span>Conformance</h2>
       
   642 <p>
       
   643   As well as sections marked as non-normative, all authoring guidelines, diagrams, examples,
       
   644   and notes in this specification are non-normative. Everything else in this specification is
       
   645   normative.
       
   646 </p>
       
   647 <p>
       
   648   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>,
       
   649   and <em title="OPTIONAL" class="rfc2119">OPTIONAL</em> in this specification are to be interpreted as described in [<cite><a class="bibref" href="#bib-RFC2119">RFC2119</a></cite>].
       
   650 </p>
       
   651 
       
   652         <p>Requirements phrased in the imperative as part of algorithms
       
   653         (such as "strip any leading space characters" or "return false and
       
   654         terminate these steps") are to be interpreted with the meaning of the
       
   655         key word ("must", "should", "may", etc) used in introducing the
       
   656         algorithm.</p>
       
   657 
       
   658         <p>Conformance requirements phrased as algorithms or specific steps
       
   659         may be implemented in any manner, so long as the end result is
       
   660         equivalent. (In particular, the algorithms defined in this
       
   661         specification are intended to be easy to follow, and not intended to
       
   662         be performant.)</p>
       
   663 
       
   664         <p id="hardwareLimitations">User agents may impose
       
   665         implementation-specific limits on otherwise unconstrained inputs,
       
   666         e.g. to prevent denial of service attacks, to guard against running
       
   667         out of memory, or to work around platform-specific limitations.</p>
       
   668 
       
   669         <p>When a method or an attribute is said to call another method or
       
   670         attribute, the user agent must invoke its internal API for that
       
   671         attribute or method so that e.g. the author can't change the behavior
       
   672         by overriding attributes or methods with custom properties or functions
       
   673         in ECMAScript.</p>
       
   674 
       
   675         <p>Unless otherwise stated, string comparisons are done in a <a title="case-sensitive" class="externalDFN" href="http://www.w3.org/TR/dom/#case-sensitive">
       
   676         case-sensitive</a> manner.</p>
       
   677 
       
   678         <p>If an algorithm calls into another algorithm, any exception that is
       
   679         thrown by the latter (unless it is explicitly caught), must cause the
       
   680         former to terminate, and the exception to be propagated up to
       
   681         <em>its</em> caller.</p>
       
   682 
       
   683         <section id="dependencies">
       
   684             <h3 id="h3_dependencies" role="heading" aria-level="2"><span class="secno">1.1 </span>Dependencies</h3>
       
   685 
       
   686             <p>The IDL fragments in this specification must be interpreted as
       
   687             required for conforming IDL fragments, as described in the Web IDL
       
   688             specification. [<cite><a class="bibref" href="#bib-WEBIDL">WEBIDL</a></cite>]</p>
       
   689 
       
   690             <p>Some of the terms used in this specification are defined in
       
   691             [<cite><a class="bibref" href="#bib-DOM4">DOM4</a></cite>], [<cite><a class="bibref" href="#bib-HTML5">HTML5</a></cite>], and [<cite><a class="bibref" href="#bib-XML10">XML10</a></cite>].
       
   692         </p></section>
       
   693 
       
   694         <section id="extensibility">
       
   695             <h3 id="h3_extensibility" role="heading" aria-level="2"><span class="secno">1.2 </span>Extensibility</h3>
       
   696 
       
   697             <p>Vendor-specific proprietary extensions to this specification are
       
   698             strongly discouraged. Authors must not use such extensions, as
       
   699             doing so reduces interoperability and fragments the user base,
       
   700             allowing only users of specific user agents to access the content in
       
   701             question.</p>
       
   702 
       
   703             <p>If vendor-specific extensions are needed, the members should be
       
   704             prefixed by vendor-specific strings to prevent clashes with future
       
   705             versions of this specification. Extensions must be defined so that
       
   706             the use of extensions neither contradicts nor causes the
       
   707             non-conformance of functionality defined in the specification.</p>
       
   708 
       
   709             <p>When vendor-neutral extensions to this specification are needed,
       
   710             either this specification can be updated accordingly, or an
       
   711             extension specification can be written that overrides the
       
   712             requirements in this specification. When someone applying this
       
   713             specification to their activities decides that they will recognise
       
   714             the requirements of such an extension specification, it becomes an
       
   715             <dfn title="other applicable specifications" id="dfn-other-applicable-specifications">applicable
       
   716             specification</dfn> for the purposes of conformance requirements in
       
   717             this specification.</p>
       
   718             <!-- http://www.w3.org/mid/17E341CD-E790-422C-9F9A-69347EE01CEB@iki.fi -->
       
   719         </section>
       
   720     </section>
       
   721 
       
   722     <section id="terminology">
       
   723         <!--OddPage--><h2 id="h2_terminology" role="heading" aria-level="1"><span class="secno">2. </span>Terminology</h2>
       
   724 
       
   725         <p>The term <dfn id="dfn-context-object">context object</dfn> means the object on which the method or
       
   726         attribute being discussed was called.
       
   727     </p></section>
       
   728 
       
   729     <section id="namespaces">
       
   730         <!--OddPage--><h2 id="h2_namespaces" role="heading" aria-level="1"><span class="secno">3. </span>Namespaces</h2>
       
   731 
       
   732         <p>The <dfn title="html-ns" id="dfn-html-ns">HTML namespace</dfn> is <code>http://www.w3.org/1999/xhtml</code>.
       
   733         <p>The <dfn title="xml-ns" id="dfn-xml-ns">XML namespace</dfn> is <code>http://www.w3.org/XML/1998/namespace</code>.
       
   734         <p>The <dfn title="xmlns-ns" id="dfn-xmlns-ns">XMLNS namespace</dfn> is <code>http://www.w3.org/2000/xmlns/</code>.
       
   735     </p></section>
       
   736 
       
   737     <section id="parsing-and-serializing-nodes">
       
   738         <!--OddPage--><h2 id="h2_parsing-and-serializing-nodes" role="heading" aria-level="1"><span class="secno">4. </span>Parsing and serializing <a title="node" class="externalDFN" href="http://www.w3.org/TR/dom/#node">Node</a>s</h2>
       
   739 
       
   740         <section id="parsing">
       
   741             <h3 id="h3_parsing" role="heading" aria-level="2"><span class="secno">4.1 </span>Parsing</h3>
       
   742 
       
   743             <p>The following steps form the
       
   744             <dfn title="concept-parse-fragment" id="dfn-concept-parse-fragment">fragment parsing algorithm</dfn>, whose
       
   745             arguments are a <var>markup</var> string and a
       
   746             <var>context element</var>:
       
   747 
       
   748             <ol>
       
   749               <li>
       
   750                 <p>If the <var>context element</var>'s
       
   751                 <a title="concept-node-document" class="externalDFN" href="http://www.w3.org/TR/dom/#concept-node-document">node document</a>
       
   752                 is an <a title="html-document" class="externalDFN" href="http://www.w3.org/TR/dom/#html-document">HTML document</a>: let
       
   753                 <var>algorithm</var> be the
       
   754                 <a title="html-fragment-parsing-algorithm" class="externalDFN" href="http://www.w3.org/TR/html5/single-page.html#html-fragment-parsing-algorithm">HTML
       
   755                 fragment parsing algorithm</a>.</p>
       
   756 
       
   757                 <p>If the <var>context element</var>'s
       
   758                 <a title="concept-node-document" class="externalDFN" href="http://www.w3.org/TR/dom/#concept-node-document">node document</a>
       
   759                 is an <a title="xml-document" class="externalDFN" href="http://www.w3.org/TR/dom/#xml-document">XML document</a>: let
       
   760                 <var>algorithm</var> be the
       
   761                 <a title="xml-fragment-parsing-algorithm" class="externalDFN" href="http://www.w3.org/TR/html5/single-page.html#xml-fragment-parsing-algorithm">XML
       
   762                 fragment parsing algorithm</a>.</p>
       
   763               </li>
       
   764 
       
   765               <li>Let <var>new children</var> be the result of invoking <var>algorithm</var> with <var>markup</var> as
       
   766               the <var>input</var>, and <var>context element</var> as the
       
   767               <var><a title="concept-frag-parse-context" class="externalDFN" href="http://www.w3.org/TR/html5/single-page.html#concept-frag-parse-context">context</a></var>
       
   768               element.</li>
       
   769 
       
   770               <li>Let <var>fragment</var> be a new
       
   771               <code><a title="documentfragment" class="externalDFN" href="http://www.w3.org/TR/dom/#documentfragment">DocumentFragment</a></code> whose
       
   772               <a title="concept-node-document" class="externalDFN" href="http://www.w3.org/TR/dom/#concept-node-document">node document</a>
       
   773               is <var>context element</var>'s
       
   774               <a title="concept-node-document" class="externalDFN" href="http://www.w3.org/TR/dom/#concept-node-document">node document</a>.
       
   775 
       
   776               <li><a title="concept-node-append" class="externalDFN" href="http://www.w3.org/TR/dom/#concept-node-append">Append</a>
       
   777               each <a title="concept-node" class="externalDFN" href="http://www.w3.org/TR/dom/#concept-node">node</a> in
       
   778               <var>new children</var> to <var>fragment</var>
       
   779               (in <a title="concept-tree-order" class="externalDFN" href="http://www.w3.org/TR/dom/#concept-tree-order">tree order</a>).
       
   780 
       
   781               <div class="note"><div class="note-title" id="h_note_1" role="heading" aria-level="3"><span>Note</span></div><p>This ensures the
       
   782               <a title="concept-node-document" class="externalDFN" href="http://www.w3.org/TR/dom/#concept-node-document">node document</a>
       
   783               for the new <a title="concept-node" class="externalDFN" href="http://www.w3.org/TR/dom/#concept-node">nodes</a> is correct.
       
   784 
       
   785               </p></div><li>Return the value of <var>fragment</var>.
       
   786             </li></ol>
       
   787     </section>
       
   788 
       
   789     <section id="serializing">
       
   790         <h3 id="h3_serializing" role="heading" aria-level="2"><span class="secno">4.2 </span>Serializing</h3>
       
   791         <p>The following steps form the
       
   792             <dfn title="concept-fragment-serializing-algorithm" id="dfn-concept-fragment-serializing-algorithm">fragment serializing algorithm</dfn>,
       
   793             whose arguments are a <code><a title="node" class="externalDFN" href="http://www.w3.org/TR/dom/#node">Node</a></code>
       
   794             <var>node</var> and a flag <dfn title="concept-well-formed" id="dfn-concept-well-formed">require well-formed</dfn>:
       
   795 
       
   796         <ol>
       
   797             <li>Let <var>context document</var> be the value of <var>node</var>'s
       
   798                 <a title="concept-node-document" class="externalDFN" href="http://www.w3.org/TR/dom/#concept-node-document">node document</a>.
       
   799             <li>If <var>context document</var> is an
       
   800                 <a title="html-document" class="externalDFN" href="http://www.w3.org/TR/dom/#html-document">HTML document</a>,
       
   801                 return an <a title="concept-serialize-html" class="internalDFN" href="#dfn-concept-serialize-html">HTML serialization</a> of <var>node</var>.
       
   802             <li>Otherwise, <var>context document</var> is an
       
   803                 <a title="xml-document" class="externalDFN" href="http://www.w3.org/TR/dom/#xml-document">XML document</a>;
       
   804                 return an <a title="concept-serialize-xml" class="internalDFN" href="#dfn-concept-serialize-xml">XML serialization</a> of <var>node</var>
       
   805                 passing the flag <var>require well-formed</var>.
       
   806             <div class="note"><div class="note-title" id="h_note_2" role="heading" aria-level="3"><span>Note</span></div><p>The <a title="concept-serialize-xml" class="internalDFN" href="#dfn-concept-serialize-xml">XML serialization</a> defined in this document
       
   807                 conforms to the requirements of the <a title="xml-fragment-serialization-algorithm" class="externalDFN" href="http://www.w3.org/TR/html5/single-page.html#xml-fragment-serialization-algorithm">XML fragment serialization algorithm</a> defined in [<cite><a class="bibref" href="#bib-HTML5">HTML5</a></cite>].</p></div>
       
   808         </li></ol>
       
   809 
       
   810         <p>To produce an <dfn title="concept-serialize-html" id="dfn-concept-serialize-html">HTML serialization</dfn> of a
       
   811             <code><a title="node" class="externalDFN" href="http://www.w3.org/TR/dom/#node">Node</a></code> <var>node</var>, the user agent
       
   812             must run the
       
   813             <a title="html-fragment-serialization-algorithm" class="externalDFN" href="http://www.w3.org/TR/html5/single-page.html#html-fragment-serialization-algorithm">HTML
       
   814             fragment serialization algorithm</a> [<cite><a class="bibref" href="#bib-HTML5">HTML5</a></cite>] on <var>node</var> and return the string produced.
       
   815 
       
   816         <p>To produce an <dfn title="concept-serialize-xml" id="dfn-concept-serialize-xml">XML serialization</dfn> of a
       
   817             <code><a title="node" class="externalDFN" href="http://www.w3.org/TR/dom/#node">Node</a></code> <var>node</var> given a
       
   818             flag <var>require well-formed</var>, run the following steps:
       
   819         <ol>
       
   820             <li>Let <dfn title="concept-context-namespace" id="dfn-concept-context-namespace">context namespace</dfn> be <code>null</code>.
       
   821                 The <a title="concept-context-namespace" class="internalDFN" href="#dfn-concept-context-namespace">context namespace</a> is changed when a
       
   822                 <var>node</var> serializes a different default namespace definition from its parent. The
       
   823                 algorithm assumes no namespace to start.
       
   824             <li>Let <dfn title="concept-namespace-prefix-map" id="dfn-concept-namespace-prefix-map">namespace prefix map</dfn> be a new map
       
   825                 for associating <code>namespaceURI</code> and namespace <code>prefix</code> pairs, where
       
   826                 <code>namespaceURI</code> values are the map's keys, and <code>prefix</code> values are
       
   827                 the map's key values. The <a title="concept-namespace-prefix-map" class="internalDFN" href="#dfn-concept-namespace-prefix-map">namespace prefix map</a>
       
   828                 will be populated by previously seen namespaceURIs and their most recent prefix associations
       
   829                 for a subtree. <span class="note"><strong>Note:</strong> the
       
   830                 <a title="concept-namespace-prefix-map" class="internalDFN" href="#dfn-concept-namespace-prefix-map">namespace prefix map</a> only associates a single
       
   831                 prefix value with a given namespaceURI. During serialization, if different namespace prefixes
       
   832                 are found that map to the same namespaceURI, the last one encountered "wins" by replacing the
       
   833                 existing key value in the map with the new prefix value.</span>
       
   834             <li>Initialize the <a title="concept-namespace-prefix-map" class="internalDFN" href="#dfn-concept-namespace-prefix-map">namespace prefix map</a> with the
       
   835                 <a title="xml-ns" class="internalDFN" href="#dfn-xml-ns">XML namespace</a> key and string "<code>xml</code>" as the key value.
       
   836             <li>Let <dfn title="concept-generated-prefix" id="dfn-concept-generated-prefix">generated namespace prefix index</dfn> be an integer
       
   837                 with a value of <code>1</code>. The <a title="concept-generated-prefix" class="internalDFN" href="#dfn-concept-generated-prefix">generated namespace
       
   838                 prefix index</a> is used to generate a new unique prefix value when no suitable existing
       
   839                 namespace prefix is available to serialize a <var>node</var>'s namespaceURI (or the namespaceURI
       
   840                 of one of <var>node</var>'s attributes). <span class="note">See the
       
   841                 <a title="concept-generate-prefix" class="internalDFN" href="#dfn-concept-generate-prefix">generate a prefix</a> algorithm.</span>
       
   842             <li>Return the result of running the <a title="concept-xml-serialization-algorithm" class="internalDFN" href="#dfn-concept-xml-serialization-algorithm">XML serialization
       
   843                 algorithm</a> on <var>node</var> passing the <a title="concept-context-namespace" class="internalDFN" href="#dfn-concept-context-namespace">context
       
   844                 namespace</a>, <a title="concept-namespace-prefix-map" class="internalDFN" href="#dfn-concept-namespace-prefix-map">namespace prefix map</a>,
       
   845                 <a title="concept-generated-prefix" class="internalDFN" href="#dfn-concept-generated-prefix">generated namespace prefix index</a> reference, and the
       
   846                 flag <var>require well-formed</var>. If an <dfn title="concept-algorithm-exception" id="dfn-concept-algorithm-exception">exception</dfn>
       
   847                 occurs during the execution of the algorithm, then catch that exception and throw a
       
   848                 <code><a title="domexception" class="externalDFN" href="http://www.w3.org/TR/dom/#domexception">DOMException</a></code> with
       
   849                 name "<code><a title="invalidstateerror" class="externalDFN" href="http://www.w3.org/TR/dom/#invalidstateerror">InvalidStateError</a></code>".
       
   850         </li></ol>
       
   851 
       
   852         <p>An <a title="concept-serialize-xml" class="internalDFN" href="#dfn-concept-serialize-xml">XML serialization</a> differs from an
       
   853             <a title="concept-serialize-html" class="internalDFN" href="#dfn-concept-serialize-html">HTML serialization</a> in the following ways:
       
   854         <ul>
       
   855             <li><a title="element" class="externalDFN" href="http://www.w3.org/TR/dom/#element">Elements</a> and
       
   856                 <a title="concept-attribute" class="externalDFN" href="http://www.w3.org/TR/dom/#concept-attribute">attributes</a>
       
   857                 will always be serialized such that their namespaceURI is preserved. In some cases
       
   858                 this means that an existing prefix, prefix declaration attribute or default namespace
       
   859                 declaration attribute might be dropped, substituted or changed.
       
   860                 An <a title="concept-serialize-html" class="internalDFN" href="#dfn-concept-serialize-html">HTML serialization</a> does not attempt to
       
   861                 preserve the namespaceURI.
       
   862             <li><a title="element" class="externalDFN" href="http://www.w3.org/TR/dom/#element">Elements</a> not in the
       
   863                 <a title="html-ns" class="internalDFN" href="#dfn-html-ns">HTML namespace</a> containing no <a title="concept-tree-child" class="externalDFN" href="http://www.w3.org/TR/dom/#concept-tree-child">children</a>, are serialized using
       
   864                 the self-closing tag syntax (i.e., according to the <code>EmptyElemTag</code>
       
   865                 production of [<cite><a class="bibref" href="#bib-XML10">XML10</a></cite>]).
       
   866         </li></ul>
       
   867 
       
   868         <p>Otherwise, the algorithm for producing an <a title="concept-serialize-xml" class="internalDFN" href="#dfn-concept-serialize-xml">XML serialization</a>
       
   869             is designed to produce a serialization that is compatible with the
       
   870             <a title="html-parser" class="externalDFN" href="http://www.w3.org/TR/html5/single-page.html#html-parser">HTML parser</a>. For example,
       
   871             elements in the <a title="html-ns" class="internalDFN" href="#dfn-html-ns">HTML namespace</a>closing tag syntax [<cite><a class="bibref" href="#bib-XML10">XML10</a></cite>].
       
   872 
       
   873         <div class="note"><div class="note-title" id="h_note_3" role="heading" aria-level="3"><span>Note</span></div><p>Per [<cite><a class="bibref" href="#bib-DOM4">DOM4</a></cite>], <code><a title="interface-attr" class="externalDFN" href="http://www.w3.org/TR/dom/#interface-attr">Attr</a></code>
       
   874             objects do not inherit from <code><a title="node" class="externalDFN" href="http://www.w3.org/TR/dom/#node">Node</a></code>, and thus cannot
       
   875             be serialized by the <a title="concept-xml-serialization-algorithm" class="internalDFN" href="#dfn-concept-xml-serialization-algorithm">XML serialization algorithm</a>.
       
   876             An attempt to serialize an <code><a title="interface-attr" class="externalDFN" href="http://www.w3.org/TR/dom/#interface-attr">Attr</a></code>
       
   877             object will result in a <code>TypeError</code> exception [<cite><a class="bibref" href="#bib-WEBIDL">WEBIDL</a></cite>].
       
   878 
       
   879         </p></div><p>To run the <dfn title="concept-xml-serialization-algorithm" id="dfn-concept-xml-serialization-algorithm">XML serialization algorithm</dfn> on
       
   880             a <var>node</var> given a <a title="concept-context-namespace" class="internalDFN" href="#dfn-concept-context-namespace">context namespace</a>
       
   881             <var>namespace</var>, a <a title="concept-namespace-prefix-map" class="internalDFN" href="#dfn-concept-namespace-prefix-map">namespace prefix map</a>
       
   882             <var>prefix map</var>, a <a title="concept-generated-prefix" class="internalDFN" href="#dfn-concept-generated-prefix">generated namespace prefix index</a>
       
   883             <var>prefix index</var>, and a flag <var>require well-formed</var>, the user agent must run the
       
   884             appropriate steps, depending on <var>node</var>'s interface:</p>
       
   885 
       
   886         <dl class="switch">
       
   887             <dt><code><a title="interface-element" class="externalDFN" href="http://www.w3.org/TR/dom/#interface-element">Element</a></code>
       
   888             <dd>
       
   889                 <p>Run the following algorithm:
       
   890                 <ol>
       
   891                     <!-- "namespace" was passed via the caller, it's the default namespace scope -->
       
   892                     <!-- "prefix map" was passed via the caller, it's the namespace->prefix map -->
       
   893                     <!-- "prefix index" was passed via the caller, it's a number for generating prefixes if necessary -->
       
   894                     <!-- "require well-formed" was passed via the caller, it's a flag (true/false) for whether certain validation steps should be taken during serialization. -->
       
   895                     <li>If the <a title="concept-well-formed" class="internalDFN" href="#dfn-concept-well-formed">require well-formed</a> flag is set (its value is
       
   896                         <code>true</code>), and this <var>node</var>'s
       
   897                         <code><a title="dom-element-localname" class="externalDFN" href="http://www.w3.org/TR/dom/#dom-element-localname">localName</a></code>
       
   898                         attribute contains the character "<code>:</code>" (U+003A COLON) or does not match the
       
   899                         XML <code>Name</code> production [<cite><a class="bibref" href="#bib-XML10">XML10</a></cite>], then <a title="concept-algorithm-exception" class="internalDFN" href="#dfn-concept-algorithm-exception">throw an
       
   900                         exception</a>; the serialization of this <var>node</var> would not be a well-formed element.
       
   901                     <li>Let <var>markup</var> be the string "<code>&lt;</code>" (U+003C LESS-THAN SIGN).
       
   902                     <li>Let <var>qualified name</var> be an empty string.
       
   903                     <li>Let a <var>skip end tag</var> flag have the value <code>false</code>.
       
   904                     <li>Let an <var>ignore namespace definition attribute</var> flag have the value <code>false</code>.
       
   905                     <li>Let <var>map</var> be a copy of the <var>prefix map</var>.
       
   906                     <li>Let <var>element prefixes list</var> be an empty list. <span class="note">This list is
       
   907                         local to each element. Its purpose is to ensure that there are no conflicting prefixes
       
   908                         should a new namespace prefix attribute need to be generated.</span>
       
   909                     <li>Let <var>duplicate prefix definition</var> be <code>null</code>.
       
   910                     <li>Let <var>local default namespace</var> be the result of
       
   911                         <a title="concept-record-namespace-info" class="internalDFN" href="#dfn-concept-record-namespace-info">recording the namespace information</a> for
       
   912                         <var>node</var> given <var>map</var>, <var>element prefixes list</var>, and
       
   913                         <var>duplicate prefix definition</var>.
       
   914                     <div class="note"><div class="note-title" id="h_note_4" role="heading" aria-level="3"><span>Note</span></div><p>This above step will update the <var>map</var> with any found namespace prefix
       
   915                         definitions, add the found prefix definitions to the <var>element prefixes list</var>, optionally
       
   916                         set the <var>duplicate prefix definition</var> value, and return a local default namespace
       
   917                         value defined by a default namespace attribute if one exists. Otherwise it returns
       
   918                         <code>null</code>.</p></div>
       
   919                     <li>Let <var>inherited ns</var> be a copy of <var>namespace</var>.
       
   920                     <li>Let <var>ns</var> be the value of <var>node</var>'s
       
   921                         <code><a title="dom-element-namespaceuri" class="externalDFN" href="http://www.w3.org/TR/dom/#dom-element-namespaceuri">namespaceURI</a></code>
       
   922                         attribute.
       
   923                     <li>If <var>inherited ns</var> is equal to <var>ns</var>, then:
       
   924                     <ol>
       
   925                         <li>If <var>local default namespace</var> is not <code>null</code>, then set <var>ignore
       
   926                             namespace definition attribute</var> to <code>true</code>.
       
   927                         <li>If <var>ns</var> is the <a title="xml-ns" class="internalDFN" href="#dfn-xml-ns">XML namespace</a>, then let <var>qualified name</var>
       
   928                             be the concatenation of the string "<code>xml:</code>" and the value of <var>node</var>'s
       
   929                             <code><a title="dom-element-localname" class="externalDFN" href="http://www.w3.org/TR/dom/#dom-element-localname">localName</a></code>.
       
   930                         <li>Otherwise, let <var>qualified name</var> be the value of <var>node</var>'s
       
   931                             <code><a title="dom-element-localname" class="externalDFN" href="http://www.w3.org/TR/dom/#dom-element-localname">localName</a></code>.
       
   932                             <span class="note">The <var>node</var>'s prefix is always dropped.</span>
       
   933                         <li>Append the value of <var>qualified name</var> to <var>markup</var>.
       
   934                     </li></ol>
       
   935                     <li>Otherwise, <var>inherited ns</var> is not equal to <var>ns</var> (the <var>node</var>'s
       
   936                         own namespace is different from the context namespace of its parent). Run these sub-steps:
       
   937                     <!-- The serialization algorithm must differentiate this node's namespace from it's parent's default
       
   938                         namespace. There are two ways to do this: (1) [preferred due to assumed minimum length] use a
       
   939                         namespace prefix if one is available or (2) use a default namespace declaration. Both cases can
       
   940                         run into conflicts with existing attributes on the element and are handled accordingly. -->
       
   941                     <ol>
       
   942                         <li>Let <var>prefix</var> be the value of <var>node</var>'s
       
   943                             <code><a title="dom-element-prefix" class="externalDFN" href="http://www.w3.org/TR/dom/#dom-element-prefix">prefix</a></code>
       
   944                             attribute.
       
   945                         <li>Let <var>candidate prefix</var> be a value from <var>map</var> where there exists a key in
       
   946                             <var>map</var> that matches the value of <var>ns</var> or if there is no such key, then let
       
   947                             <var>candidate prefix</var> be <code>null</code>.
       
   948                         <!-- Found a suitable prefix to use, either locally, or inherited through a parent node that
       
   949                             matches the node's namespaceURI. This prefix will be used in serialization even if the node
       
   950                             doesn't have a real prefix. -->
       
   951                         <li>If <var>candidate prefix</var> is not <code>null</code> (a suitable namespace prefix is defined
       
   952                             which maps to <var>ns</var>), then:
       
   953                         <ol>
       
   954                             <li>Let <var>qualified name</var> be the concatenation of <var>candidate prefix</var>,
       
   955                                 "<code>:</code>" (U+003A COLON), and <var>node</var>'s <code>
       
   956                                 <a title="dom-element-localname" class="externalDFN" href="http://www.w3.org/TR/dom/#dom-element-localname">localName</a></code>.
       
   957                                 <span class="note">There exists on this <var>node</var> or the <var>node</var>'s ancestry a
       
   958                                 namespace prefix definition that defines the <var>node</var>'s namespace.</span>
       
   959                             <li>If <var>local default namespace</var> is not <code>null</code> (there exists a locally-defined
       
   960                                 default namespace declaration attribute), then let <var>inherited ns</var> get the value of
       
   961                                 <var>ns</var>.
       
   962                             <li>Append the value of <var>qualified name</var> to <var>markup</var>.
       
   963                         </li></ol>
       
   964                         <!-- Now there's no existing namespace->prefix mapping to override; try to use a prefix: -->
       
   965                         <li>Otherwise, if <var>prefix</var> is not <code>null</code> and <var>local default namespace</var> is
       
   966                             <code>null</code>, then:
       
   967                         <ol>
       
   968                             <li>If the <var>element prefixes list</var> contains the value of <var>prefix</var>, then
       
   969                                 let <var>prefix</var> be the result of
       
   970                                 <a title="concept-generate-prefix" class="internalDFN" href="#dfn-concept-generate-prefix">generating a prefix</a> providing as input the
       
   971                                 <a title="concept-namespace-prefix-map" class="internalDFN" href="#dfn-concept-namespace-prefix-map">namespace prefix map</a> <var>map</var>,
       
   972                                 <var>node</var>'s <var>ns</var> string, and the <var>prefix index</var> integer.
       
   973                             <li>Otherwise, append to <var>map</var> a new key <var>ns</var> whose key value is
       
   974                                 <var>prefix</var>.
       
   975                             <!-- Prefix is now either real or generated, and added to the map. -->
       
   976                             <li>Let <var>qualified name</var> be the concatenation
       
   977                             of <var>prefix</var>, "<code>:</code>" (U+003A COLON), and <var>node</var>'s
       
   978                             <code><a title="dom-element-localname" class="externalDFN" href="http://www.w3.org/TR/dom/#dom-element-localname">localName</a></code>.
       
   979                             <li>Append the value of <var>qualified name</var> to <var>markup</var>.
       
   980                             <li>Append the following to <var>markup</var>, in the order listed: <span class="note">The following
       
   981                                 serializes the new namespace/prefix association just added to the <var>map</var>.</span>
       
   982                             <ol>
       
   983                                 <li>"<code> </code>" (U+0020 SPACE);
       
   984                                 <li>The string "<code>xmlns:</code>";
       
   985                                 <li>The value of <var>prefix</var>;
       
   986                                 <li>"<code>="</code>" (U+003D EQUALS SIGN, U+0022 QUOTATION MARK);
       
   987                                 <li>The result of <a title="concept-serialize-attr-value" class="internalDFN" href="#dfn-concept-serialize-attr-value">serializing an attribute value</a>
       
   988                                     given <var>ns</var> and the <a title="concept-well-formed" class="internalDFN" href="#dfn-concept-well-formed">require well-formed</a> flag
       
   989                                     as input;
       
   990                                 <li>"<code>"</code>" (U+0022 QUOTATION MARK).
       
   991                             </li></ol>
       
   992                         </li></ol>
       
   993                         <!-- Giving up on the prefix route, try to use a default namespace instead (stomping on an existing
       
   994                              one if necessary) and dropping the node's prefix -->
       
   995                         <li>Otherwise, if <var>local default namespace</var> is <code>null</code>, or <var>local default
       
   996                             namespace</var> is not <code>null</code> and its value is not equal to <var>ns</var>, then:
       
   997                         <ol>
       
   998                             <li>Set the <var>ignore namespace definition attribute</var> flag to <code>true</code>.
       
   999                             <li>Let <var>qualified name</var> be the value of <var>node</var>'s <code><a title="dom-element-localname" class="externalDFN" href="http://www.w3.org/TR/dom/#dom-element-localname">localName</a></code>.
       
  1000                             <li>Let the value of <var>inherited ns</var> be <var>ns</var>. <span class="note">The new
       
  1001                                 default namespace will be used in the serialization to define this <var>node</var>'s
       
  1002                                 namespace and act as the context namespace for its <a title="concept-tree-child" class="externalDFN" href="http://www.w3.org/TR/dom/#concept-tree-child">children</a>.</span>
       
  1003                             <li>Append the value of <var>qualified name</var> to <var>markup</var>.
       
  1004                             <li>Append the following to <var>markup</var>, in the order listed: <span class="note">The following
       
  1005                                 serializes the new (or replacement) default namespace definition.</span>
       
  1006                             <ol>
       
  1007                                 <li>"<code> </code>" (U+0020 SPACE);
       
  1008                                 <li>The string "<code>xmlns</code>";
       
  1009                                 <li>"<code>="</code>" (U+003D EQUALS SIGN, U+0022 QUOTATION MARK);
       
  1010                                 <li>The result of <a title="concept-serialize-attr-value" class="internalDFN" href="#dfn-concept-serialize-attr-value">serializing an attribute value</a>
       
  1011                                     given <var>ns</var> and the <a title="concept-well-formed" class="internalDFN" href="#dfn-concept-well-formed">require well-formed</a> flag
       
  1012                                     as input;
       
  1013                                 <li>"<code>"</code>" (U+0022 QUOTATION MARK).
       
  1014                             </li></ol>
       
  1015                         </li></ol>
       
  1016                         <!-- Finally, regardless of prefix, the node has a local default namespace that matches 'ns'.
       
  1017                             So, we'll just use that and drop the prefix -->
       
  1018                         <li>Otherwise, the <var>node</var> has a <var>local default namespace</var> that matches
       
  1019                             <var>ns</var>. Let <var>qualified name</var> be the value of <var>node</var>'s
       
  1020                             <code><a title="dom-element-localname" class="externalDFN" href="http://www.w3.org/TR/dom/#dom-element-localname">localName</a></code>,
       
  1021                             let the value of <var>inherited ns</var> be <var>ns</var>, and append the value of
       
  1022                             <var>qualified name</var> to <var>markup</var>.
       
  1023                     </li></ol>
       
  1024                     <li>Append to <var>markup</var> the result of the
       
  1025                         <a title="concept-serialize-xml-attributes" class="internalDFN" href="#dfn-concept-serialize-xml-attributes">XML serialization of <var>node</var>'s
       
  1026                         attributes</a> given the
       
  1027                         <a title="concept-namespace-prefix-map" class="internalDFN" href="#dfn-concept-namespace-prefix-map">namespace prefix map</a> <var>map</var>,
       
  1028                         the <a title="concept-generated-prefix" class="internalDFN" href="#dfn-concept-generated-prefix">generated prefix index</a> <var>prefix index</var>, the
       
  1029                         flag <var>ignore namespace definition attribute</var> and the value of <var>duplicate
       
  1030                         prefix definition</var>.
       
  1031                     <li>If <var>ns</var> is the <a title="html-ns" class="internalDFN" href="#dfn-html-ns">HTML namespace</a>,
       
  1032                         and the <var>node</var>'s list of
       
  1033                         <a title="concept-tree-child" class="externalDFN" href="http://www.w3.org/TR/dom/#concept-tree-child">children</a>
       
  1034                         is empty, and the <var>node</var>'s
       
  1035                         <code><a title="dom-element-localname" class="externalDFN" href="http://www.w3.org/TR/dom/#dom-element-localname">localName</a></code>
       
  1036                         matches any one of the following
       
  1037                         <a title="void-elements" class="externalDFN" href="http://www.w3.org/TR/html5/single-page.html#void-elements">void elements</a>:
       
  1038                         "<code>area</code>",
       
  1039                         "<code>base</code>",
       
  1040                         "<code>basefont</code>",
       
  1041                         "<code>bgsound</code>",
       
  1042                         "<code>br</code>",
       
  1043                         "<code>col</code>",
       
  1044                         "<code>embed</code>",
       
  1045                         "<code>frame</code>",
       
  1046                         "<code>hr</code>",
       
  1047                         "<code>img</code>",
       
  1048                         "<code>input</code>",
       
  1049                         "<code>keygen</code>",
       
  1050                         "<code>link</code>",
       
  1051                         "<code>menuitem</code>",
       
  1052                         "<code>meta</code>",
       
  1053                         "<code>param</code>",
       
  1054                         "<code>source</code>",
       
  1055                         "<code>track</code>",
       
  1056                         "<code>wbr</code>";
       
  1057                         then append the following to <var>markup</var>, in the order listed:
       
  1058                         <ol>
       
  1059                             <li>"<code> </code>" (U+0020 SPACE);
       
  1060                             <li>"<code>/</code>" (U+002F SOLIDUS).
       
  1061                         </li></ol>
       
  1062                         and set the <var>skip end tag</var> flag to <code>true</code>.
       
  1063                     <li>If <var>ns</var> is not the <a title="html-ns" class="internalDFN" href="#dfn-html-ns">HTML namespace</a>,
       
  1064                         and the <var>node</var>'s list of
       
  1065                         <a title="concept-tree-child" class="externalDFN" href="http://www.w3.org/TR/dom/#concept-tree-child">children</a>
       
  1066                         is empty, then append "<code>/</code>" (U+002F SOLIDUS) to <var>markup</var>
       
  1067                         and set the <var>skip end tag</var> flag to <code>true</code>.
       
  1068                     <li>Append "<code>&gt;</code>" (U+003E GREATER-THAN SIGN) to <var>markup</var>.
       
  1069                     <li>If the value of <var>skip end tag</var> is <code>true</code>, then return
       
  1070                         the value of <var>markup</var> and skip the remaining steps. The
       
  1071                         <var>node</var> is a leaf-node.
       
  1072                     <li>If <var>ns</var> is the <a title="html-ns" class="internalDFN" href="#dfn-html-ns">HTML namespace</a>, and the <var>node</var>'s
       
  1073                         <code><a title="dom-element-localname" class="externalDFN" href="http://www.w3.org/TR/dom/#dom-element-localname">localName</a></code>
       
  1074                         matches the string "<code>template</code>", then this is a
       
  1075                         <code><a title="the-template-element" class="externalDFN" href="http://www.w3.org/TR/html5/single-page.html#the-template-element">template</a></code> element.
       
  1076                         Append to <var>markup</var> the result of running the
       
  1077                         <a title="concept-xml-serialization-algorithm" class="internalDFN" href="#dfn-concept-xml-serialization-algorithm">XML serialization algorithm</a> on the
       
  1078                         <a title="the-template-element" class="externalDFN" href="http://www.w3.org/TR/html5/single-page.html#the-template-element">template</a> element's
       
  1079                         <a title="template-contents" class="externalDFN" href="http://www.w3.org/TR/html5/single-page.html#template-contents">template contents</a>
       
  1080                         (a <code><a title="interface-documentfragment" class="externalDFN" href="http://www.w3.org/TR/dom/#interface-documentfragment">DocumentFragment</a></code>),
       
  1081                         providing the value of <var>inherited ns</var> for the
       
  1082                         <a title="concept-context-namespace" class="internalDFN" href="#dfn-concept-context-namespace">context namespace</a>,
       
  1083                         <var>map</var> for the <a title="concept-namespace-prefix-map" class="internalDFN" href="#dfn-concept-namespace-prefix-map">namespace prefix map</a>,
       
  1084                         <var>prefix index</var> for the
       
  1085                         <a title="concept-generated-prefix" class="internalDFN" href="#dfn-concept-generated-prefix">generated namespace prefix index</a>, and the value
       
  1086                         of the <var>require well-formed</var> flag. <span class="note">This allows
       
  1087                         <a title="template-contents" class="externalDFN" href="http://www.w3.org/TR/html5/single-page.html#template-contents">template content</a> to
       
  1088                         round-trip , given the rules for
       
  1089                         <a title="parsing-xhtml-documents" class="externalDFN" href="http://www.w3.org/TR/html5/single-page.html#parsing-xhtml-documents">parsing XHTML documents</a>
       
  1090                         [<cite><a class="bibref" href="#bib-HTML5">HTML5</a></cite>].</span>
       
  1091                     <li>Otherwise, append to <var>markup</var> the result of running the
       
  1092                         <a title="concept-xml-serialization-algorithm" class="internalDFN" href="#dfn-concept-xml-serialization-algorithm">XML serialization algorithm</a> on each
       
  1093                         of <var>node</var>'s
       
  1094                         <a title="concept-tree-child" class="externalDFN" href="http://www.w3.org/TR/dom/#concept-tree-child">children</a>,
       
  1095                         in <a title="concept-tree-order" class="externalDFN" href="http://www.w3.org/TR/dom/#concept-tree-order">tree order</a>,
       
  1096                         providing the value of <var>inherited ns</var> for the
       
  1097                         <a title="concept-context-namespace" class="internalDFN" href="#dfn-concept-context-namespace">context namespace</a>,
       
  1098                         <var>map</var> for the <a title="concept-namespace-prefix-map" class="internalDFN" href="#dfn-concept-namespace-prefix-map">namespace prefix map</a>,
       
  1099                         <var>prefix index</var> for the
       
  1100                         <a title="concept-generated-prefix" class="internalDFN" href="#dfn-concept-generated-prefix">generated namespace prefix index</a>, and the value
       
  1101                         of the <var>require well-formed</var> flag.
       
  1102                     <li>Append the following to <var>markup</var>, in the order listed:
       
  1103                         <ol>
       
  1104                             <li>"<code>&lt;/</code>" (U+003C LESS-THAN SIGN, U+002F SOLIDUS);
       
  1105                             <li>The value of <var>qualified name</var>;
       
  1106                             <li>"<code>&gt;</code>" (U+003E GREATER-THAN SIGN).
       
  1107                         </li></ol>
       
  1108                     <li>Return the value of <var>markup</var>.
       
  1109                 </li></ol>
       
  1110 
       
  1111             <dt><code><a title="interface-document" class="externalDFN" href="http://www.w3.org/TR/dom/#interface-document">Document</a></code>
       
  1112             <dd>
       
  1113                 <p>If the <a title="concept-well-formed" class="internalDFN" href="#dfn-concept-well-formed">require well-formed</a> flag is set (its value is
       
  1114                     <code>true</code>), and this <var>node</var> has no
       
  1115                     <code><a title="dom-document-documentelement" class="externalDFN" href="http://www.w3.org/TR/dom/#dom-document-documentelement">documentElement</a></code>
       
  1116                     (the <code><a title="dom-document-documentelement" class="externalDFN" href="http://www.w3.org/TR/dom/#dom-document-documentelement">documentElement</a></code>
       
  1117                     attribute's value is <code>null</code>), then <a title="concept-algorithm-exception" class="internalDFN" href="#dfn-concept-algorithm-exception">throw an
       
  1118                     exception</a>; the serialization of this <var>node</var> would not be a well-formed document.
       
  1119                 <p>Otherwise, run the following steps:
       
  1120                 <ol>
       
  1121                     <li>Let <var>serialized document</var> be an empty string.
       
  1122                     <li>Append to <var>serialized document</var> the string produced by running the steps to
       
  1123                         <a title="concept-serialize-doctype" class="internalDFN" href="#dfn-concept-serialize-doctype">produce a DocumentType serialization</a>
       
  1124                         of <var>node</var>'s
       
  1125                         <code><a title="dom-document-doctype" class="externalDFN" href="http://www.w3.org/TR/dom/#dom-document-doctype">doctype</a></code>
       
  1126                         attribute provided the <var>require well-formed</var> flag if <var>node</var>'s
       
  1127                         <code><a title="dom-document-doctype" class="externalDFN" href="http://www.w3.org/TR/dom/#dom-document-doctype">doctype</a></code>
       
  1128                         attribute is not <code>null</code>.
       
  1129                     <li>For each <a title="concept-tree-child" class="externalDFN" href="http://www.w3.org/TR/dom/#concept-tree-child">child</a>
       
  1130                         <var>child</var> of <var>node</var>, in
       
  1131                         <a title="concept-tree-order" class="externalDFN" href="http://www.w3.org/TR/dom/#concept-tree-order">tree order</a>, run the
       
  1132                         <a title="concept-xml-serialization-algorithm" class="internalDFN" href="#dfn-concept-xml-serialization-algorithm">XML serialization algorithm</a>
       
  1133                         on the <var>child</var> given a <a title="concept-context-namespace" class="internalDFN" href="#dfn-concept-context-namespace">context namespace</a>
       
  1134                         <var>namespace</var>, a <a title="concept-namespace-prefix-map" class="internalDFN" href="#dfn-concept-namespace-prefix-map">namespace prefix map</a>
       
  1135                         <var>prefix map</var>, a reference to a <a title="concept-generated-prefix" class="internalDFN" href="#dfn-concept-generated-prefix">generated
       
  1136                         namespace prefix index</a> <var>prefix index</var>, flag <var>require well-formed</var>, and
       
  1137                         append the result to <var>serialized document</var>.
       
  1138                     <li>Return the value of <var>serialized document</var>.
       
  1139                 </li></ol>
       
  1140 
       
  1141             <dt><code><a title="interface-comment" class="externalDFN" href="http://www.w3.org/TR/dom/#interface-comment">Comment</a></code>
       
  1142             <dd>
       
  1143                 <p>If the <a title="concept-well-formed" class="internalDFN" href="#dfn-concept-well-formed">require well-formed</a> flag is set (its value is
       
  1144                     <code>true</code>), and <var>node</var>'s
       
  1145                     <code><a title="dom-characterdata-data" class="externalDFN" href="http://www.w3.org/TR/dom/#dom-characterdata-data">data</a></code>
       
  1146                     contains characters that are not matched by the XML <code>Char</code> production [<cite><a class="bibref" href="#bib-XML10">XML10</a></cite>] or
       
  1147                     contains "<code>--</code>" (two adjacent U+002D HYPHEN-MINUS characters) or that ends with
       
  1148                     a "<code>-</code>" (U+002D HYPHEN-MINUS) character, then
       
  1149                     <a title="concept-algorithm-exception" class="internalDFN" href="#dfn-concept-algorithm-exception">throw an exception</a>; the serialization of this
       
  1150                     <var>node</var>'s
       
  1151                     <code><a title="dom-characterdata-data" class="externalDFN" href="http://www.w3.org/TR/dom/#dom-characterdata-data">data</a></code>
       
  1152                     would not be well-formed.
       
  1153                 <p>Return the concatenation of "<code>&lt;!--</code>", <var>node</var>'s
       
  1154                 <code><a title="dom-characterdata-data" class="externalDFN" href="http://www.w3.org/TR/dom/#dom-characterdata-data">data</a></code>, and
       
  1155                 "<code>--&gt;</code>".
       
  1156 
       
  1157             <!-- Removing CDATA Serialization steps as this interface type is removed from DOM4:
       
  1158             <dt><code><a title="cdata" data-spec="DOML2" class="externalDFN">CDATASection</a></code>
       
  1159             <dd><ol>
       
  1160                 <li>Let <var>markup</var> be the concatenation of "<code>&lt;![CDATA[</code>",
       
  1161                     <var>node</var>'s <code><a title="dom-characterdata-data" data-spec="DOM4"
       
  1162                     class="externalDFN">data</a></code>, and "<code>]]></code>".
       
  1163                 <li>Return the value of <var>markup</var>.
       
  1164               </ol>
       
  1165 
       
  1166               <p class=note>CDATASection objects may be created by the historical
       
  1167             <code>document.createCDATASection</code> API, or as a result of parsing an
       
  1168             <a title="xml-document" data-spec="DOM4" class="externalDFN">XML document</a>.
       
  1169             -->
       
  1170 
       
  1171             </p><dt><code><a title="interface-text" class="externalDFN" href="http://www.w3.org/TR/dom/#interface-text">Text</a></code>
       
  1172             <dd><ol>
       
  1173                 <li>If the <a title="concept-well-formed" class="internalDFN" href="#dfn-concept-well-formed">require well-formed</a> flag is set (its value is
       
  1174                     <code>true</code>), and <var>node</var>'s
       
  1175                     <code><a title="dom-characterdata-data" class="externalDFN" href="http://www.w3.org/TR/dom/#dom-characterdata-data">data</a></code>
       
  1176                     contains characters that are not matched by the XML <code>Char</code> production [<cite><a class="bibref" href="#bib-XML10">XML10</a></cite>],
       
  1177                     then <a title="concept-algorithm-exception" class="internalDFN" href="#dfn-concept-algorithm-exception">throw an exception</a>; the serialization of this
       
  1178                     <var>node</var>'s
       
  1179                     <code><a title="dom-characterdata-data" class="externalDFN" href="http://www.w3.org/TR/dom/#dom-characterdata-data">data</a></code>
       
  1180                     would not be well-formed.
       
  1181                 <li>Let <var>markup</var> be the value of <var>node</var>'s
       
  1182                 <code><a title="dom-characterdata-data" class="externalDFN" href="http://www.w3.org/TR/dom/#dom-characterdata-data">data</a></code>.
       
  1183 
       
  1184                 <li>Replace any occurrences of "<code>&amp;</code>" in <var>markup</var> by
       
  1185                 "<code>&amp;amp;</code>".
       
  1186 
       
  1187                 <li>Replace any occurrences of "<code>&lt;</code>" in <var>markup</var> by
       
  1188                 "<code>&amp;lt;</code>".
       
  1189 
       
  1190                 <li>Replace any occurrences of "<code>&gt;</code>" in <var>markup</var> by
       
  1191                 "<code>&amp;gt;</code>".
       
  1192 
       
  1193                 <li>Return the value of <var>markup</var>.
       
  1194               </li></ol>
       
  1195             <dt><code><a title="interface-documentfragment" class="externalDFN" href="http://www.w3.org/TR/dom/#interface-documentfragment">DocumentFragment</a></code>
       
  1196             <dd><ol>
       
  1197                 <li>Let <var>markup</var> the empty string.
       
  1198 
       
  1199                 <li>For each <a title="concept-tree-child" class="externalDFN" href="http://www.w3.org/TR/dom/#concept-tree-child">child</a>
       
  1200                     <var>child</var> of <var>node</var>, in
       
  1201                     <a title="concept-tree-order" class="externalDFN" href="http://www.w3.org/TR/dom/#concept-tree-order">tree order</a>,
       
  1202                     run the <a title="concept-xml-serialization-algorithm" class="internalDFN" href="#dfn-concept-xml-serialization-algorithm">XML serialization algorithm</a>
       
  1203                     on the <var>child</var> given
       
  1204                     a <a title="concept-context-namespace" class="internalDFN" href="#dfn-concept-context-namespace">context namespace</a> <var>namespace</var>, a
       
  1205                     <a title="concept-namespace-prefix-map" class="internalDFN" href="#dfn-concept-namespace-prefix-map">namespace prefix map</a> <var>prefix map</var>,
       
  1206                     a reference to a <a title="concept-generated-prefix" class="internalDFN" href="#dfn-concept-generated-prefix">generated namespace prefix index</a>
       
  1207                     <var>prefix index</var>, and flag <var>require well-formed</var>. Concatenate the result
       
  1208                     to <var>markup</var>.
       
  1209                 <li>Return the value of <var>markup</var>.
       
  1210               </li></ol>
       
  1211 
       
  1212             <dt><code><a title="interface-documenttype" class="externalDFN" href="http://www.w3.org/TR/dom/#interface-documenttype">DocumentType</a></code>
       
  1213             <dd>Run the steps to <a title="concept-serialize-doctype" class="internalDFN" href="#dfn-concept-serialize-doctype">produce a DocumentType
       
  1214                 serialization</a> of <var>node</var> given the <a title="concept-well-formed" class="internalDFN" href="#dfn-concept-well-formed">require well-formed</a>
       
  1215                 flag, and return the string this produced.
       
  1216 
       
  1217             <dt><code><a title="interface-processinginstruction" class="externalDFN" href="http://www.w3.org/TR/dom/#interface-processinginstruction">ProcessingInstruction</a></code>
       
  1218             <dd><ol>
       
  1219                 <li>If the <a title="concept-well-formed" class="internalDFN" href="#dfn-concept-well-formed">require well-formed</a> flag is set (its value is
       
  1220                     <code>true</code>), and <var>node</var>'s
       
  1221                     <code><a title="dom-processinginstruction-target" class="externalDFN" href="http://www.w3.org/TR/dom/#dom-processinginstruction-target">target</a></code>
       
  1222                     contains a "<code>:</code>" (U+003A COLON) character or is an
       
  1223                     <a title="ascii-case-insensitive" class="externalDFN" href="http://www.w3.org/TR/dom/#ascii-case-insensitive">ASCII case-insensitive</a>
       
  1224                     match for the string "<code>xml</code>", then <a title="concept-algorithm-exception" class="internalDFN" href="#dfn-concept-algorithm-exception">throw an
       
  1225                     exception</a>; the serialization of this <var>node</var>'s
       
  1226                     <code><a title="dom-processinginstruction-target" class="externalDFN" href="http://www.w3.org/TR/dom/#dom-processinginstruction-target">target</a></code>
       
  1227                     would not be well-formed.
       
  1228                 <li>If the <a title="concept-well-formed" class="internalDFN" href="#dfn-concept-well-formed">require well-formed</a> flag is set (its value is
       
  1229                     <code>true</code>), and <var>node</var>'s
       
  1230                     <code><a title="dom-characterdata-data" class="externalDFN" href="http://www.w3.org/TR/dom/#dom-characterdata-data">data</a></code>
       
  1231                     contains characters that are not matched by the XML <code>Char</code> production [<cite><a class="bibref" href="#bib-XML10">XML10</a></cite>] or
       
  1232                     contains the string "<code>?&gt;</code>" (U+003F QUESTION MARK, U+003E GREATER-THAN SIGN),
       
  1233                     then <a title="concept-algorithm-exception" class="internalDFN" href="#dfn-concept-algorithm-exception">throw an exception</a>; the serialization of this
       
  1234                     <var>node</var>'s
       
  1235                     <code><a title="dom-characterdata-data" class="externalDFN" href="http://www.w3.org/TR/dom/#dom-characterdata-data">data</a></code>
       
  1236                     would not be well-formed.
       
  1237                 <li>Let <var>markup</var> be the concatenation of the following, in the order listed:
       
  1238                 <ol>
       
  1239                     <li>"<code>&lt;?</code>" (U+003C LESS-THAN SIGN, U+003F QUESTION MARK);
       
  1240                     <li>The value of <var>node</var>'s <code><a title="dom-processinginstruction-target" class="externalDFN" href="http://www.w3.org/TR/dom/#dom-processinginstruction-target">target</a></code>;
       
  1241                     <li>"<code> </code>" (U+0020 SPACE);
       
  1242                     <li>The value of <var>node</var>'s <code><a title="dom-characterdata-data" class="externalDFN" href="http://www.w3.org/TR/dom/#dom-characterdata-data">data</a></code>;
       
  1243                     <li>"<code>?&gt;</code>" (U+003F QUESTION MARK, U+003E GREATER-THAN SIGN).
       
  1244                 </li></ol>
       
  1245                 <li>Return the value of <var>markup</var>.
       
  1246               </li></ol>
       
  1247 
       
  1248         </dd></dl>
       
  1249 
       
  1250         <p>To <dfn title="concept-serialize-doctype" id="dfn-concept-serialize-doctype">produce a DocumentType serialization</dfn> of a
       
  1251             <code><a title="node" class="externalDFN" href="http://www.w3.org/TR/dom/#node">Node</a></code> <var>node</var>, given a
       
  1252             <a title="concept-well-formed" class="internalDFN" href="#dfn-concept-well-formed">require well-formed</a> flag, the user agent must return
       
  1253             the result of the following algorithm:</p>
       
  1254 
       
  1255         <ol>
       
  1256             <li>If the <a title="concept-well-formed" class="internalDFN" href="#dfn-concept-well-formed">require well-formed</a> flag is <code>true</code>
       
  1257                 and the <var>node</var>'s
       
  1258                 <code><a title="dom-documenttype-publicid" class="externalDFN" href="http://www.w3.org/TR/dom/#dom-documenttype-publicid">publicId</a></code>
       
  1259                 attribute contains characters that are not matched by the XML <code>PubidChar</code> production
       
  1260                 [<cite><a class="bibref" href="#bib-XML10">XML10</a></cite>], then <a title="concept-algorithm-exception" class="internalDFN" href="#dfn-concept-algorithm-exception">throw an exception</a>; the serialization
       
  1261                 of this <var>node</var> would not be a well-formed document type declaration.
       
  1262             <li>If the <a title="concept-well-formed" class="internalDFN" href="#dfn-concept-well-formed">require well-formed</a> flag is <code>true</code>
       
  1263                 and the <var>node</var>'s
       
  1264                 <code><a title="dom-documenttype-systemid" class="externalDFN" href="http://www.w3.org/TR/dom/#dom-documenttype-systemid">systemId</a></code>
       
  1265                 attribute contains characters that are not matched by the XML <code>Char</code> production
       
  1266                 [<cite><a class="bibref" href="#bib-XML10">XML10</a></cite>] or that contains both a "<code>"</code>" (U+0022 QUOTATION MARK) and a "<code>'</code>"
       
  1267                 (U+0027 APOSTROPHE), then <a title="concept-algorithm-exception" class="internalDFN" href="#dfn-concept-algorithm-exception">throw an exception</a>; the
       
  1268                 serialization of this <var>node</var> would not be a well-formed document type declaration.
       
  1269             <li>Let <var>markup</var> be an empty string.
       
  1270             <li>Append the string "<code>&lt;!DOCTYPE</code>" to <var>markup</var>.
       
  1271             <li>Append "<code> </code>" (U+0020 SPACE) to <var>markup</var>.
       
  1272             <li>Append the value of the <var>node</var>'s
       
  1273                 <code><a title="dom-documenttype-name" class="externalDFN" href="http://www.w3.org/TR/dom/#dom-documenttype-name">name</a></code>
       
  1274                 attribute to <var>markup</var>. For a <var>node</var> belonging to an
       
  1275                 <a title="html-document" class="externalDFN" href="http://www.w3.org/TR/dom/#html-document">HTML document</a>,
       
  1276                 the value will be all lowercase.
       
  1277             <li>If the <var>node</var>'s
       
  1278                 <code><a title="dom-documenttype-publicid" class="externalDFN" href="http://www.w3.org/TR/dom/#dom-documenttype-publicid">publicId</a></code>
       
  1279                 is not the empty string then append the following, in the order listed, to <var>markup</var>:
       
  1280                 <ol>
       
  1281                     <li>"<code> </code>" (U+0020 SPACE);
       
  1282                     <li>The string "<code>PUBLIC</code>";
       
  1283                     <li>"<code> </code>" (U+0020 SPACE);
       
  1284                     <li>"<code>"</code>" (U+0022 QUOTATION MARK);
       
  1285                     <li>The value of the <var>node</var>'s
       
  1286                         <code><a title="dom-documenttype-publicid" class="externalDFN" href="http://www.w3.org/TR/dom/#dom-documenttype-publicid">publicId</a></code>
       
  1287                         attribute;
       
  1288                     <li>"<code>"</code>" (U+0022 QUOTATION MARK).
       
  1289                 </li></ol>
       
  1290             </li>
       
  1291             <li>If the <var>node</var>'s
       
  1292                 <code><a title="dom-documenttype-systemid" class="externalDFN" href="http://www.w3.org/TR/dom/#dom-documenttype-systemid">systemId</a></code>
       
  1293                 is not the empty string and the <var>node</var>'s
       
  1294                 <code><a title="dom-documenttype-publicid" class="externalDFN" href="http://www.w3.org/TR/dom/#dom-documenttype-publicid">publicId</a></code>
       
  1295                 is set to the empty string, then append the following, in the order listed, to <var>markup</var>:
       
  1296                 <ol>
       
  1297                     <li>"<code> </code>" (U+0020 SPACE);
       
  1298                     <li>The string "<code>SYSTEM</code>".
       
  1299                 </li></ol>
       
  1300             </li>
       
  1301             <li>If the <var>node</var>'s
       
  1302                 <code><a title="dom-documenttype-systemid" class="externalDFN" href="http://www.w3.org/TR/dom/#dom-documenttype-systemid">systemId</a></code>
       
  1303                 is not the empty string then append the following, in the order listed, to <var>markup</var>:
       
  1304                 <ol>
       
  1305                     <li>"<code> </code>" (U+0020 SPACE);
       
  1306                     <li>"<code>"</code>" (U+0022 QUOTATION MARK);
       
  1307                     <li>The value of the <var>node</var>'s
       
  1308                         <code><a title="dom-documenttype-systemid" class="externalDFN" href="http://www.w3.org/TR/dom/#dom-documenttype-systemid">systemId</a></code>
       
  1309                         attribute;
       
  1310                     <li>"<code>"</code>" (U+0022 QUOTATION MARK).
       
  1311                 </li></ol>
       
  1312             </li>
       
  1313             <!-- Removing internalSubset serialization steps as this property is not supported by DOM4. Also,
       
  1314                 optional requirements don't help improve interoperability:
       
  1315             <li>Optional: if the <var>node</var> has an (historical)
       
  1316                 <code><a title="ID-Core-DocType-internalSubset" data-spec="DOM3" class="externalDFN">internalSubset</a></code>
       
  1317                 and the
       
  1318                 <code><a title="ID-Core-DocType-internalSubset" data-spec="DOM3" class="externalDFN">internalSubset</a></code>
       
  1319                 attribute's value is a non-empty string, then append the following,
       
  1320                 in the order listed, to <var>markup</var>:
       
  1321                 <ol>
       
  1322                     <li>"<code> </code>" (U+0020 SPACE);
       
  1323                     <li>"<code>[</code>" (U+005B LEFT SQUARE BRACKET);
       
  1324                     <li>The value of the <var>node</var>'s
       
  1325                         <code><a title="ID-Core-DocType-internalSubset" data-spec="DOM3" class="externalDFN">internalSubset</a></code>
       
  1326                         attribute;
       
  1327                     <li>"<code>]</code>" (U+005D RIGHT SQUARE BRACKET);
       
  1328                 </ol>
       
  1329                 <p class=note>A <var>node</var> belonging to an
       
  1330                    <a title="html-document" data-spec="DOM4" class="externalDFN">HTML document</a>
       
  1331                    will never have an
       
  1332                    <code><a title="ID-Core-DocType-internalSubset" data-spec="DOM3" class="externalDFN">internalSubset</a></code>
       
  1333                    because any <code><a title="ID-Core-DocType-internalSubset" data-spec="DOM3" class="externalDFN">internalSubset</a></code>
       
  1334                    markup is ignored by the parser.</p>
       
  1335             </li>
       
  1336             -->
       
  1337             <li>Append "<code>&gt;</code>" (U+003E GREATER-THAN SIGN) to <var>markup</var>.
       
  1338             <li>Return the value of <var>markup</var>.
       
  1339         </li></ol>
       
  1340 
       
  1341         <p>To <dfn title="concept-record-namespace-info" id="dfn-concept-record-namespace-info">record the namespace information</dfn> for an
       
  1342             <code><a title="element" class="externalDFN" href="http://www.w3.org/TR/dom/#element">Element</a></code> <var>element</var>, given a
       
  1343             <a title="concept-namespace-prefix-map" class="internalDFN" href="#dfn-concept-namespace-prefix-map">namespace prefix map</a> <var>map</var>, an
       
  1344             <var>element prefixes list</var> (initially empty), and a <var>duplicate prefix
       
  1345             definition</var> reference, the user agent must run the following steps:
       
  1346         <ol>
       
  1347             <li>Let <var>default namespace attr value</var> be <code>null</code>.
       
  1348             <li><dfn title="record-namespace-loop" id="dfn-record-namespace-loop">Main</dfn>: For each <a title="concept-attribute" class="externalDFN" href="http://www.w3.org/TR/dom/#concept-attribute">attribute</a>
       
  1349                 <var>attr</var> in <var>element</var>'s
       
  1350                 <code><a title="dom-element-attributes" class="externalDFN" href="http://www.w3.org/TR/dom/#dom-element-attributes">attributes</a></code>,
       
  1351                 in the order they are specified in the <var>element</var>'s
       
  1352                 <a title="dom-element-attributes" class="externalDFN" href="http://www.w3.org/TR/dom/#dom-element-attributes">attribute list</a>:
       
  1353 
       
  1354                 <div class="note"><div class="note-title" id="h_note_5" role="heading" aria-level="3"><span>Note</span></div><p>The following conditional steps add namespace prefixes
       
  1355                     into the <var>element prefixes list</var> and add or replace them in the <var>map</var>.
       
  1356                     Only attributes in the <a title="xmlns-ns" class="internalDFN" href="#dfn-xmlns-ns">XMLNS namespace</a> are
       
  1357                     considered (e.g., attributes made to look like namespace declarations via
       
  1358                     <code><a title="dom-element-setattribute" class="externalDFN" href="http://www.w3.org/TR/dom/#dom-element-setattribute">setAttribute</a>(<em>"xmlns:pretend-prefix"</em>,
       
  1359                     <em>"pretend-namespace"</em>)</code> are not included).</p></div>
       
  1360             <ol>
       
  1361                 <li>Let <var>attribute namespace</var> be the value of <var>attr</var>'s
       
  1362                     <code><a title="dom-attr-namespaceuri" class="externalDFN" href="http://www.w3.org/TR/dom/#dom-attr-namespaceuri">namespaceURI</a></code>
       
  1363                     value.
       
  1364                 <li>Let <var>attribute prefix</var> be the value of <var>attr</var>'s
       
  1365                         <code><a title="dom-attr-prefix" class="externalDFN" href="http://www.w3.org/TR/dom/#dom-attr-prefix">prefix</a></code>.
       
  1366                 <li>If the <var>attribute namespace</var> is the <a title="xmlns-ns" class="internalDFN" href="#dfn-xmlns-ns">XMLNS namespace</a>, then:
       
  1367                 <ol>
       
  1368                     <li>If <var>attribute prefix</var> is <code>null</code>, then <var>attr</var> is a
       
  1369                         default namespace declaration. Set the <var>default namespace attr value</var> to
       
  1370                         <var>attr</var>'s <code><a title="dom-attr-value" class="externalDFN" href="http://www.w3.org/TR/dom/#dom-attr-value">value</a></code> and stop running these steps, returning to
       
  1371                         <a title="record-namespace-loop" class="internalDFN" href="#dfn-record-namespace-loop">Main</a> to visit the next attribute.
       
  1372                     <li>Otherwise, the <var>attribute prefix</var> is not <code>null</code> and <var>attr</var>
       
  1373                         is a namespace prefix definition. Run the following steps:
       
  1374                     <ol>
       
  1375                         <li>Let <var>prefix definition</var> be the value of <var>attr</var>'s
       
  1376                             <code><a title="dom-attr-localname" class="externalDFN" href="http://www.w3.org/TR/dom/#dom-attr-localname">localName</a></code>.
       
  1377                         <li>Let <var>namespace definition</var> be the value of <var>attr</var>'s
       
  1378                             <code><a title="dom-attr-value" class="externalDFN" href="http://www.w3.org/TR/dom/#dom-attr-value">value</a></code>.
       
  1379                         <li>If a key matching the value of <var>namespace definition</var> already exists in
       
  1380                             <var>map</var>, and the key's value matches <var>prefix definition</var>, then
       
  1381                             this is a duplicate namespace prefix definition. Set the value of <var>duplicate
       
  1382                             prefix definition</var> to <var>prefix definition</var>.
       
  1383                         <li>Otherwise, if the key matching the value of <var>namespace definition</var> already
       
  1384                             exists in <var>map</var>, but the key's value does not match <var>prefix definition</var>,
       
  1385                             then update the key's value to be <var>prefix definition</var>.
       
  1386                         <li>Otherwise, no key matching the value of <var>namespace definition</var> exists;
       
  1387                             append to <var>map</var> a new key <var>namespace definition</var>
       
  1388                             whose key value is the <var>prefix definition</var>.
       
  1389                         <li>Append the value of <var>prefix definition</var> to <var>element prefixes list</var>.
       
  1390                     </li></ol>
       
  1391                 </li></ol>
       
  1392             </li></ol>
       
  1393             <li>Return the value of <var>default namespace attr value</var>.
       
  1394         </li></ol>
       
  1395 
       
  1396         <p>To <dfn title="concept-generate-prefix" id="dfn-concept-generate-prefix">generate a prefix</dfn> given a
       
  1397             <a title="concept-namespace-prefix-map" class="internalDFN" href="#dfn-concept-namespace-prefix-map">namespace prefix map</a> <var>map</var>, a
       
  1398             string <var>new namespace</var>, and a reference to a
       
  1399             <a title="concept-generated-prefix" class="internalDFN" href="#dfn-concept-generated-prefix">generated namespace prefix index</a> <var>prefix
       
  1400             index</var>, the user agent must run the following steps:
       
  1401         <ol>
       
  1402             <li>Let <var>generated prefix</var> be the concatenation of the string "<code>ns</code>" and
       
  1403                 the current numerical value of <var>prefix index</var>.
       
  1404             <li>Let the value of <var>prefix index</var> be incremented by one.
       
  1405             <li>Append to <var>map</var> a new key <var>new namespace</var> whose key value is the
       
  1406                 <var>generated prefix</var>.
       
  1407             <li>Return the value of <var>generated prefix</var>.
       
  1408         </li></ol>
       
  1409 
       
  1410         <p>The <dfn title="concept-serialize-xml-attributes" id="dfn-concept-serialize-xml-attributes">XML serialization of the attributes</dfn>
       
  1411             of an <code><a title="concept-element" class="externalDFN" href="http://www.w3.org/TR/dom/#concept-element">Element</a></code>
       
  1412             <var>element</var> together with a <a title="concept-namespace-prefix-map" class="internalDFN" href="#dfn-concept-namespace-prefix-map">namespace prefix
       
  1413             map</a> <var>map</var>, a <a title="concept-generated-prefix" class="internalDFN" href="#dfn-concept-generated-prefix">generated prefix index</a>
       
  1414             <var>prefix index</var> reference, a flag <var>ignore namespace definition attribute</var>, a
       
  1415             <var>duplicate prefix definition</var> value, and a flag <var>require well-formed</var>,
       
  1416             is the result of the following algorithm:
       
  1417         <ol>
       
  1418             <li>Let <var>result</var> be the empty string.
       
  1419             <li>Let <var>localname set</var> be a new empty
       
  1420                 <dfn title="concept-namespace-localname-set" id="dfn-concept-namespace-localname-set">namespace localname set</dfn>. This <var>localname
       
  1421                 set</var> will contain tuples of unique attribute
       
  1422                 <code><a title="dom-attr-namespaceuri" class="externalDFN" href="http://www.w3.org/TR/dom/#dom-attr-namespaceuri">namespaceURI</a></code>
       
  1423                 and <code><a title="dom-element-localname" class="externalDFN" href="http://www.w3.org/TR/dom/#dom-element-localname">localName</a></code>
       
  1424                 pairs, and is populated as each <var>attr</var> is processed.
       
  1425                 <span class="note">This set is used to [optionally] enforce the well-formed constraint that an
       
  1426                 element cannot have two attributes with the same
       
  1427                 <code><a title="dom-attr-namespaceuri" class="externalDFN" href="http://www.w3.org/TR/dom/#dom-attr-namespaceuri">namespaceURI</a></code>
       
  1428                 and <code><a title="dom-element-localname" class="externalDFN" href="http://www.w3.org/TR/dom/#dom-element-localname">localName</a></code>.
       
  1429                 This can occur when two otherwise identical attributes on the same element differ only by their
       
  1430                 prefix values.</span>
       
  1431             <li><dfn title="serialize-attributes-loop" id="dfn-serialize-attributes-loop">Main</dfn>: For each <a title="concept-attribute" class="externalDFN" href="http://www.w3.org/TR/dom/#concept-attribute">attribute</a>
       
  1432                 <var>attr</var> in <var>element</var>'s
       
  1433                 <code><a title="dom-element-attributes" class="externalDFN" href="http://www.w3.org/TR/dom/#dom-element-attributes">attributes</a></code>,
       
  1434                 in the order they are specified in the <var>element</var>'s
       
  1435                 <a title="dom-element-attributes" class="externalDFN" href="http://www.w3.org/TR/dom/#dom-element-attributes">attribute list</a>:
       
  1436             <ol>
       
  1437                 <li>If the <a title="concept-well-formed" class="internalDFN" href="#dfn-concept-well-formed">require well-formed</a> flag is set (its value is
       
  1438                     <code>true</code>), and the <var>localname set</var> contains a tuple whose values match those
       
  1439                     of a new tuple consisting of <var>attr</var>'s
       
  1440                     <code><a title="dom-attr-namespaceuri" class="externalDFN" href="http://www.w3.org/TR/dom/#dom-attr-namespaceuri">namespaceURI</a></code>
       
  1441                     attribute and <code><a title="dom-element-localname" class="externalDFN" href="http://www.w3.org/TR/dom/#dom-element-localname">localName</a></code>
       
  1442                     attribute, then <a title="concept-algorithm-exception" class="internalDFN" href="#dfn-concept-algorithm-exception">throw an exception</a>; the serialization of this
       
  1443                     <var>attr</var> would fail to produce a well-formed element serialization.
       
  1444                 <li>Create a new tuple consisting of <var>attr</var>'s
       
  1445                     <code><a title="dom-attr-namespaceuri" class="externalDFN" href="http://www.w3.org/TR/dom/#dom-attr-namespaceuri">namespaceURI</a></code>
       
  1446                     attribute and <code><a title="dom-element-localname" class="externalDFN" href="http://www.w3.org/TR/dom/#dom-element-localname">localName</a></code>
       
  1447                     attribute, and add it to the <var>localname set</var>.
       
  1448                 <li>Let <var>attribute namespace</var> be the value of <var>attr</var>'s
       
  1449                     <code><a title="dom-attr-namespaceuri" class="externalDFN" href="http://www.w3.org/TR/dom/#dom-attr-namespaceuri">namespaceURI</a></code>
       
  1450                     value.
       
  1451                 <!-- Check for an unregistered attribute namespace, and if so, serialize a definition for it -->
       
  1452                 <li>Let <var>candidate prefix</var> be <code>null</code>.
       
  1453                 <li>If <var>attribute namespace</var> is not <code>null</code>, then run these sub-steps:
       
  1454                 <ol>
       
  1455                     <li>If the value of <var>attribute namespace</var> is the
       
  1456                         <a title="xmlns-ns" class="internalDFN" href="#dfn-xmlns-ns">XMLNS namespace</a> and either the <var>attr</var>'s
       
  1457                         <code><a title="dom-attr-prefix" class="externalDFN" href="http://www.w3.org/TR/dom/#dom-attr-prefix">prefix</a></code>
       
  1458                         is <code>null</code> and the <var>ignore namespace definition
       
  1459                         attribute</var> flag is <code>true</code> or the <var>attr</var>'s
       
  1460                         <code><a title="dom-attr-prefix" class="externalDFN" href="http://www.w3.org/TR/dom/#dom-attr-prefix">prefix</a></code>
       
  1461                         is not <code>null</code> and the <var>attr</var>'s
       
  1462                         <code><a title="dom-attr-localname" class="externalDFN" href="http://www.w3.org/TR/dom/#dom-attr-localname">localName</a></code>
       
  1463                         matches the value of <var>duplicate prefix definition</var>, then stop running
       
  1464                         these steps and goto <a title="serialize-attributes-loop" class="internalDFN" href="#dfn-serialize-attributes-loop">Main</a> to visit the next attribute.
       
  1465                     <li>Otherwise, if there exists a key in <var>map</var> that matches the value of <var>attribute
       
  1466                         namespace</var>, then let <var>candidate prefix</var> be that key's value from the
       
  1467                         <var>map</var>.
       
  1468                     <li>Otherwise, there is no key matching <var>attribute namespace</var> in <var>map</var> and
       
  1469                         the <var>attribute namespace</var> is not the <a title="xmlns-ns" class="internalDFN" href="#dfn-xmlns-ns">XMLNS namespace</a>.
       
  1470                         Run these steps:
       
  1471                     <ol>
       
  1472                         <li>Let <var>candidate prefix</var> be the result of
       
  1473                             <a title="concept-generate-prefix" class="internalDFN" href="#dfn-concept-generate-prefix">generating a prefix</a> providing <var>map</var>,
       
  1474                             <var>attribute namespace</var>, and <var>prefix index</var> as input.
       
  1475                         <li>Append the following to <var>result</var>, in the order listed:
       
  1476                         <ol>
       
  1477                             <li>"<code> </code>" (U+0020 SPACE);
       
  1478                             <li>The string "<code>xmlns:</code>";
       
  1479                             <li>The value of <var>candidate prefix</var>;
       
  1480                             <li>"<code>="</code>" (U+003D EQUALS SIGN, U+0022 QUOTATION MARK);
       
  1481                             <li>The result of <a title="concept-serialize-attr-value" class="internalDFN" href="#dfn-concept-serialize-attr-value">serializing an attribute value</a>
       
  1482                                 given <var>attribute namespace</var> and the
       
  1483                                 <a title="concept-well-formed" class="internalDFN" href="#dfn-concept-well-formed">require well-formed</a> flag as input;
       
  1484                             <li>"<code>"</code>" (U+0022 QUOTATION MARK).
       
  1485                         </li></ol>
       
  1486                     </li></ol>
       
  1487                 </li></ol>
       
  1488                 <!-- A namespace prefix has been set by this point if it needed to be set -->
       
  1489                 <li>Append a "<code> </code>" (U+0020 SPACE) to <var>result</var>.
       
  1490                 <li>If <var>candidate prefix</var> is not <code>null</code>, then append to <var>result</var>
       
  1491                     the concatenation of <var>candidate prefix</var> with "<code>:</code>" (U+003A COLON).
       
  1492                 <!-- Check for well-formed localName -->
       
  1493                 <li>If the <a title="concept-well-formed" class="internalDFN" href="#dfn-concept-well-formed">require well-formed</a> flag is set (its value is
       
  1494                     <code>true</code>), and this <var>attr</var>'s
       
  1495                     <code><a title="dom-element-localname" class="externalDFN" href="http://www.w3.org/TR/dom/#dom-element-localname">localName</a></code>
       
  1496                     attribute contains the character "<code>:</code>" (U+003A COLON) or does not match the XML
       
  1497                     <code>Name</code> production [<cite><a class="bibref" href="#bib-XML10">XML10</a></cite>] or equals "<code>xmlns</code>" and <var>attribute
       
  1498                     namespace</var> is <code>null</code>, then <a title="concept-algorithm-exception" class="internalDFN" href="#dfn-concept-algorithm-exception">throw an
       
  1499                     exception</a>; the serialization of this <var>attr</var> would not be a well-formed attribute.
       
  1500                 <!-- Write out the standard attribute -->
       
  1501                 <li>Append the following strings to <var>result</var>, in the order listed:
       
  1502                 <ol>
       
  1503                     <li>The value of <var>attr</var>'s
       
  1504                         <code><a title="dom-attr-localname" class="externalDFN" href="http://www.w3.org/TR/dom/#dom-attr-localname">localName</a></code>;
       
  1505                     <li>"<code>="</code>" (U+003D EQUALS SIGN, U+0022 QUOTATION MARK);
       
  1506                     <li>The result of <a title="concept-serialize-attr-value" class="internalDFN" href="#dfn-concept-serialize-attr-value">serializing an attribute value</a>
       
  1507                         given <var>attr</var>'s
       
  1508                         <code><a title="concept-attribute-value" class="externalDFN" href="http://www.w3.org/TR/dom/#concept-attribute-value">value</a></code>
       
  1509                         attribute and the <a title="concept-well-formed" class="internalDFN" href="#dfn-concept-well-formed">require well-formed</a> flag as input;
       
  1510                     <li>"<code>"</code>" (U+0022 QUOTATION MARK).
       
  1511                 </li></ol>
       
  1512             </li></ol>
       
  1513             <li>Return the value of <var>result</var>.
       
  1514         </li></ol>
       
  1515 
       
  1516         <p>To <dfn title="concept-serialize-attr-value" id="dfn-concept-serialize-attr-value">serialize an attribute value</dfn> given an
       
  1517             <var>attribute value</var> and <a title="concept-well-formed" class="internalDFN" href="#dfn-concept-well-formed">require well-formed</a> flag,
       
  1518             the user agent must run the following steps:
       
  1519         <ol>
       
  1520             <li>If the <a title="concept-well-formed" class="internalDFN" href="#dfn-concept-well-formed">require well-formed</a> flag is set (its value is
       
  1521                 <code>true</code>), and <var>attribute value</var> contains characters that are not matched
       
  1522                 by the XML <code>Char</code> production [<cite><a class="bibref" href="#bib-XML10">XML10</a></cite>], then
       
  1523                 <a title="concept-algorithm-exception" class="internalDFN" href="#dfn-concept-algorithm-exception">throw an exception</a>; the serialization of this
       
  1524                 <var>attribute value</var> would fail to produce a well-formed element serialization.
       
  1525             <li>If <var>attribute value</var> is <code>null</code>, then return the empty string.
       
  1526             <li>Otherwise, <var>attribute value</var> is a string. Return the value of
       
  1527                 <var>attribute value</var>, first replacing any occurrences of the following:
       
  1528             <ol>
       
  1529                 <li>"<code>"</code>" with "<code>&amp;quot;</code>"
       
  1530                 <li>"<code>&amp;</code>" with "<code>&amp;amp;</code>"
       
  1531                 <li>"<code>&lt;</code>" with "<code>&amp;lt;</code>"
       
  1532                 <li>"<code>&gt;</code>" with "<code>&amp;gt;</code>"
       
  1533             </li></ol>
       
  1534             <div class="note"><div class="note-title" id="h_note_6" role="heading" aria-level="3"><span>Note</span></div><p>This matches behavior present in browsers, and goes above
       
  1535                 and beyond the grammar requirement in the XML specification's AttValue
       
  1536                 production [<cite><a class="bibref" href="#bib-XML10">XML10</a></cite>] by also replacing "<code>&gt;</code>" characters.</p></div>
       
  1537         </li></ol>
       
  1538     </section>
       
  1539 </section>
       
  1540 
       
  1541 <section id="the-domparser-interface">
       
  1542     <!--OddPage--><h2 id="h2_the-domparser-interface" role="heading" aria-level="1"><span class="secno">5. </span>The <code>DOMParser</code> interface</h2>
       
  1543 
       
  1544 <pre class="extraidl">enum <span class="idlInterfaceID">SupportedType</span> {
       
  1545     "text/html",
       
  1546     "text/xml",
       
  1547     "application/xml",
       
  1548     "application/xhtml+xml",
       
  1549     "image/svg+xml"
       
  1550 };</pre>
       
  1551 
       
  1552     <p>The <dfn title="dom-domparser" id="dfn-dom-domparser"><code>DOMParser()</code></dfn> constructor
       
  1553     must return a new <code>DOMParser</code> object.
       
  1554 
       
  1555     <pre class="idl"><span class="idlInterface" id="idl-def-DOMParser">[<span class="extAttr">Constructor</span>]
       
  1556 interface <span class="idlInterfaceID">DOMParser</span> {
       
  1557 <span class="idlMethod">    [<span class="extAttr">NewObject</span>]
       
  1558     <span class="idlMethType">Document</span> <span class="idlMethName"><a href="#widl-DOMParser-parseFromString-Document-DOMString-str-SupportedType-type">parseFromString</a></span> (<span class="idlParam"><span class="idlParamType">DOMString</span> <span class="idlParamName">str</span></span>, <span class="idlParam"><span class="idlParamType">SupportedType</span> <span class="idlParamName">type</span></span>);</span>
       
  1559 };</span></pre><section id="methods"><h3 id="h3_methods" role="heading" aria-level="2"><span class="secno">5.1 </span>Methods</h3><dl class="methods"><dt id="widl-DOMParser-parseFromString-Document-DOMString-str-SupportedType-type"><code>parseFromString</code></dt><dd>
       
  1560             <p>The
       
  1561             <dfn title="dom-domparser-parsefromstring" id="dfn-dom-domparser-parsefromstring"><code>parseFromString(<var>str</var>, <var>type</var>)</code></dfn>
       
  1562             method must run these steps, depending on <var>type</var>:
       
  1563 
       
  1564             <dl class="switch">
       
  1565                 <dt>"<code>text/html</code>"
       
  1566                 <dd>
       
  1567                 <p>Parse <var>str</var> with an
       
  1568                 <code><a title="html-parser" class="externalDFN" href="http://www.w3.org/TR/html5/single-page.html#html-parser">HTML parser</a></code>, and return the newly
       
  1569                 created <a title="concept-document" class="externalDFN" href="http://www.w3.org/TR/dom/#concept-document">document</a>.
       
  1570 
       
  1571                 <p>The <a title="scripting-flag" class="externalDFN" href="http://www.w3.org/TR/html5/single-page.html#scripting-flag">scripting flag</a> must be set to
       
  1572                 "disabled".
       
  1573 
       
  1574                 <div class="note"><div class="note-title" id="h_note_7" role="heading" aria-level="3"><span>Note</span></div><p><code><a title="meta" class="externalDFN" href="http://www.w3.org/TR/html5/single-page.html#meta">meta</a></code> elements are not
       
  1575                 taken into account for the encoding used, as a Unicode stream is passed into
       
  1576                 the parser.
       
  1577 
       
  1578                 </p></div><div class="note"><div class="note-title" id="h_note_8" role="heading" aria-level="3"><span>Note</span></div><p><code><a title="script" class="externalDFN" href="http://www.w3.org/TR/html5/single-page.html#script">script</a></code> elements get marked
       
  1579                 unexecutable and the contents of <code><a title="the-noscript-element" class="externalDFN" href="http://www.w3.org/TR/html5/single-page.html#the-noscript-element">noscript</a></code>
       
  1580                 get parsed as markup.
       
  1581 
       
  1582                 </p></div><dt>"<code>text/xml</code>"
       
  1583                 <dt>"<code>application/xml</code>"
       
  1584                 <dt>"<code>application/xhtml+xml</code>"
       
  1585                 <dt>"<code>image/svg+xml</code>"
       
  1586                 <dd>
       
  1587                 <ol>
       
  1588                     <li>Parse <var>str</var> with a namespace-enabled
       
  1589                     <code><a title="xml-parser" class="externalDFN" href="http://www.w3.org/TR/html5/single-page.html#xml-parser">XML parser</a></code>.
       
  1590 
       
  1591                     <div class="note"><div class="note-title" id="h_note_9" role="heading" aria-level="3"><span>Note</span></div><p>For all XHTML <code><a title="script" class="externalDFN" href="http://www.w3.org/TR/html5/single-page.html#script">script</a></code>
       
  1592                         elements parsed using the <code><a title="xml-parser" class="externalDFN" href="http://www.w3.org/TR/html5/single-page.html#xml-parser">XML parser</a></code>,
       
  1593                         the equivalent of the <a title="scripting-flag" class="externalDFN" href="http://www.w3.org/TR/html5/single-page.html#scripting-flag">scripting flag</a> must
       
  1594                         be set to "disabled".</p></div>
       
  1595 
       
  1596                     <li>If the previous step didn't return an error, return the newly
       
  1597                     created <a title="concept-document" class="externalDFN" href="http://www.w3.org/TR/dom/#concept-document">document</a>.
       
  1598 
       
  1599                     <!-- This seemed like a good idea, but isn't web compatible, unfortunately.
       
  1600                     <li>Otherwise, throw a
       
  1601                     <code><a data-spec="DOM4" title="domexception" class="externalDFN">DOMException</a></code>
       
  1602                     with name <code>SyntaxError</code>. -->
       
  1603 
       
  1604                     <li>Let <var>document</var> be a newly-created
       
  1605                     <a title="xml-document" class="externalDFN" href="http://www.w3.org/TR/dom/#xml-document">XML Document</a>.
       
  1606                     <span class="note">The <var>document</var> will use the
       
  1607                     <code><a title="document" class="externalDFN" href="http://www.w3.org/TR/dom/#document">Document</a></code> interface
       
  1608                     rather than the <code><a title="xmldocument" class="externalDFN" href="http://www.w3.org/TR/dom/#xmldocument">XMLDocument</a></code>
       
  1609                     interface.</span>
       
  1610 
       
  1611                     <li>
       
  1612                     <p>Let <var>root</var> be a new
       
  1613                     <code><a title="element" class="externalDFN" href="http://www.w3.org/TR/dom/#element">Element</a></code>, with its
       
  1614                     <a title="concept-element-local-name" class="externalDFN" href="http://www.w3.org/TR/dom/#concept-element-local-name">local name</a>
       
  1615                     set to "<code>parsererror</code>" and its
       
  1616                     <a title="concept-element-namespace" class="externalDFN" href="http://www.w3.org/TR/dom/#concept-element-namespace">namespace</a>
       
  1617                     set to
       
  1618                     "<code>http://www.mozilla.org/newlayout/xml/parsererror.xml</code>".
       
  1619                     <!-- see https://bugzilla.mozilla.org/show_bug.cgi?id=45566 -->
       
  1620                     <p>At this point user agents may
       
  1621                     <a title="concept-node-append" class="externalDFN" href="http://www.w3.org/TR/dom/#concept-node-append">append</a> nodes
       
  1622                     to <var>root</var>, for example to describe the nature of the
       
  1623                     error.
       
  1624 
       
  1625                     </p><li><a title="concept-node-append" class="externalDFN" href="http://www.w3.org/TR/dom/#concept-node-append">Append</a>
       
  1626                     <var>root</var> to <var>document</var>.
       
  1627 
       
  1628                     <li>Return the value of <var>document</var>.
       
  1629                 </li></ol>
       
  1630             </dd></dl>
       
  1631 
       
  1632             <p>In any case, the returned
       
  1633             <a title="concept-document" class="externalDFN" href="http://www.w3.org/TR/dom/#concept-document">document</a>'s
       
  1634             <a title="concept-document-content-type" class="externalDFN" href="http://www.w3.org/TR/dom/#concept-document-content-type">content type</a>
       
  1635             must be the <var>type</var> argument. Additionally, the
       
  1636             <a title="concept-document" class="externalDFN" href="http://www.w3.org/TR/dom/#concept-document">document</a> must have a
       
  1637             <a title="concept-document-url" class="externalDFN" href="http://www.w3.org/TR/dom/#concept-document-url">URL</a> value equal to
       
  1638             the URL of the
       
  1639             <a title="active-document" class="externalDFN" href="http://www.w3.org/TR/html5/single-page.html#active-document">active document</a>, a
       
  1640             <a title="location" class="externalDFN" href="http://www.w3.org/TR/html5/single-page.html#location">location</a> value of <code>null</code>.
       
  1641 
       
  1642             <div class="note"><div class="note-title" id="h_note_10" role="heading" aria-level="3"><span>Note</span></div><p>The returned
       
  1643             <a title="concept-document" class="externalDFN" href="http://www.w3.org/TR/dom/#concept-document">document</a>'s
       
  1644             <a title="concept-document-encoding" class="externalDFN" href="http://www.w3.org/TR/dom/#concept-document-encoding">encoding</a> is
       
  1645             the default, UTF-8.
       
  1646         </p></div><table class="parameters"><tbody><tr><th>Parameter</th><th>Type</th><th>Nullable</th><th>Optional</th><th>Description</th></tr><tr><td class="prmName">str</td><td class="prmType"><code>DOMString</code></td><td class="prmNullFalse"><span role="img" aria-label="False">✘</span></td><td class="prmOptFalse"><span role="img" aria-label="False">✘</span></td><td class="prmDesc"></td></tr><tr><td class="prmName">type</td><td class="prmType"><code>SupportedType</code></td><td class="prmNullFalse"><span role="img" aria-label="False">✘</span></td><td class="prmOptFalse"><span role="img" aria-label="False">✘</span></td><td class="prmDesc"></td></tr></tbody></table><div><em>Return type: </em><code>Document</code></div></dd></dl></section>
       
  1647 </section>
       
  1648 
       
  1649 <section id="the-xmlserializer-interface">
       
  1650     <!--OddPage--><h2 id="h2_the-xmlserializer-interface" role="heading" aria-level="1"><span class="secno">6. </span>The <code>XMLSerializer</code> interface</h2>
       
  1651 
       
  1652     <p>The <dfn title="dom-xmlserializer" id="dfn-dom-xmlserializer"><code>XMLSerializer()</code></dfn>
       
  1653     constructor must return a new <code>XMLSerializer</code> object.
       
  1654 
       
  1655     <pre class="idl"><span class="idlInterface" id="idl-def-XMLSerializer">[<span class="extAttr">Constructor</span>]
       
  1656 interface <span class="idlInterfaceID">XMLSerializer</span> {
       
  1657 <span class="idlMethod">    <span class="idlMethType">DOMString</span> <span class="idlMethName"><a href="#widl-XMLSerializer-serializeToString-DOMString-Node-root">serializeToString</a></span> (<span class="idlParam"><span class="idlParamType">Node</span> <span class="idlParamName">root</span></span>);</span>
       
  1658 };</span></pre><section id="methods-1"><h3 id="h3_methods-1" role="heading" aria-level="2"><span class="secno">6.1 </span>Methods</h3><dl class="methods"><dt id="widl-XMLSerializer-serializeToString-DOMString-Node-root"><code>serializeToString</code></dt><dd>The <dfn title="dom-xmlserializer-serializetostring" id="dfn-dom-xmlserializer-serializetostring"><code>serializeToString(<var>root</var>)</code></dfn>
       
  1659         method must <a title="concept-serialize-xml" class="internalDFN" href="#dfn-concept-serialize-xml">produce an XML serialization</a> of <var>root</var> passing
       
  1660         a value of <code>false</code> for the <a title="concept-well-formed" class="internalDFN" href="#dfn-concept-well-formed">require well-formed</a> parameter, and return the result.<table class="parameters"><tbody><tr><th>Parameter</th><th>Type</th><th>Nullable</th><th>Optional</th><th>Description</th></tr><tr><td class="prmName">root</td><td class="prmType"><code>Node</code></td><td class="prmNullFalse"><span role="img" aria-label="False">✘</span></td><td class="prmOptFalse"><span role="img" aria-label="False">✘</span></td><td class="prmDesc"></td></tr></tbody></table><div><em>Return type: </em><code>DOMString</code></div></dd></dl></section>
       
  1661 </section>
       
  1662 
       
  1663 <section id="extensions-to-the-element-interface">
       
  1664     <!--OddPage--><h2 id="h2_extensions-to-the-element-interface" role="heading" aria-level="1"><span class="secno">7. </span>Extensions to the <code><a title="element" class="externalDFN" href="http://www.w3.org/TR/dom/#element">Element</a></code> interface</h2>
       
  1665 
       
  1666     <pre class="idl"><span class="idlInterface" id="idl-def-Element">partial interface <span class="idlInterfaceID">Element</span> {
       
  1667 <span class="idlAttribute">    [<span class="extAttr">TreatNullAs=EmptyString</span>]
       
  1668                 attribute <span class="idlAttrType">DOMString</span> <span class="idlAttrName"><a href="#widl-Element-innerHTML">innerHTML</a></span>;</span>
       
  1669 <span class="idlAttribute">    [<span class="extAttr">TreatNullAs=EmptyString</span>]
       
  1670                 attribute <span class="idlAttrType">DOMString</span> <span class="idlAttrName"><a href="#widl-Element-outerHTML">outerHTML</a></span>;</span>
       
  1671 <span class="idlMethod">    <span class="idlMethType">void</span> <span class="idlMethName"><a href="#widl-Element-insertAdjacentHTML-void-DOMString-position-DOMString-text">insertAdjacentHTML</a></span> (<span class="idlParam"><span class="idlParamType">DOMString</span> <span class="idlParamName">position</span></span>, <span class="idlParam"><span class="idlParamType">DOMString</span> <span class="idlParamName">text</span></span>);</span>
       
  1672 };</span></pre><section id="attributes"><h3 id="h3_attributes" role="heading" aria-level="2"><span class="secno">7.1 </span>Attributes</h3><dl class="attributes"><dt id="widl-Element-innerHTML"><code>innerHTML</code> of type <span class="idlAttrType">DOMString</span>,            </dt><dd>
       
  1673             <p>The <dfn title="dom-element-innerhtml" id="dfn-dom-element-innerhtml"><code>innerHTML</code></dfn> IDL
       
  1674             attribute represents the markup of the
       
  1675             <code><a title="element" class="externalDFN" href="http://www.w3.org/TR/dom/#element">Element</a></code>'s contents.
       
  1676 
       
  1677             <dl class="domintro">
       
  1678                 <!--doc.ih
       
  1679                 <dt><var>document</var> . <code title="dom-document-innerhtml">innerHTML</code> [ = <var>value</var> ]
       
  1680                 <dd>
       
  1681                 <p>Returns a fragment of HTML or XML that represents the
       
  1682                 <code><a title="document" data-spec="DOM4" class="externalDFN">Document</a></code>.
       
  1683 
       
  1684                 <p>Can be set, to replace the
       
  1685                 <code><a title="document" data-spec="DOM4" class="externalDFN">Document</a></code>'s contents with the result of
       
  1686                 parsing the given string.
       
  1687 
       
  1688                 <p>In the case of an <a title="xml-document" data-spec="DOM4" class="externalDFN">XML document</a>,
       
  1689                 will throw an
       
  1690                 <code><a data-spec="DOM4" title="domexception" class="externalDFN">DOMException</a></code> with name <code>InvalidStateError</code>
       
  1691                 if the <code><a title="document" data-spec="DOM4" class="externalDFN">Document</a></code> cannot be serialized
       
  1692                 to XML, and a
       
  1693                 <code><a data-spec="DOM4" title="domexception" class="externalDFN">DOMException</a></code> with name <code>SyntaxError</code>
       
  1694                 if the given string is not well-formed.
       
  1695                 -->
       
  1696 
       
  1697                 <dt><var>element</var> . <code title="dom-element-innerhtml">innerHTML</code> [ = <var>value</var> ]
       
  1698                 <dd>
       
  1699                 <p>Returns a fragment of HTML or XML that represents the element's
       
  1700                 contents.
       
  1701 
       
  1702                 <p>Can be set, to replace the contents of the element with nodes
       
  1703                 parsed from the given string.
       
  1704 
       
  1705                 <p>In the case of an <a title="xml-document" class="externalDFN" href="http://www.w3.org/TR/dom/#xml-document">XML document</a>,
       
  1706                 will throw a
       
  1707                 <code><a title="domexception" class="externalDFN" href="http://www.w3.org/TR/dom/#domexception">DOMException</a></code> with name
       
  1708                 "<code><a title="invalidstateerror" class="externalDFN" href="http://www.w3.org/TR/dom/#invalidstateerror">InvalidStateError</a></code>"
       
  1709                 if the <code><a title="element" class="externalDFN" href="http://www.w3.org/TR/dom/#element">Element</a></code> cannot be serialized
       
  1710                 to XML, and a
       
  1711                 <code><a title="domexception" class="externalDFN" href="http://www.w3.org/TR/dom/#domexception">DOMException</a></code> with name
       
  1712                 "<code><a title="syntaxerror" class="externalDFN" href="http://www.w3.org/TR/dom/#syntaxerror">SyntaxError</a></code>"
       
  1713                 if the given string is not well-formed.
       
  1714             </p></dd></dl>
       
  1715 
       
  1716             <p>On getting, return the result of invoking the
       
  1717                 <a title="concept-fragment-serializing-algorithm" class="internalDFN" href="#dfn-concept-fragment-serializing-algorithm">fragment serializing algorithm</a> on the
       
  1718                 <a title="context object" class="internalDFN" href="#dfn-context-object">context object</a> providing <code>true</code> for the
       
  1719                 <a title="concept-well-formed" class="internalDFN" href="#dfn-concept-well-formed">require well-formed</a> flag (this might throw an exception
       
  1720                 instead of returning a string).
       
  1721 
       
  1722             <p>On setting, these steps must be run:
       
  1723             <ol>
       
  1724                 <li>Let <var>fragment</var> be the result of invoking the
       
  1725                 <a title="concept-parse-fragment" class="internalDFN" href="#dfn-concept-parse-fragment">fragment parsing algorithm</a> with
       
  1726                 the new value as <var>markup</var>, and the
       
  1727                 <a title="context object" class="internalDFN" href="#dfn-context-object">context object</a> as the <var>context element</var>.
       
  1728 
       
  1729                 <li><a title="concept-node-replace-all" class="externalDFN" href="http://www.w3.org/TR/dom/#concept-node-replace-all">Replace all</a>
       
  1730                 with <var>fragment</var> within the <a title="context object" class="internalDFN" href="#dfn-context-object">context object</a>.
       
  1731             </li></ol>
       
  1732         </dd><dt id="widl-Element-outerHTML"><code>outerHTML</code> of type <span class="idlAttrType">DOMString</span>,            </dt><dd>
       
  1733             <p>The <dfn title="dom-element-outerhtml" id="dfn-dom-element-outerhtml"><code>outerHTML</code></dfn> IDL
       
  1734             attribute represents the markup of the
       
  1735             <code><a title="element" class="externalDFN" href="http://www.w3.org/TR/dom/#element">Element</a></code> and its contents.
       
  1736 
       
  1737             <dl class="domintro">
       
  1738               <dt><var>element</var> . <code title="dom-element-outerhtml">outerHTML</code> [ = <var>value</var> ]
       
  1739               <dd>
       
  1740                 <p>Returns a fragment of HTML or XML that represents the element and its
       
  1741                 contents.
       
  1742 
       
  1743                 <p>Can be set, to replace the element with nodes parsed from the given
       
  1744                 string.
       
  1745 
       
  1746                 <p>In the case of an <a title="xml-document" class="externalDFN" href="http://www.w3.org/TR/dom/#xml-document">XML document</a>,
       
  1747                 will throw a
       
  1748                 <code><a title="domexception" class="externalDFN" href="http://www.w3.org/TR/dom/#domexception">DOMException</a></code> with name
       
  1749                 "<code><a title="invalidstateerror" class="externalDFN" href="http://www.w3.org/TR/dom/#invalidstateerror">InvalidStateError</a></code>"
       
  1750                 if the element cannot be serialized to XML, and a
       
  1751                 <code><a title="domexception" class="externalDFN" href="http://www.w3.org/TR/dom/#domexception">DOMException</a></code> with name
       
  1752                 "<code><a title="syntaxerror" class="externalDFN" href="http://www.w3.org/TR/dom/#syntaxerror">SyntaxError</a></code>"
       
  1753                 if the given string is not well-formed.
       
  1754 
       
  1755                 <p>Throws a
       
  1756                 <code><a title="domexception" class="externalDFN" href="http://www.w3.org/TR/dom/#domexception">DOMException</a></code> with name
       
  1757                 "<code><a title="nomodificationallowederror" class="externalDFN" href="http://www.w3.org/TR/dom/#nomodificationallowederror">NoModificationAllowedError</a></code>"
       
  1758                 if the parent of the element is the
       
  1759                 <code><a title="document" class="externalDFN" href="http://www.w3.org/TR/dom/#document">Document</a></code> node.
       
  1760             </p></dd></dl>
       
  1761 
       
  1762             <p>On getting, return the result of invoking the
       
  1763                 <a title="concept-fragment-serializing-algorithm" class="internalDFN" href="#dfn-concept-fragment-serializing-algorithm">fragment serializing algorithm</a> on a
       
  1764                 fictional node whose only child is the <a title="context object" class="internalDFN" href="#dfn-context-object">context object</a>
       
  1765                 providing <code>true</code> for the <a title="concept-well-formed" class="internalDFN" href="#dfn-concept-well-formed">require well-formed</a>
       
  1766                 flag (this might throw an exception instead of returning a string).
       
  1767 
       
  1768             <p>On setting, the following steps must be run:
       
  1769 
       
  1770             <ol>
       
  1771                 <li>Let <var>parent</var> be the <a title="context object" class="internalDFN" href="#dfn-context-object">context object</a>'s
       
  1772                 <a title="concept-tree-parent" class="externalDFN" href="http://www.w3.org/TR/dom/#concept-tree-parent">parent</a>.
       
  1773 
       
  1774                 <li>If <var>parent</var> is null, terminate these steps. There would be no
       
  1775                 way to obtain a reference to the nodes created even if the remaining steps
       
  1776                 were run.
       
  1777 
       
  1778                 <li>If <var>parent</var> is a
       
  1779                 <code><a title="document" class="externalDFN" href="http://www.w3.org/TR/dom/#document">Document</a></code>, throw a
       
  1780                 <code><a title="domexception" class="externalDFN" href="http://www.w3.org/TR/dom/#domexception">DOMException</a></code> with name
       
  1781                 "<code><a title="nomodificationallowederror" class="externalDFN" href="http://www.w3.org/TR/dom/#nomodificationallowederror">NoModificationAllowedError</a></code>"
       
  1782                 exception.
       
  1783 
       
  1784                 <li>If <var>parent</var> is a
       
  1785                 <code><a title="documentfragment" class="externalDFN" href="http://www.w3.org/TR/dom/#documentfragment">DocumentFragment</a></code>, let
       
  1786                 <var>parent</var> be a new
       
  1787                 <code><a title="element" class="externalDFN" href="http://www.w3.org/TR/dom/#element">Element</a></code> with
       
  1788 
       
  1789                 <ul>
       
  1790                     <li><code>body</code> as its
       
  1791                     <a title="concept-element-local-name" class="externalDFN" href="http://www.w3.org/TR/dom/#concept-element-local-name">local name</a>,
       
  1792 
       
  1793                     <li>The <a title="html-ns" class="internalDFN" href="#dfn-html-ns">HTML namespace</a> as its
       
  1794                     <a title="concept-element-namespace" class="externalDFN" href="http://www.w3.org/TR/dom/#concept-element-namespace">namespace</a>, and
       
  1795                     <li>The <a title="context object" class="internalDFN" href="#dfn-context-object">context object</a>'s
       
  1796                     <a title="concept-node-document" class="externalDFN" href="http://www.w3.org/TR/dom/#concept-node-document">node document</a>
       
  1797                     as its
       
  1798                     <a title="concept-node-document" class="externalDFN" href="http://www.w3.org/TR/dom/#concept-node-document">node document</a>.
       
  1799                 </li></ul>
       
  1800 
       
  1801                 <li>Let <var>fragment</var> be the result of invoking the
       
  1802                 <a title="concept-parse-fragment" class="internalDFN" href="#dfn-concept-parse-fragment">fragment parsing algorithm</a> with
       
  1803                 the new value as <var>markup</var>, and <var>parent</var> as
       
  1804                 the <var>context element</var>.
       
  1805 
       
  1806                 <li><a title="concept-node-replace" class="externalDFN" href="http://www.w3.org/TR/dom/#concept-node-replace">Replace</a>
       
  1807                 the <a title="context object" class="internalDFN" href="#dfn-context-object">context object</a> with <var>fragment</var> within
       
  1808                 the <a title="context object" class="internalDFN" href="#dfn-context-object">context object</a>'s
       
  1809                 <a title="concept-tree-parent" class="externalDFN" href="http://www.w3.org/TR/dom/#concept-tree-parent">parent</a>.
       
  1810             </li></ol>
       
  1811         </dd></dl></section><section id="methods-2"><h3 id="h3_methods-2" role="heading" aria-level="2"><span class="secno">7.2 </span>Methods</h3><dl class="methods"><dt id="widl-Element-insertAdjacentHTML-void-DOMString-position-DOMString-text"><code>insertAdjacentHTML</code></dt><dd>
       
  1812              <dl class="domintro">
       
  1813                   <dt><var>element</var> . <code title="dom-element-insertadjacenthtml">insertAdjacentHTML</code>(<var>position</var>, <var>text</var>)
       
  1814 
       
  1815                   <dd>
       
  1816                     <p>Parses the given string <var>text</var> as HTML or XML and inserts
       
  1817                     the resulting nodes into the tree in the position given by the
       
  1818                     <var>position</var> argument, as follows:
       
  1819 
       
  1820                     <dl>
       
  1821                       <dt>"beforebegin"
       
  1822                       <dd>Before the element itself.
       
  1823 
       
  1824                       <dt>"afterbegin"
       
  1825                       <dd>Just inside the element, before its first child.
       
  1826 
       
  1827                       <dt>"beforeend"
       
  1828                       <dd>Just inside the element, after its last child.
       
  1829 
       
  1830                       <dt>"afterend"
       
  1831                       <dd>After the element itself.
       
  1832                     </dd></dl>
       
  1833 
       
  1834                     <p>Throws a <code><a title="domexception" class="externalDFN" href="http://www.w3.org/TR/dom/#domexception">DOMException</a></code> with name
       
  1835                     "<code><a title="syntaxerror" class="externalDFN" href="http://www.w3.org/TR/dom/#syntaxerror">SyntaxError</a></code>"
       
  1836                     if the arguments have invalid values (e.g., in the case of an
       
  1837                     <a title="xml-document" class="externalDFN" href="http://www.w3.org/TR/dom/#xml-document">XML document</a>, if the given string is
       
  1838                     not well-formed).
       
  1839 
       
  1840                     <p>Throws a
       
  1841                     <code><a title="domexception" class="externalDFN" href="http://www.w3.org/TR/dom/#domexception">DOMException</a></code> with name
       
  1842                     "<code><a title="nomodificationallowederror" class="externalDFN" href="http://www.w3.org/TR/dom/#nomodificationallowederror">NoModificationAllowedError</a></code>"
       
  1843                     if the given position isn't possible (e.g. inserting elements
       
  1844                     after the root element of a <code><a title="document" class="externalDFN" href="http://www.w3.org/TR/dom/#document">Document</a></code>).
       
  1845                 </p></dd></dl>
       
  1846 
       
  1847                 <p>The
       
  1848                 <dfn title="dom-element-insertadjacenthtml" id="dfn-dom-element-insertadjacenthtml"><code>insertAdjacentHTML(<var>position</var>, <var>text</var>)</code></dfn>
       
  1849                 method must run these steps:
       
  1850 
       
  1851                 <ol>
       
  1852                     <li>Use the first matching item from this list:
       
  1853 
       
  1854                     <dl class="switch">
       
  1855                         <dt>If <var>position</var> is an
       
  1856                         <a title="ascii-case-insensitive" class="externalDFN" href="http://www.w3.org/TR/dom/#ascii-case-insensitive">ASCII case-insensitive</a> match for
       
  1857                         the string "beforebegin"
       
  1858 
       
  1859                         <dt>If <var>position</var> is an
       
  1860                         <a title="ascii-case-insensitive" class="externalDFN" href="http://www.w3.org/TR/dom/#ascii-case-insensitive">ASCII case-insensitive</a> match for
       
  1861                         the string "afterend"
       
  1862 
       
  1863                         <dd>
       
  1864                             <p>Let <var>context</var> be the <a title="context object" class="internalDFN" href="#dfn-context-object">context object</a>'s
       
  1865                             <a title="concept-tree-parent" class="externalDFN" href="http://www.w3.org/TR/dom/#concept-tree-parent">parent</a>.
       
  1866 
       
  1867                             <p>If <var>context</var> is null or a
       
  1868                             <a title="concept-document" class="externalDFN" href="http://www.w3.org/TR/dom/#concept-document">document</a>, throw
       
  1869                             a
       
  1870                             <code><a title="domexception" class="externalDFN" href="http://www.w3.org/TR/dom/#domexception">DOMException</a></code> with name
       
  1871                             "<code><a title="nomodificationallowederror" class="externalDFN" href="http://www.w3.org/TR/dom/#nomodificationallowederror">NoModificationAllowedError</a></code>".
       
  1872 
       
  1873                         </p><dt>If <var>position</var> is an
       
  1874                         <a title="ascii-case-insensitive" class="externalDFN" href="http://www.w3.org/TR/dom/#ascii-case-insensitive">ASCII case-insensitive</a> match for
       
  1875                         the string "afterbegin"
       
  1876 
       
  1877                         <dt>If <var>position</var> is an
       
  1878                         <a title="ascii-case-insensitive" class="externalDFN" href="http://www.w3.org/TR/dom/#ascii-case-insensitive">ASCII case-insensitive</a> match for
       
  1879                         the string "beforeend"
       
  1880 
       
  1881                         <dd>Let <var>context</var> be the <a title="context object" class="internalDFN" href="#dfn-context-object">context object</a>.
       
  1882 
       
  1883                         <dt>Otherwise
       
  1884                         <dd>
       
  1885                             <p>Throw a <code><a title="domexception" class="externalDFN" href="http://www.w3.org/TR/dom/#domexception">DOMException</a></code>
       
  1886                             with name "<code><a title="syntaxerror" class="externalDFN" href="http://www.w3.org/TR/dom/#syntaxerror">SyntaxError</a></code>".
       
  1887                     </p></dd></dl>
       
  1888 
       
  1889                   <li>If <var>context</var> is not an
       
  1890                     <code><a title="element" class="externalDFN" href="http://www.w3.org/TR/dom/#element">Element</a></code> or the following are all true:
       
  1891 
       
  1892                     <ul>
       
  1893                       <li><var>context</var>'s
       
  1894                       <a title="concept-node-document" class="externalDFN" href="http://www.w3.org/TR/dom/#concept-node-document">node document</a>
       
  1895                       is an <a title="html-document" class="externalDFN" href="http://www.w3.org/TR/dom/#html-document">HTML document</a>,
       
  1896 
       
  1897                       <li><var>context</var>'s
       
  1898                       <a title="concept-element-local-name" class="externalDFN" href="http://www.w3.org/TR/dom/#concept-element-local-name">local name</a>
       
  1899                       is "<code>html</code>", and
       
  1900 
       
  1901                       <li><var>context</var>'s
       
  1902                       <a title="concept-element-namespace" class="externalDFN" href="http://www.w3.org/TR/dom/#concept-element-namespace">namespace</a>
       
  1903                       is the <a title="html-ns" class="internalDFN" href="#dfn-html-ns">HTML namespace</a>;
       
  1904                     </li></ul>
       
  1905 
       
  1906                     <p>let <var>context</var> be a new
       
  1907                     <code><a title="element" class="externalDFN" href="http://www.w3.org/TR/dom/#element">Element</a></code> with
       
  1908 
       
  1909                     <ul>
       
  1910                       <li><code>body</code> as its
       
  1911                       <a title="concept-element-local-name" class="externalDFN" href="http://www.w3.org/TR/dom/#concept-element-local-name">local name</a>,
       
  1912 
       
  1913                       <li>The <a title="html-ns" class="internalDFN" href="#dfn-html-ns">HTML namespace</a> as its
       
  1914                       <a title="concept-element-namespace" class="externalDFN" href="http://www.w3.org/TR/dom/#concept-element-namespace">namespace</a>, and
       
  1915 
       
  1916                       <li>The <a title="context object" class="internalDFN" href="#dfn-context-object">context object</a>'s
       
  1917                       <a title="concept-node-document" class="externalDFN" href="http://www.w3.org/TR/dom/#concept-node-document">node document</a>
       
  1918                       as its
       
  1919                       <a title="concept-node-document" class="externalDFN" href="http://www.w3.org/TR/dom/#concept-node-document">node document</a>.
       
  1920                     </li></ul>
       
  1921 
       
  1922                 <li>Let <var>fragment</var> be the result of invoking the
       
  1923                 <a title="concept-parse-fragment" class="internalDFN" href="#dfn-concept-parse-fragment">fragment parsing algorithm</a> with <var>text</var> as
       
  1924                 <var>markup</var>, and <var>context</var> as the <var>context element</var>.
       
  1925 
       
  1926                 <li>Use the first matching item from this list:
       
  1927 
       
  1928                 <dl class="switch">
       
  1929                     <dt>If <var>position</var> is an
       
  1930                     <a title="ascii-case-insensitive" class="externalDFN" href="http://www.w3.org/TR/dom/#ascii-case-insensitive">ASCII case-insensitive</a> match for
       
  1931                     the string "beforebegin"
       
  1932 
       
  1933                     <dd><a title="concept-node-insert" class="externalDFN" href="http://www.w3.org/TR/dom/#concept-node-insert">Insert</a>
       
  1934                     <var>fragment</var> into the <a title="context object" class="internalDFN" href="#dfn-context-object">context object</a>'s
       
  1935                     <a title="concept-tree-parent" class="externalDFN" href="http://www.w3.org/TR/dom/#concept-tree-parent">parent</a>
       
  1936                     before the <a title="context object" class="internalDFN" href="#dfn-context-object">context object</a>.
       
  1937 
       
  1938                     <dt>If <var>position</var> is an
       
  1939                     <a title="ascii-case-insensitive" class="externalDFN" href="http://www.w3.org/TR/dom/#ascii-case-insensitive">ASCII case-insensitive</a> match for
       
  1940                     the string "afterbegin"
       
  1941 
       
  1942                     <dd><a title="concept-node-insert" class="externalDFN" href="http://www.w3.org/TR/dom/#concept-node-insert">Insert</a>
       
  1943                     <var>fragment</var> into the <a title="context object" class="internalDFN" href="#dfn-context-object">context object</a>
       
  1944                     before its
       
  1945                     <a title="concept-tree-first-child" class="externalDFN" href="http://www.w3.org/TR/dom/#concept-tree-first-child">first child</a>.
       
  1946 
       
  1947                     <dt>If <var>position</var> is an
       
  1948                     <a title="ascii-case-insensitive" class="externalDFN" href="http://www.w3.org/TR/dom/#ascii-case-insensitive">ASCII case-insensitive</a> match for
       
  1949                     the string "beforeend"
       
  1950 
       
  1951                     <dd><a title="concept-node-append" class="externalDFN" href="http://www.w3.org/TR/dom/#concept-node-append">Append</a>
       
  1952                     <var>fragment</var> to the <a title="context object" class="internalDFN" href="#dfn-context-object">context object</a>.
       
  1953 
       
  1954                     <dt>If <var>position</var> is an
       
  1955                     <a title="ascii-case-insensitive" class="externalDFN" href="http://www.w3.org/TR/dom/#ascii-case-insensitive">ASCII case-insensitive</a> match for
       
  1956                     the string "afterend"
       
  1957 
       
  1958                     <dd><a title="concept-node-insert" class="externalDFN" href="http://www.w3.org/TR/dom/#concept-node-insert">Insert</a>
       
  1959                     <var>fragment</var> into the <a title="context object" class="internalDFN" href="#dfn-context-object">context object</a>'s
       
  1960                     <a title="concept-tree-parent" class="externalDFN" href="http://www.w3.org/TR/dom/#concept-tree-parent">parent</a>
       
  1961                     before the <a title="context object" class="internalDFN" href="#dfn-context-object">context object</a>'s
       
  1962                     <a title="concept-tree-next-sibling" class="externalDFN" href="http://www.w3.org/TR/dom/#concept-tree-next-sibling">next sibling</a>.
       
  1963                 </dd></dl>
       
  1964             </li></ol>
       
  1965         <table class="parameters"><tbody><tr><th>Parameter</th><th>Type</th><th>Nullable</th><th>Optional</th><th>Description</th></tr><tr><td class="prmName">position</td><td class="prmType"><code>DOMString</code></td><td class="prmNullFalse"><span role="img" aria-label="False">✘</span></td><td class="prmOptFalse"><span role="img" aria-label="False">✘</span></td><td class="prmDesc"></td></tr><tr><td class="prmName">text</td><td class="prmType"><code>DOMString</code></td><td class="prmNullFalse"><span role="img" aria-label="False">✘</span></td><td class="prmOptFalse"><span role="img" aria-label="False">✘</span></td><td class="prmDesc"></td></tr></tbody></table><div><em>Return type: </em><code>void</code></div></dd></dl></section>
       
  1966 </section>
       
  1967 
       
  1968 <!-- Dropping this extention as it is not implemented, nor does it appear that any browser
       
  1969      is currently interested in supporting it. Perhaps it can come back in a V2 of this spec
       
  1970      if browsers become interested.
       
  1971 <section>
       
  1972     <h1>Extensions to the <code><a title="text" data-spec="DOM4" class="externalDFN">Text</a></code> interface</h1>
       
  1973 
       
  1974     <dl class="idl" title="partial interface Text">
       
  1975         <dt>attribute boolean serializeAsCDATA</dt>
       
  1976         <dd>
       
  1977             <dl class=domintro>
       
  1978               <dt><var>text</var> .
       
  1979                   <code title="dom-text-serializeascdata">serializeAsCDATA</code> [ = <var>value</var> ]
       
  1980               <dd>Controls whether, in XML, this node is serialized as a CDATA section.
       
  1981             </dl>
       
  1982 
       
  1983             <p><code><a title="text" data-spec="DOM4" class="externalDFN">Text</a></code> nodes have an additional
       
  1984             associated flag, the <dfn>serialize as CDATA flag</dfn>.
       
  1985 
       
  1986             <p>The
       
  1987             <dfn title="dom-text-serializeascdata"><code>serializeAsCDATA</code></dfn>
       
  1988             attribute must return true if the <a title="context object">context object</a> has its
       
  1989             <a>serialize as CDATA flag</a> set, or false otherwise.
       
  1990 
       
  1991             <p>Setting the <code title="dom-text-serializeascdata">serializeAsCDATA</code>
       
  1992             attribute must, if the new value is true, set the
       
  1993             <a title="context object">context object</a>'s <a>serialize as CDATA flag</a>, or unset
       
  1994             it otherwise.
       
  1995         </dd>
       
  1996     </dl>
       
  1997 </section>
       
  1998 -->
       
  1999 
       
  2000 <section id="extensions-to-the-range-interface">
       
  2001     <!--OddPage--><h2 id="h2_extensions-to-the-range-interface" role="heading" aria-level="1"><span class="secno">8. </span>Extensions to the <code><a title="range" class="externalDFN" href="http://www.w3.org/TR/dom/#range">Range</a></code> interface</h2>
       
  2002 
       
  2003     <pre class="idl"><span class="idlInterface" id="idl-def-Range">partial interface <span class="idlInterfaceID">Range</span> {
       
  2004 <span class="idlMethod">    [<span class="extAttr">NewObject</span>]
       
  2005     <span class="idlMethType">DocumentFragment</span> <span class="idlMethName"><a href="#widl-Range-createContextualFragment-DocumentFragment-DOMString-fragment">createContextualFragment</a></span> (<span class="idlParam"><span class="idlParamType">DOMString</span> <span class="idlParamName">fragment</span></span>);</span>
       
  2006 };</span></pre><section id="methods-3"><h3 id="h3_methods-3" role="heading" aria-level="2"><span class="secno">8.1 </span>Methods</h3><dl class="methods"><dt id="widl-Range-createContextualFragment-DocumentFragment-DOMString-fragment"><code>createContextualFragment</code></dt><dd>
       
  2007             <dl class="domintro">
       
  2008               <dt><var>docFragment</var> = <var>range</var> . <code title="dom-range-createcontextualfragment">createContextualFragment</code>(<var>markupString</var>)
       
  2009               <dd>Returns a <code><a title="documentfragment" class="externalDFN" href="http://www.w3.org/TR/dom/#documentfragment">DocumentFragment</a></code>, created
       
  2010                 from the markup string given.
       
  2011             </dd></dl>
       
  2012 
       
  2013             <p>The
       
  2014             <dfn title="dom-range-createcontextualfragment" id="dfn-dom-range-createcontextualfragment"><code>createContextualFragment(<var>fragment</var>)</code></dfn>
       
  2015             method must run these steps:
       
  2016 
       
  2017             <ol>
       
  2018                 <li>Let <var>node</var> be the <a title="context object" class="internalDFN" href="#dfn-context-object">context object</a>'s
       
  2019                 <a title="concept-range-start-node" class="externalDFN" href="http://www.w3.org/TR/dom/#concept-range-start-node">start node</a>.
       
  2020 
       
  2021                 <p>Let <var>element</var> be as follows, depending on <var>node</var>'s interface:
       
  2022 
       
  2023                 <dl class="switch">
       
  2024                     <dt><code><a title="document" class="externalDFN" href="http://www.w3.org/TR/dom/#document">Document</a></code>
       
  2025                     <dt><code><a title="documentfragment" class="externalDFN" href="http://www.w3.org/TR/dom/#documentfragment">DocumentFragment</a></code>
       
  2026                     <dd>null
       
  2027 
       
  2028                     <dt><code><a title="element" class="externalDFN" href="http://www.w3.org/TR/dom/#element">Element</a></code>
       
  2029                     <dd><var>node</var>
       
  2030 
       
  2031                     <dt><code><a title="text" class="externalDFN" href="http://www.w3.org/TR/dom/#text">Text</a></code>
       
  2032                     <dt><code><a title="comment" class="externalDFN" href="http://www.w3.org/TR/dom/#comment">Comment</a></code>
       
  2033                     <dd><var>node</var>'s
       
  2034                     <a title="parent-element" class="externalDFN" href="http://www.w3.org/TR/dom/#parent-element">parent element</a>
       
  2035 
       
  2036                     <dt><code><a title="documenttype" class="externalDFN" href="http://www.w3.org/TR/dom/#documenttype">DocumentType</a></code>
       
  2037                     <dt><code><a title="processinginstruction" class="externalDFN" href="http://www.w3.org/TR/dom/#processinginstruction">ProcessingInstruction</a></code>
       
  2038                     <dd>[<cite><a class="bibref" href="#bib-DOM4">DOM4</a></cite>] prevents this case.
       
  2039                 </dd></dl>
       
  2040 
       
  2041                 <li>If either <var>element</var> is null or the following are all true:
       
  2042 
       
  2043                     <ul>
       
  2044                       <li><var>element</var>'s
       
  2045                       <a title="concept-node-document" class="externalDFN" href="http://www.w3.org/TR/dom/#concept-node-document">node document</a>
       
  2046                       is an <a title="html-document" class="externalDFN" href="http://www.w3.org/TR/dom/#html-document">HTML document</a>,
       
  2047 
       
  2048                       <li><var>element</var>'s
       
  2049                       <a title="concept-element-local-name" class="externalDFN" href="http://www.w3.org/TR/dom/#concept-element-local-name">local name</a>
       
  2050                       is "<code>html</code>", and
       
  2051 
       
  2052                       <li><var>element</var>'s
       
  2053                       <a title="concept-element-namespace" class="externalDFN" href="http://www.w3.org/TR/dom/#concept-element-namespace">namespace</a>
       
  2054                       is the <a title="html-ns" class="internalDFN" href="#dfn-html-ns">HTML namespace</a>;
       
  2055                     </li></ul>
       
  2056 
       
  2057                     <p>let <var>element</var> be a new
       
  2058                     <a title="concept-element" class="externalDFN" href="http://www.w3.org/TR/dom/#concept-element">element</a> with
       
  2059 
       
  2060                     <ul>
       
  2061                       <li>"<code>body</code>" as its
       
  2062                       <a title="concept-element-local-name" class="externalDFN" href="http://www.w3.org/TR/dom/#concept-element-local-name">local name</a>,
       
  2063 
       
  2064                       <li>The <a title="html-ns" class="internalDFN" href="#dfn-html-ns">HTML namespace</a> as its
       
  2065                       <a title="concept-element-namespace" class="externalDFN" href="http://www.w3.org/TR/dom/#concept-element-namespace">namespace</a>, and
       
  2066 
       
  2067                       <li>The <a title="context object" class="internalDFN" href="#dfn-context-object">context object</a>'s
       
  2068                       <a title="concept-node-document" class="externalDFN" href="http://www.w3.org/TR/dom/#concept-node-document">node document</a>
       
  2069                       as its
       
  2070                       <a title="concept-node-document" class="externalDFN" href="http://www.w3.org/TR/dom/#concept-node-document">node document</a>.
       
  2071                     </li></ul>
       
  2072 
       
  2073                 <li>Let <var>fragment node</var> be the result of invoking the
       
  2074                 <a title="concept-parse-fragment" class="internalDFN" href="#dfn-concept-parse-fragment">fragment parsing algorithm</a> with <var>fragment</var> as
       
  2075                 <var>markup</var>, and <var>element</var> as the <var>context element</var>.
       
  2076 
       
  2077                 <li>Unmark all scripts in <var>fragment node</var> as "already started".
       
  2078 
       
  2079                 <li>Return the value of <var>fragment node</var>.
       
  2080             </li></ol>
       
  2081         <table class="parameters"><tbody><tr><th>Parameter</th><th>Type</th><th>Nullable</th><th>Optional</th><th>Description</th></tr><tr><td class="prmName">fragment</td><td class="prmType"><code>DOMString</code></td><td class="prmNullFalse"><span role="img" aria-label="False">✘</span></td><td class="prmOptFalse"><span role="img" aria-label="False">✘</span></td><td class="prmDesc"></td></tr></tbody></table><div><em>Return type: </em><code>DocumentFragment</code></div></dd></dl></section>
       
  2082 </section>
       
  2083 
       
  2084 <section class="appendix" id="revision-history">
       
  2085     <!--OddPage--><h2 id="h2_revision-history" role="heading" aria-level="1"><span class="secno">A. </span>Revision History</h2>
       
  2086     <p>The following is an informative summary of the changes since the last publication of this 
       
  2087         specification. A complete revision history of the Editor's Drafts of this specification 
       
  2088         can be found <a href="https://dvcs.w3.org/hg/innerhtml/summary/">here</a>.</p>
       
  2089     
       
  2090     <ul>
       
  2091        <li><a href="https://dvcs.w3.org/hg/innerhtml/raw-file/tip/LC2_comments.html">Incorporated 
       
  2092         non-normative changes from previous Last Call document.</a>
       
  2093     </li></ul>
       
  2094 </section>
       
  2095 
       
  2096 <section class="appendix" id="acknowledgements">
       
  2097     <!--OddPage--><h2 id="h2_acknowledgements" role="heading" aria-level="1"><span class="secno">B. </span>Acknowledgements</h2>
       
  2098     <p>Thanks to Ms2ger [<a href="http://www.mozilla.org">Mozilla</a>] for maintaining the initial
       
  2099        drafts of this specification and for its continued improvement in the
       
  2100        <a href="http://domparsing.spec.whatwg.org/">Living Specification</a>.
       
  2101 
       
  2102     <p>Thanks to
       
  2103         Victor Costan,
       
  2104         Aryeh Gregor,
       
  2105         Anne van Kesteren,
       
  2106         Arkadiusz Michalski,
       
  2107         Simon Pieters,
       
  2108         Henri Sivonen,
       
  2109         Josh Soref
       
  2110         and Boris Zbarsky,
       
  2111         for their useful comments.
       
  2112 
       
  2113     <p>Special thanks to Ian Hickson for defining the
       
  2114     <code title="dom-element-innerhtml">innerHTML</code> and
       
  2115     <code title="dom-element-outerhtml">outerHTML</code> attributes, and the
       
  2116     <code title="dom-element-insertadjacenthtml">insertAdjacentHTML()</code> method in
       
  2117     [<cite><a class="bibref" href="#bib-HTML5">HTML5</a></cite>] and his useful comments.
       
  2118 </p></section>
       
  2119 
       
  2120 <section class="appendix" id="references" typeof="bibo:Chapter" rel="bibo:Chapter" resource="#references"><!--OddPage--><h2 id="h2_references" role="heading" aria-level="1"><span class="secno">C. </span>References</h2><section id="normative-references" typeof="bibo:Chapter" rel="bibo:Chapter" resource="#normative-references"><h3 id="h3_normative-references" role="heading" aria-level="2"><span class="secno">C.1 </span>Normative references</h3><dl class="bibliography" about=""><dt id="bib-HTML5">[HTML5]</dt><dd rel="dcterms:requires">Robin Berjon; Steve Faulkner; Travis Leithead; Erika Doyle Navara; Edward O'Connor; Silvia Pfeiffer. <a href="http://www.w3.org/TR/html5/"><cite>HTML5</cite></a>. 29 April 2014. W3C Candidate Recommendation. URL: <a href="http://www.w3.org/TR/html5/">http://www.w3.org/TR/html5/</a>
       
  2121 </dd><dt id="bib-RFC2119">[RFC2119]</dt><dd rel="dcterms:requires">S. Bradner. <a href="http://www.ietf.org/rfc/rfc2119.txt"><cite>Key words for use in RFCs to Indicate Requirement Levels.</cite></a> March 1997. Internet RFC 2119.  URL: <a href="http://www.ietf.org/rfc/rfc2119.txt">http://www.ietf.org/rfc/rfc2119.txt</a> 
       
  2122 </dd><dt id="bib-WEBIDL">[WEBIDL]</dt><dd rel="dcterms:requires">Cameron McCormack. <a href="http://www.w3.org/TR/WebIDL/"><cite>Web IDL</cite></a>. 19 April 2012. W3C Candidate Recommendation. URL: <a href="http://www.w3.org/TR/WebIDL/">http://www.w3.org/TR/WebIDL/</a>
       
  2123 </dd></dl></section><section id="informative-references" typeof="bibo:Chapter" rel="bibo:Chapter" resource="#informative-references"><h3 id="h3_informative-references" role="heading" aria-level="2"><span class="secno">C.2 </span>Informative references</h3><dl class="bibliography" about=""><dt id="bib-DOM4">[DOM4]</dt><dd rel="dcterms:references">Anne van Kesteren; Aryeh Gregor; Ms2ger; Alex Russell; Robin Berjon. <a href="http://www.w3.org/TR/dom/"><cite>W3C DOM4</cite></a>. 8 May 2014. W3C Candidate Recommendation. URL: <a href="http://www.w3.org/TR/dom/">http://www.w3.org/TR/dom/</a>
       
  2124 </dd><dt id="bib-XML10">[XML10]</dt><dd rel="dcterms:references">Tim Bray; Jean Paoli; Michael Sperberg-McQueen; Eve Maler; François Yergeau et al. <a href="http://www.w3.org/TR/xml"><cite>Extensible Markup Language (XML) 1.0 (Fifth Edition)</cite></a>. 26 November 2008. W3C Recommendation. URL: <a href="http://www.w3.org/TR/xml">http://www.w3.org/TR/xml</a>
       
  2125 </dd></dl></section></section></body></html>