diff --git a/index.html b/index.html index fdd3efa..ff2a9b4 100644 --- a/index.html +++ b/index.html @@ -59,7 +59,9 @@

Candidate Recommendation Exit Criteria

Report. -
+
+

This specification depends on the Infra Standard. [[!INFRA]] +

The IDL fragments in this specification must be interpreted as required for conforming IDL fragments, as described in the Web IDL specification. [[!WEBIDL]] @@ -80,14 +82,12 @@

Candidate Recommendation Exit Criteria

behavior by overriding attributes or methods with custom properties or functions in ECMAScript. [[ECMA-262]] -

Unless otherwise stated, string comparisons are done in a case-sensitive manner. -

If an algorithm calls into another algorithm, any exception that is thrown by the latter (unless it is explicitly caught), must cause the former to terminate, and the exception to be propagated up to its caller.

-
+

Extensibility

Vendor-specific proprietary extensions to this specification are strongly discouraged. Authors @@ -102,24 +102,24 @@

Extensibility

When vendor-neutral extensions to this specification are needed, either this specification can be updated accordingly, or an extension specification can be written that overrides the requirements in this specification. Such an extension specification becomes an - applicable specification for the purposes of conformance requirements in this + applicable specification for the purposes of conformance requirements in this specification.

Introduction

-

A document object model (DOM) is an in-memory representation of various types of Nodes - where each Node is connected in a tree. The [[HTML5]] and [[DOM4]] specifications describe - DOM and its Nodes is greater detail. +

A document object model (DOM) is an in-memory representation of various types of {{Node}}s + where each {{Node}} is connected in a tree. The [[HTML]] and [[DOM]] specifications describe + DOM and its {{Node}}s is greater detail.

Parsing is the term used for converting a string representation of a DOM into an actual DOM, and Serializing is the term used to transform a DOM back into a string. This specification concerns itself with defining various APIs for both parsing and serializing a DOM. -

For example: the innerHTML API is a common way to both - parse and serialize a DOM (it does both). If a particular Node, has the following in-memory +
For example: the {{Element.innerHTML}} API is a common way to both + parse and serialize a DOM (it does both). If a particular {{Node}} has the following in-memory DOM:
     HTMLDivElement (nodeName: "div")
@@ -134,7 +134,7 @@ 

Extensibility

And the HTMLDivElement node is stored in a variable myDiv, then to serialize myDiv's children simply get (read) the - Element's innerHTML property (this triggers the serialization): + {{Element.innerHTML}} property (this triggers the serialization):
     var serializedChildren = myDiv.innerHTML;
@@ -143,7 +143,7 @@ 

Extensibility

To parse new children for myDiv from a string (replacing its existing - children), simply set the innerHTML property (this triggers + children), simply set the {{Element.innerHTML}} property (this triggers parsing of the assigned string):

@@ -154,16 +154,16 @@ 

Extensibility

This specification describes two flavors of parsing and serializing: HTML and XML (with XHTML being a type of XML). Each follows the rules of its respective markup language. The above example shows HTML parsing and serialization. The specific algorithms for HTML parsing - and serializing are defined in the [[HTML5]] specification. This specification contains the + and serializing are defined in the [[HTML]] specification. This specification contains the algorithm for XML serializing. The grammar for XML parsing is described in the [[XML10]] specification.

Round-tripping a DOM means to serialize and then immediately parse the serialized string back into a DOM. Ideally, this process does not result in any data loss with respect to the - identity and attributes of the Node in the DOM. + identity and attributes of the {{Node}} in the DOM. Round-tripping is especially tricky for an XML serialization, which must be concerned with - preserving the Node's namespace identity in the serialization (wereas namespaces are + preserving the {{Node}}'s namespace identity in the serialization (wereas namespaces are ignored in HTML).

Consider the XML serialization of the following in-memory DOM: @@ -174,11 +174,10 @@

Extensibility

┃ ┗━ Text (data: "alert('hello world')")
- An XML serialization must include the HTMLScriptElement Node's - namespace in order to preserve the identity of the - script element, and to allow the serialized string to + An XML serialization must include the {{HTMLScriptElement}}'s [=Element/namespace=] in order to + preserve the identity of the [^script^] element, and to allow the serialized string to round-trip through an XML parser. Assuming that root - is in a variable named root: + is in a variable named root:
     var xmlSerialization = new XMLSerializer().serializeToString(root);
@@ -187,23 +186,11 @@ 

Extensibility

-

The term context object means the object on which the API being discussed was - called. - -

The following terms are understood to represent their respective namespaces in this - specification (and makes it easier to read): - -

    -
  • The HTML namespace is http://www.w3.org/1999/xhtml -
  • The XML namespace is http://www.w3.org/XML/1998/namespace -
  • The XMLNS namespace is http://www.w3.org/2000/xmlns/ -
-

APIs for parsing and serializing DOM

-

The DOMParser interface

+

The {{DOMParser}} interface

@@ -214,16 +201,16 @@

Extensibility

-

The definition of DOMParser has moved to the HTML Standard.

+

The definition of {{DOMParser}} has moved to the HTML Standard.

-

The XMLSerializer interface

+

The {{XMLSerializer}} interface

-

The definition of XMLSerializer has moved to the HTML Standard.

+

The definition of {{XMLSerializer}} has moved to the HTML Standard.

@@ -231,31 +218,31 @@

Extensibility

-

The definition of InnerHTML has moved to the HTML Standard.

+

The definition of {{Element.innerHTML}} has moved to the HTML Standard.

-

Extensions to the Element interface

+

Extensions to the {{Element}} interface

-

The definition of outerHTML has moved to the HTML Standard.

+

The definition of {{Element.outerHTML}} has moved to the HTML Standard.

-

The definition of insertAdjacentHTML has moved to the HTML Standard.

+

The definition of {{Element.insertAdjacentHTML}} has moved to the HTML Standard.

-

Extensions to the Range interface

+

Extensions to the {{Range}} interface

-

The definition of createContextualFragment has moved to the HTML Standard.

+

The definition of {{Range.createContextualFragment()}} has moved to the HTML Standard.

@@ -295,7 +282,7 @@

Extensibility

-

The definition of fragment parsing algorithm has moved to the HTML Standard.

+

The definition of fragment parsing algorithm has moved to the HTML Standard.

@@ -303,315 +290,341 @@

Extensibility

-

The definition of fragment serializing algorithm has moved to the HTML Standard.

+

The definition of fragment serializing algorithm has moved to the HTML Standard.

XML Serialization

An XML serialization differs from an HTML serialization in the following ways:

    -
  • Elements and attributes will always be serialized such - that their namespaceURI is preserved. In some cases this means that an existing - prefix, prefix declaration attribute or default namespace declaration attribute +
  • {{Element}}s and attributes will always be serialized such + that their namespace is preserved. In some cases this means that an existing + prefix, prefix declaration attribute or default namespace declaration attribute might be dropped, substituted or changed. An HTML serialization does not attempt to - preserve the namespaceURI. + preserve the namespace. -
  • Elements not in the HTML namespace containing no children, are +
  • {{Element}}s not in the HTML namespace containing no [=tree/children=], are serialized using the empty-element tag syntax (i.e., according to the XML EmptyElemTag production).

Otherwise, the algorithm for producing an XML serialization is designed to produce a serialization that is compatible with the HTML parser. For example, elements in the - HTML namespace that contain no child nodes are serialized with an explicit begin and end - tag rather than using the empty-element tag syntax. + HTML namespace that contain no [=tree/children=] are serialized with an explicit begin and + end tag rather than using the empty-element tag syntax. -

Per [[DOM4]], Attr objects do not inherit from Node, and - thus cannot be serialized by the XML serialization algorithm. An attempt to serialize an - Attr object will result in an empty string. - -

To produce an XML serialization of a Node node given - a flag require well-formed, run the following steps: +

+

To produce an XML serialization of a {{Node}} node given + a boolean require well-formed, run the following steps:

    -
  1. Let namespace be a context namespace with value null. - The context namespace tracks the XML serialization algorithm's current default - namespace. The context namespace is changed when either an Element Node has - a default namespace declaration, or the algorithm generates a default namespace declaration for - the Element Node to match its own namespace. The algorithm assumes no namespace - (null) to start. - -
  2. Let prefix map be a new namespace prefix map. - -
  3. Add the XML namespace with prefix value "xml" to - prefix map. - -
  4. Let prefix index be a generated namespace prefix index with value - 1. The generated namespace prefix index is used to generate a new unique - prefix value when no suitable existing namespace prefix is available to serialize a - node's namespaceURI (or the namespaceURI of one of - node's attributes). See the generate a prefix algorithm. - - -
  5. Return the result of running the XML serialization algorithm on node - passing the context namespace namespace, namespace prefix map - prefix map, generated namespace prefix index reference to - prefix index, and the flag require well-formed. If an - exception occurs during the execution of the algorithm, - then catch that exception and throw an "InvalidStateError" - DOMException. +
  6. +

    Let |namespace:namespace| be null. + +

    namespace tracks the XML serialization algorithm's current + default namespace. It is changed when either an {{Element}} has a default namespace + declaration, or the algorithm generates a default namespace declaration for the {{Element}} to + match its own namespace. + The algorithm assumes no namespace (null) to start. + +

  7. Let |prefix map:namespace prefix map| be «» (a namespace prefix map). + +
  8. Add "xml" to prefix map given the XML namespace. + +
  9. +

    Let |prefix index:integer| be 1. +

    prefix index is used to generate a new unique prefix when no + suitable existing namespace prefix is available to serialize a node's [=Element/namespace=] + (or the [=Attr/namespace=] of one of the attributes in + node's [=Element/attribute list=]). + See the generate a prefix algorithm. + +

  10. Return the result of running the XML serialization algorithm given node, + namespace, prefix map, a mutable reference to prefix index, and + require well-formed. + If an exception occurs during the execution of the + algorithm, then catch that exception and throw an {{"InvalidStateError"}} {{DOMException}}.
+
-

Each of the following algorithms for producing an XML serialization of a DOM node - take as input a node to serialize and the following arguments: -

+
+

The XML serialization algorithm, given + a {{Node}} |node:Node|, + a string |namespace:string|, + a [=namespace prefix map=] |prefix map:namespace prefix map|, + a mutable reference to an integer |prefix index:mutable reference to an integer|, + and + a boolean require well-formed, + must run the following steps: -

The XML serialization algorithm - produces an XML serialization of an arbitrary DOM node - node based on the node's interface type. Each referenced algorithm is - to be passed the arguments as they were recieved by the caller and return their result to the - caller. Re-throw any exceptions. If node's interface is:

+
    +
  1. If node's interface is:

    -
    -
    Element -
    Run the algorithm for XML serializing an Element node node. +
    +
    {{Element}} +
    Run the algorithm for XML serializing an Element node given |node|, |namespace|, + |namespace prefix map|, |prefix index| and require well-formed. -
    Document -
    Run the algorithm for XML serializing a Document node node. +
    {{Document}} +
    Run the algorithm for XML serializing a Document node given |node|, |namespace|, + |namespace prefix map|, |prefix index| and require well-formed. -
    Comment -
    Run the algorithm for XML serializing a Comment node node. +
    {{Comment}} +
    Run the algorithm for XML serializing a Comment node given |node| and + require well-formed. - +
    {{CDATASection}} +
    Run the algorithm for XML serializing a CDATASection node given |node| and + require well-formed. -
    Text -
    Run the algorithm for XML serializing a Text node node. +
    {{Text}} +
    Run the algorithm for XML serializing a Text node given |node| and + require well-formed. -
    DocumentFragment -
    Run the algorithm for XML serializing a DocumentFragment node node. +
    {{DocumentFragment}} +
    Run the algorithm for XML serializing a DocumentFragment node given |node|, + |namespace|, |namespace prefix map|, |prefix index| and require well-formed. -
    DocumentType -
    Run the algorithm for XML serializing a DocumentType node node. +
    {{DocumentType}} +
    Run the algorithm for XML serializing a DocumentType node given |node| and + require well-formed. -
    ProcessingInstruction -
    Run the algorithm for XML serializing a ProcessingInstruction node node. +
    {{ProcessingInstruction}} +
    Run the algorithm for XML serializing a ProcessingInstruction node given |node| and + require well-formed. -
    An Attr object -
    Return an empty string. +
    {{Attr}} +
    Return the empty string. -
    Anything else -
    Throw a TypeError. Only Nodes and Attr objects can be serialized by - this algorithm. -
    +
    Anything else +
    Throw a {{TypeError}}. Only {{Node}}s and {{Attr}}s can be serialized by this algorithm. +
    +
+
- Each of the above referenced algorithms are detailed in the sections that follow. +

Each of the above referenced algorithms are detailed in the sections that follow.

-

XML serializing an Element node

+

XML serializing an Element node

- The algorithm for producing an XML serialization of a DOM node of type Element is as - follows: +
+

The algorithm for XML serializing an Element node, given + an {{Element}} |node:Element|, + a string |namespace:string|, + a [=namespace prefix map=] |prefix map:namespace prefix map|, + a mutable reference to an integer |prefix index:mutable reference to an integer|, + and + a boolean require well-formed, + must run the following steps:

    -
  1. If the require well-formed flag is set (its value is true), - and this node's localName attribute contains the character +
  2. If require well-formed is true, + and node's [=Element/local name=] contains the character ":" (U+003A COLON) or does not match the XML Name production, then - throw an exception; the serialization of this node would not be a well-formed - element. + throw an exception. + (The serialization of node would not be well-formed.) -
  3. Let markup be the string "<" (U+003C LESS-THAN SIGN). +
  4. Let |markup:string| be "<" (U+003C LESS-THAN SIGN). -
  5. Let qualified name be an empty string. +
  6. Let |qualified name:string| be the empty string. -
  7. Let skip end tag be a boolean flag with value false. +
  8. Let |skip end tag:boolean| be false. -
  9. Let ignore namespace definition attribute be a boolean flag with value - false. +
  10. Let |ignore namespace definition attribute:boolean| be false. -
  11. Given prefix map, copy a namespace prefix map and let - map be the result. +
  12. Let |map:namespace prefix map| be the result of copy a namespace prefix map given + prefix map. -
  13. Let local prefixes map be an empty map. The map has unique Node - prefix strings as its keys, with corresponding namespaceURI - Node values as the map's key values (in this map, the null namespace is - represented by the empty string). +
  14. +

    Let |local prefixes map:map| be « » (an [=ordered map=] from strings to strings). + +

    Its keys will be prefixes, and its values will be namespaces. In this map, + the null namespace is represented by the empty string.

    This map is local to each element. It is used to ensure there are no conflicting - prefixes should a new namespace prefix attribute need to be - generated. It is also used to enable skipping of duplicate - prefix definitions when + prefixes if a new namespace prefix attribute needs to be + generated. + It is also used to enable skipping of duplicate prefix definitions when writing an element's attributes: the map - allows the algorithm to distinguish between a prefix in the - namespace prefix map that might be locally-defined (to the current Element) and - one that is not.

    + allows the algorithm to distinguish between a prefix in the namespace prefix map that + might be locally-defined (to the current {{Element}}) and one that is not.

    -
  15. Let local default namespace be the result of - recording the namespace information for node given map and - local prefixes map. +
  16. Let local default namespace be the result of + recording the namespace information for node's [=Element/attribute list=] + given map and local prefixes map.

    The above step will update map with any found namespace prefix - definitions, add the found prefix definitions to the local prefixes map and - return a local default namespace value defined by a default namespace attribute if one - exists. Otherwise it returns null.

    + definitions, add the found prefix definitions to local prefixes map and + return the value of a default namespace attribute (which can be empty) if one exists. + Otherwise it returns null.

    + +
  17. Let inherited ns be namespace. -
  18. Let inherited ns be a copy of namespace. +

    inherited ns will be passed down as the namespace argument + when serializing node's [=tree/children=]. -

  19. Let ns be the value of node's - namespaceURI attribute. +
  20. Let ns be node's [=Element/namespace=]. + +
  21. If inherited ns is ns, then: + +

    node is in the current default namespace. The steps below + serialize node without a prefix (even if it had one), and drop any default + namespace declaration. An exception is made if node is in the [=XML namespace=], + in which case the "`xml:`" prefix is used; this prefix does not need to be declared and no + effort is made to declare it. -

  22. If inherited ns is equal to ns, then:
      -
    1. If local default namespace is not null, then set - ignore namespace definition attribute to true. +
    2. If local default namespace is not null, then set + ignore namespace definition attribute to true. -
    3. If ns is the XML namespace, then append to - qualified name the concatenation of the string "xml:" and the - value of node's localName. +
    4. If ns is the XML namespace, then append the concatenation of + "xml:" and node's [=Element/local name=] to qualified name. -
    5. Otherwise, append to qualified name the value of node's - localName. The node's - prefix if it exists, is dropped. +
    6. Otherwise, append node's [=Element/local name=] to qualified name. -
    7. Append the value of qualified name to markup. +
    8. Append qualified name to markup.
    -
  23. Otherwise, inherited ns is not equal to ns (the node's - own namespace is different from the context namespace of its parent). Run these sub-steps: - +
  24. Otherwise: + +

    inherited ns is not equal to ns; node's + own [=Element/namespace=] is different from the context namespace. + To differentiate node's namespace from the context namespace, the steps below + will use a namespace prefix if one is available; if not, they will use or introduce a + default namespace declaration. +

      -
    1. Let prefix be the value of node's - prefix attribute. +
    2. Let prefix be node's [=Element/namespace prefix=].
    3. Let candidate prefix be the result of - retrieving a preferred prefix string prefix from map given - namespace ns. + retrieving a preferred prefix string prefix from map given + ns. -

      The above may return null if no namespace key ns exists - in map.

      +

      candidate prefix will be null if no prefix was found that maps + to ns (not even prefix). In that case, this algorithm will + generate a new `xmlns` attribute and add any new prefix to map below. -

    4. If the value of prefix matches "xmlns", then run the following - steps: +
    5. If prefix is "xmlns", then:
        -
      1. If the require well-formed flag is set, then throw an error. An - Element with prefix "xmlns" - will not legally round-trip in a conforming XML parser. +
      2. If require well-formed is true, then throw an exception. + An {{Element}} with [=Element/namespace prefix=] "xmlns" + will not legally round-trip in a conforming XML parser. -
      3. Let candidate prefix be the value of prefix. +
      4. Set candidate prefix to prefix.
    6. Found a suitable namespace prefix: if candidate prefix is not - null (a namespace prefix is defined which maps to ns), then: + null, then: -

      The following may serialize a different - prefix than the Element's existing - prefix if it already had one. However, the - retrieving a preferred prefix string algorithm already tried to match the existing - prefix if possible.

      +

      Either node or one of its ancestors defines that + candidate prefix maps to node's [=Element/namespace=]. + +

      The following could serialize a different prefix than node's + existing [=Element/namespace prefix=], if any. However, this only happens if this prefix + does not map to the correct namespace, as the retrieving a preferred prefix string + algorithm already tried to match the existing prefix.

      + +
        -
      1. Append to qualified name the concatenation of - candidate prefix, ":" (U+003A COLON), and node's - localName. There exists on this node or the - node's ancestry a namespace prefix definition that defines the node's - namespace. - -
      2. If the local default namespace is not null (there exists - a locally-defined default namespace declaration attribute) and its value is not the - XML namespace, then let inherited ns get the value of - local default namespace unless the - local default namespace is the empty string in which case let it get - null (the context namespace is changed to the declared default, rather - than this node's own namespace). +
      3. Append the concatenation of candidate prefix, ":" + (U+003A COLON), and node's [=Element/local name=] to qualified name. + +
      4. If local default namespace is not null (node has a default + namespace declaration attribute) and is not the + XML namespace, then: +
          +
        1. If local default namespace is the empty string, set + inherited ns to null. +
        2. Otherwise, set inherited ns to local default namespace. +
        + +

        It is possible that inherited ns differs from + node's [=Element/namespace=].

        Any default namespace definitions or namespace prefixes that define the - XML namespace are omitted when serializing this node's attributes.

        + XML namespace are omitted when serializing attributes in + node's [=Element/attribute list=].

        -
      5. Append the value of qualified name to markup. +
      6. Append qualified name to markup.
      -
    7. Otherwise, if prefix is not null, then: +
    8. Otherwise, if prefix is not null, then: -

      By this step, there is no namespace or prefix mapping declaration in this - node (or any parent node visited by this algorithm) that defines - prefix otherwise the step labelled Found a suitable namespace prefix would - have been followed. The sub-steps that follow will create a new namespace prefix declaration - for prefix and ensure that prefix does not conflict with an existing - namespace prefix declaration of the same localName in node's - attribute list.

      +

      By this step, there is no namespace or prefix mapping declaration in + node (or any parent {{Node}} visited by this algorithm) that defines + a prefix that maps to node's [=Element/namespace=]; otherwise the step labelled + Found a suitable namespace prefix would have been followed. Ideally we would use + node's [=Element/namespace prefix=]. However, it could be the case that + node already declares its own prefix as mapping to something else than its own + namespace. In that case we will [=generating a prefix|generate a new prefix=] as a last + resort. In either case, the sub-steps that follow will serialize a new namespace prefix + declaration for the prefix we end up using.

        -
      1. If the local prefixes map contains a key matching prefix, - then let prefix be the result of generating a prefix providing as input - map, ns, and prefix index. +
      2. If local prefixes map [=map/contains=] prefix, + then set prefix to the result of generating a prefix given + map, ns, and prefix index. -
      3. Add prefix to map given namespace ns. +
      4. Add prefix to map given ns. -
      5. Append to qualified name the concatenation of prefix, - ":" (U+003A COLON), and node's localName. +
      6. Append the concatenation of prefix, ":" (U+003A COLON), and + node's [=Element/local name=] to qualified name. -
      7. Append the value of qualified name to markup. +
      8. Append qualified name to markup.
      9. Append the following to markup, in the order listed:

        The following serializes a namespace prefix declaration for prefix - which was just added to the map.

        + which was just added to map.

        1. " " (U+0020 SPACE); -
        2. The string "xmlns:"; +
        3. "xmlns:"; -
        4. The value of prefix; +
        5. prefix;
        6. "="" (U+003D EQUALS SIGN, U+0022 QUOTATION MARK); -
        7. The result of serializing an attribute value given ns and the - require well-formed flag as input; +
        8. The result of serializing an attribute value given ns and + require well-formed;
        9. """ (U+0022 QUOTATION MARK). +
        + +
      10. If local default namespace is not null (node has a + default namespace declaration attribute), then: -
      11. If local default namespace is not null (there exists a - locally-defined default namespace declaration attribute), then let - inherited ns get the value of local default namespace - unless the local default namespace is the empty string in which case let - it get null. +
          +
        1. If local default namespace is the empty string, set + inherited ns to null. +
        2. Otherwise, set inherited ns to local default namespace.
      -
    9. Otherwise, if local default namespace is null, or - local default namespace is not null and its value is not equal +
    10. Otherwise, if local default namespace is null, or + local default namespace is not null and its value is not equal to ns, then:

      At this point, the namespace for this node still needs to be serialized, but - there's no prefix (or candidate prefix) availble; the following uses - the default namespace declaration to define the namespace--optionally replacing an existing - default declaration if present.

      + there's no [=Element/namespace prefix=] (or candidate prefix) available; the + following uses the default namespace declaration to define the namespace—optionally replacing + an existing default declaration if present.

        -
      1. Set the ignore namespace definition attribute flag to - true. +
      2. Set ignore namespace definition attribute to true. -
      3. Append to qualified name the value of node's - localName. +
      4. Append node's [=Element/local name=] to qualified name. -
      5. Let the value of inherited ns be ns. +
      6. Set inherited ns to ns. -

        The new default namespace will be used in the serialization to define this - node's namespace and act as the context namespace for its - children.

        +

        The new default namespace will be used in the serialization to define + node's [=Element/namespace=] and act as the context namespace for its + [=tree/children=].

        -
      7. Append the value of qualified name to markup. +
      8. Append qualified name to markup.
      9. Append the following to markup, in the order listed: @@ -621,37 +634,42 @@

        Extensibility

        1. " " (U+0020 SPACE); -
        2. The string "xmlns"; +
        3. "xmlns";
        4. "="" (U+003D EQUALS SIGN, U+0022 QUOTATION MARK); -
        5. The result of serializing an attribute value given ns and the - require well-formed flag as input; +
        6. The result of serializing an attribute value given ns and + require well-formed;
        7. """ (U+0022 QUOTATION MARK).
      + -
    11. Otherwise, the node has a local default namespace that matches - ns. Append to qualified name the value of node's - localName, let the value of inherited ns be ns, - and append the value of qualified name to markup. +
    12. Otherwise: + +

      local default namespace is ns. + +

        +
      1. Append node's [=Element/local name=] to qualified name. + +
      2. Set inherited ns to ns. + +
      3. Append qualified name to markup. +

      All of the combinations where ns is not equal to - inherited ns are handled above such that node will be serialized - preserving its original namespaceURI.

      + inherited ns are handled above such that node will be serialized + preserving its original [=Element/namespace=].

    -
  25. Append to markup the result of the - XML serialization of node's attributes - given map, prefix index, local prefixes map, - ignore namespace definition attribute flag, and - require well-formed flag. +
  26. Append to markup the result of the [=XML serialization of the attributes=] of + node given map, prefix index, local prefixes map, + ignore namespace definition attribute, and require well-formed. -
  27. If ns is the HTML namespace, and the node's list of - children is empty, and the node's localName matches any - one of the following void elements: +
  28. If ns is the HTML namespace, and node's [=tree/children=] + [=set/is empty=], and node's [=Element/local name=] is one of the following: "area", "base", "basefont", @@ -677,370 +695,402 @@

    Extensibility

  29. "/" (U+002F SOLIDUS).
- and set the skip end tag flag to true. + and set skip end tag to true. -
  • If ns is not the HTML namespace, and the node's list of - children is empty, then append "/" (U+002F SOLIDUS) to markup - and set the skip end tag flag to true. +
  • If ns is not the HTML namespace, and node's [=tree/children=] + [=set/is empty=], then append "/" (U+002F SOLIDUS) to markup + and set skip end tag to true.
  • Append ">" (U+003E GREATER-THAN SIGN) to markup. -
  • If the value of skip end tag is true, then return the value of - markup and skip the remaining steps. The node is a leaf-node. +
  • If skip end tag is true, then return markup. + node is a leaf node. -
  • If ns is the HTML namespace, and the node's - localName matches the string "template", then this is a - template element. Append to markup the result of - XML serializing a DocumentFragment node given the template element's - template contents (a DocumentFragment), providing - inherited ns, map, prefix index, and the - require well-formed flag. +
  • If ns is the HTML namespace, and node's + [=Element/local name=] is "template" (this is a [^template^] element), append to + markup the result of XML serializing a DocumentFragment node given + node's template contents (a {{DocumentFragment}}), + inherited ns, map, prefix index, and + require well-formed. -

    This allows template content to round-trip , given the rules for +

    This allows template content to round-trip, given the rules for parsing XHTML documents.

    -
  • Otherwise, append to markup the result of running the - XML serialization algorithm on each of node's children, in - tree order, providing inherited ns, map, - prefix index, and the require well-formed flag. +
  • +

    Otherwise, [=set/for each=] child of node's [=tree/children=]: +

      +
    1. Append to markup the result of running the XML serialization algorithm + given |child|, inherited ns, map, prefix index, and + require well-formed. +
  • Append the following to markup, in the order listed:
    1. "</" (U+003C LESS-THAN SIGN, U+002F SOLIDUS); -
    2. The value of qualified name; +
    3. qualified name;
    4. ">" (U+003E GREATER-THAN SIGN).
    -
  • Return the value of markup. +
  • Return markup. +
  • Recording the namespace

    -

    This following algorithm will update the namespace prefix map with any found namespace - prefix definitions, add the found prefix definitions to the local prefixes map, - and return a local default namespace value defined by a default namespace attribute if one - exists. Otherwise it returns null.

    +
    +

    This following algorithm will update the namespace prefix map with any + found namespace prefix definitions, add the found prefix definitions to + local prefixes map, and return a local default namespace value defined by a default + namespace attribute if one exists. Otherwise it returns null.

    -

    When recording the namespace information for an Element - element, given a namespace prefix map map and a - local prefixes map (initially empty), the user agent must run the following - steps: +

    When recording the namespace information for a [=list=] of + attributes |attributes|, given a namespace prefix map map + and an [=ordered map=] local prefixes map, run the following steps:

      -
    1. Let default namespace attr value be null. +
    2. Let default namespace attr value be null. -
    3. Main: For each attribute attr in element's - attributes, in the order they are specified in the element's - attribute list: +
    4. [=list/For each=] attr of attributes: -

      The following conditional steps find namespace prefixes. Only attributes - in the XMLNS namespace are considered (e.g., attributes made to look like namespace - declarations via setAttribute("xmlns:pretend-prefix", - "pretend-namespace") are not included).

      +

      The following conditional steps find namespace prefixes. Only + attributes in the XMLNS namespace are considered (e.g., + attributes made to look like namespace declarations via + {{Element/setAttribute(qualifiedName, value)|setAttribute("xmlns:pretend-prefix", + "pretend-namespace")}} are not included).

        -
      1. Let attribute namespace be the value of attr's - namespaceURI value. +
      2. Let attribute namespace be attr's [=Attr/namespace=]. -
      3. Let attribute prefix be the value of attr's - prefix. +
      4. Let attribute prefix be attr's [=Attr/namespace prefix=]. -
      5. If the attribute namespace is the XMLNS namespace, then: +
      6. If attribute namespace is the XMLNS namespace, then:
          -
        1. If attribute prefix is null, then attr is a default - namespace declaration. Set the default namespace attr value to attr's - value and stop running these steps, returning to Main to visit - the next attribute. +
        2. If attribute prefix is null (attr is a default namespace + declaration), set default namespace attr value to attr's + [=Attr/value=], and [=iteration/continue=]. -
        3. Otherwise, the attribute prefix is not null and attr - is a namespace prefix definition. Run the following steps: +
        4. Otherwise:
            -
          1. Let prefix definition be the value of attr's - localName. +
          2. attribute prefix is not null and attr is a namespace + prefix definition. -
          3. Let namespace definition be the value of attr's - value. +
          4. Let prefix definition be attr's [=Attr/local name=]. -
          5. If namespace definition is the XML namespace, then stop running - these steps, and return to Main to visit the next attribute. +
          6. Let namespace definition be attr's [=Attr/value=]. + +
          7. If namespace definition is the XML namespace, then + [=iteration/continue=].

            XML namespace definitions in prefixes are completely ignored (in order to avoid unnecessary work when there might be prefix conflicts). - XML namespaced elements are always handled uniformly by prefixing (and overriding - if necessary) the element's localname with the reserved "xml" prefix.

            + {{Element}}s in the XML namespace are always handled uniformly by prefixing (and + overriding if necessary) the element's [=Element/local name=] with the reserved + "xml" prefix.

          8. If namespace definition is the empty string (the declarative form of - having no namespace), then let namespace definition be null - instead. + having no namespace), then set namespace definition to null. -
          9. If prefix definition is found in map given the namespace - namespace definition, then stop running these steps, and return to Main - to visit the next attribute. +
          10. If prefix definition is found in map given + namespace definition, then [=iteration/continue=].

            This step avoids adding duplicate prefix definitions for the same namespace - in the map. This has the side-effect of avoiding later serialization of + in map. This has the side-effect of avoiding later serialization of duplicate namespace prefix declarations in any descendant nodes.

            -
          11. Add the prefix prefix definition to map given namespace +
          12. Add prefix definition to map given namespace definition. -
          13. Add the value of prefix definition as a new key to the - local prefixes map, with the namespace definition as the - key's value replacing the value of null with the empty string if applicable. +
          14. If namespace definition is null, then set namespace definition to + the empty string. + +
          15. Set local prefixes map[prefix definition] to + namespace definition.
      -
    5. Return the value of default namespace attr value. +
    6. Return default namespace attr value.

      The empty string is a legitimate return value and is not converted to - null.

      + null.

    +

    The Namespace Prefix Map

    -

    A namespace prefix map is a map that associates namespaceURI and - namespace prefix lists, where namespaceURI values are the - map's unique keys (which can include the null value representing no namespace), and - ordered lists of associated prefix values are the map's key values. The - namespace prefix map will be populated by previously seen namespaceURIs and all their - previously encountered prefix associations for a given node and its ancestors. - -

    Note: the last seen prefix for a given - namespaceURI is at the end of its respective list. The list is searched to - find potentially matching prefixes, and if no matches are found for the given - namespaceURI, then the last prefix in the list is used. See - copy a namespace prefix map and retrieve a preferred prefix string for additional - details.

    - -

    To copy a namespace prefix map map means to copy the map's - keys into a new empty namespace prefix map, and to copy each of the values in the - namespace prefix list associated with each keys' value into a new - list which should be associated with the respective key in the new map. +

    A namespace prefix map is an ordered map from strings or null + to lists of strings.

    + +
    +

    The keys are namespaces, with null representing no namespace; the values are + lists of prefixes that map to that namespace. + +

    An empty namespace prefix map will be created at the start of the + XML serialization algorithm. Whenever a new {{Element}} is encountered, the map will be + cloned (copy a namespace prefix map) and new associations will be added for that + {{Element}} (primarily in recording the namespace information, but also when adding + new namespace declarations because no prefix is available for a particular namespace). +

    The last seen prefix for a given namespace is at the end of its respective [=list=]. + When serializing, the [=Element=]'s [=Element/namespace prefix=] will be used if it is in the + [=list=]; otherwise the last prefix in the [=list=] is used. See + retrieve a preferred prefix string for additional details.

    +
    + +
    +

    To copy a namespace prefix map map: +

      +
    1. Let |copy| be a new [=namespace prefix map=]. +
    2. +

      [=map/For each=] |key| → |value| in map: +

        +
      1. Set |copy|[|key|] to a [=list/clone=] of |value|. +
      +
    3. Return |copy|. +
    +
    + +

    To retrieve a preferred prefix string - preferred prefix from the namespace prefix map map given a namespace - ns, the user agent should: + preferred prefix (a string or null) from the namespace prefix map map + given a namespace ns:

      -
    1. Let candidates list be the result of retrieving a list from map - where there exists a key in map that matches the value of ns or if there - is no such key, then stop running these steps, and return the null value. +
    2. If map does not [=map/contain=] ns, return null. -
    3. Otherwise, for each prefix value prefix in candidates list, iterating - from beginning to end: +
    4. Let candidates be map[ns]. -

      There will always be at least one prefix value in the list.

      +
    5. [=Assert=]: candidates [=list/is not empty=].
    6. -
        -
      1. If prefix matches preferred prefix, then stop running these steps - and return prefix. +
      2. +

        If prefix is not null, then: +

          +
        1. +

          [=list/For each=] prefix of candidates: -

        2. If prefix is the last item in the candidates list, then stop running - these steps and return prefix. -
        +
          +
        1. If prefix is preferred prefix, return prefix. +
        +
      +
    7. Return candidates[[=list/size=] of candidates - 1].
    +
    -

    To check if a prefix string prefix is found in a - namespace prefix map map given a namespace ns, the user agent should: +

    +

    To check if a string prefix is found in a namespace prefix map + map given a namespace ns:

      -
    1. Let candidates list be the result of retrieving a list from map - where there exists a key in map that matches the value of ns or if there - is no such key, then stop running these steps, and return false. +
    2. If map does not [=map/contain=] ns, return false. + +
    3. Let candidates be map[ns]. -
    4. If the value of prefix occurs at least once in candidates list, return - true, otherwise return false. +
    5. If |candidates| [=list/contains=] prefix, return true, otherwise return false.
    +
    -

    To add a prefix string prefix to the namespace prefix map - map given a namespace ns, the user agent should: +

    +

    To add a string prefix to a namespace prefix map map + given a namespace ns:

      -
    1. Let candidates list be the result of retrieving a list from map - where there exists a key in map that matches the value of ns or if there - is no such key, then let candidates list be null. - -
    2. If candidates list is null, then create a new list with - prefix as the only item in the list, and associate that list with a new - key ns in map. - -
    3. Otherwise, append prefix to the end of candidates list. - -

      The steps in retrieve a preferred prefix string use the list to - track the most recently used (MRU) prefix associated with a given namespace, which - will be the prefix at the end of the list. This list may contain duplicates of the - same prefix value seen earlier (and that's OK).

      +
    4. +

      If |map| does not [=map/contain=] |ns|: +

        +
      1. Let |candidates| be « |prefix| ». +
      2. Set |map|[|ns|] to |candidates|. +
      +
    5. +

      Otherwise: +

        +
      1. Let |candidates| be |map|[|ns|]. +
      2. [=list/Append=] |prefix| to |candidates|. +
    +
    + +

    The steps in retrieve a preferred prefix string use the list to track + the most recently used prefix associated with a given namespace, which will be the prefix at the + end of the list. This list can contain duplicates of the same prefix seen earlier (and that's + OK).

    Serializing an Element's attributes

    -

    The XML serialization of the attributes of an Element - element together with a namespace prefix map map, a - generated namespace prefix index prefix index reference, a - local prefixes map, a ignore namespace definition attribute flag, and a - require well-formed flag, is the result of the following algorithm: +

    +

    The XML serialization of the attributes of an {{Element}} + element given a namespace prefix map map, + a mutable reference to an integer prefix index, + an [=ordered map=] local prefixes map, + a boolean ignore namespace definition attribute, and + a boolean require well-formed, is the result of the following algorithm:

    1. Let result be the empty string. -
    2. Let localname set be a new empty namespace localname set. This - localname set will contain tuples of unique attribute - namespaceURI and localName pairs, and is populated as - each attr is processed. This set is used to [optionally] enforce - the well-formed constraint that an element cannot have two attributes with the same - namespaceURI and localName. This can occur when two - otherwise identical attributes on the same element differ only by their prefix values. - -
    3. Loop: For each attribute attr in element's - attributes, in the order they are specified in the element's - attribute list: +
    4. Let localname set be « » (an empty [=ordered set=]). + +

      localname set will contain tuples of unique attribute + (namespace, local name) pairs, and is populated as each attr is processed. If + require well-formed is true, it is used to enforce the well-formed constraint + that an element cannot have two attributes with the same [=Attr/namespace=] and + [=Attr/local name=]. This can occur when two otherwise identical attributes on the same + element differ only by their prefix values. If require well-formed is false, + localname set is unnecessary. + +

    5. [=list/For each=] attr of element's [=Element/attribute list=]:
        -
      1. If the require well-formed flag is set (its value is true), and the - localname set contains a tuple whose values match those of a new tuple consisting - of attr's namespaceURI attribute and - localName attribute, then throw an exception; the serialization of - this attr would fail to produce a well-formed element serialization. +
      2. Let attribute namespace be attr's [=Attr/namespace=]. + +
      3. Let |attrName| be a new tuple (|attribute namespace|, attr's + [=Attr/local name=]). -
      4. Create a new tuple consisting of attr's namespaceURI - attribute and localName attribute, and add it to the - localname set. +
      5. If require well-formed is true, and localname set [=set/contains=] + |attrName|, then throw an exception. The serialization of + attr would not be well-formed. -
      6. Let attribute namespace be the value of attr's - namespaceURI value. +
      7. [=set/Append=] |attrName| to localname set. -
      8. Let candidate prefix be null. +
      9. Let candidate prefix be null. -
      10. If attribute namespace is not null, then run these sub-steps: +
      11. If attribute namespace is not null, then:
          -
        1. Let candidate prefix be the result of - retrieving a preferred prefix string from map given namespace - attribute namespace with preferred prefix being attr's - prefix value. +
        2. Let |prefix| be attr's [=Attr/namespace prefix=]. -
        3. If the value of attribute namespace is the XMLNS namespace, then run - these steps: +
        4. Set candidate prefix to the result of + retrieving a preferred prefix string |prefix| from map given + attribute namespace. + +
        5. If attribute namespace is the XMLNS namespace, then:
            -
          1. If any of the following are true, then stop running these steps and goto Loop - to visit the next attribute: +
          2. If any of the following are true, then [=iteration/continue=]:
              -
            • the attr's value is the XML namespace; +
            • attr's [=Attr/value=] is the XML namespace;

              The XML namespace cannot be redeclared and survive round-tripping (unless it defines the prefix "xml"). To avoid this problem, this algorithm always prefixes elements in the XML namespace with "xml" and drops any related definitions as seen in the above condition.

              -
            • the attr's prefix is null and the - ignore namespace definition attribute flag is true (the - Element's default namespace attribute should be skipped); +
            • |prefix| is null and ignore namespace definition attribute is true (the + {{Element}}'s default namespace attribute is to be skipped); -
            • the attr's prefix is not null and either +
            • |prefix| is not null and either
                -
              • the attr's localName is - not a key contained in the local prefixes map, or +
              • local prefixes map does not [=map/contain=] attr's + [=Attr/local name=], or -
              • the attr's localName is - present in the local prefixes map but the value of the key does not match - attr's value +
              • local prefixes map does [=map/contain=] attr's + [=Attr/local name=], but + local prefixes map[attr's [=Attr/local name=]] is not + attr's [=Attr/value=]
              - and furthermore that the attr's - localName (as the prefix to - find) is found in the namespace prefix map given the namespace consisting - of the attr's value (the current namespace prefix - definition was exactly defined previously--on an ancestor element not the current - element whose attributes are being processed). + and furthermore that attr's [=Attr/local name=] is found in + map given attr's [=Attr/value=] (the current namespace prefix + definition was exactly defined previously—on an ancestor element, not |element|).
            -
          3. If the require well-formed flag is set (its value is true), and - the value of attr's value attribute matches the - XMLNS namespace, then throw an exception; the serialization of this attribute would - produce invalid XML because the XMLNS namespace is reserved and cannot be applied - as an element's namespace via XML parsing. +
          4. If require well-formed is true, and attr's [=Attr/value=] is the + XMLNS namespace, then [=throw an exception=]. + The serialization of this attribute would produce invalid XML + because the XMLNS namespace is reserved and cannot be applied as an + element's namespace via XML parsing.

            DOM APIs do allow creation of elements in the XMLNS namespace but with strict qualifications.

            -
          5. If the require well-formed flag is set (its value is true), and - the value of attr's value attribute is the empty string, - then throw an exception; namespace prefix declarations cannot be used to undeclare a - namespace (use a default namespace declaration instead). +
          6. If require well-formed is true, and attr's [=Attr/value=] is the + empty string, then [=throw an exception=]. + Namespace prefix declarations cannot be used to undeclare a + namespace (use a default namespace declaration instead). -
          7. the attr's prefix matches the string - "xmlns", then let candidate prefix be the string +
          8. If |prefix| is "xmlns", then set candidate prefix to "xmlns".
          -
        6. Otherwise, the attribute namespace in not the XMLNS namespace. Run - these steps: +
        7. Otherwise (attribute namespace is not the XMLNS namespace), + if candidate prefix is null: +
            -
          1. Let candidate prefix be the result of generating a prefix providing - map, attribute namespace, and prefix index as input. +
          2. If |prefix| is not null and |local prefixes map| does not [=map/contain=] + |prefix|, set |candidate prefix| to |prefix|. + +
          3. Otherwise, set candidate prefix to the result of + generating a prefix given map, attribute namespace, + and prefix index. + +
          4. [=Add=] |candidate prefix| to |map| given |attribute namespace|. + +
          5. Let |map value| be the empty string if |attribute namespace| is null, and + |attribute namespace| otherwise. + +
          6. [=map/Set=] |local prefixes map|[|candidate prefix|] to |map value|.
          7. Append the following to result, in the order listed:
            1. " " (U+0020 SPACE); -
            2. The string "xmlns:"; +
            3. "xmlns:"; -
            4. The value of candidate prefix; +
            5. candidate prefix;
            6. "="" (U+003D EQUALS SIGN, U+0022 QUOTATION MARK); -
            7. The result of serializing an attribute value given attribute namespace - and the require well-formed flag as input; +
            8. The result of serializing an attribute value given + attribute namespace and require well-formed;
            9. """ (U+0022 QUOTATION MARK).
        -
      12. Append a " " (U+0020 SPACE) to result. +
      13. Append " " (U+0020 SPACE) to result. -
      14. If candidate prefix is not null, then append to result - the concatenation of candidate prefix with ":" (U+003A COLON). +
      15. If candidate prefix is not null, then append to result + the concatenation of candidate prefix and ":" (U+003A COLON). -
      16. If the require well-formed flag is set (its value is true), and this - attr's localName attribute contains the character - ":" (U+003A COLON) or does not match the XML Name production or equals - "xmlns" and attribute namespace is null, then - throw an exception; the serialization of this attr would not be a - well-formed attribute. +
      17. If require well-formed is true, and attr's [=Attr/local name=] + contains the character ":" (U+003A COLON) or does not match the XML Name + production or equals "xmlns" and attribute namespace is null, then + throw an exception. + The serialization of attr would not be well-formed. -
      18. Append the following strings to result, in the order listed: +
      19. Append the following to result, in the order listed:
          -
        1. The value of attr's localName; +
        2. attr's [=Attr/local name=];
        3. "="" (U+003D EQUALS SIGN, U+0022 QUOTATION MARK);
        4. The result of serializing an attribute value given attr's - value attribute and the require well-formed flag as input; + [=Attr/value=] and require well-formed;
        5. """ (U+0022 QUOTATION MARK).
      -
    6. Return the value of result. +
    7. Return result.
    +
    -

    When serializing an attribute value given an attribute value and - require well-formed flag, the user agent must run the following steps: +

    +

    When serializing an attribute value given a string or null |attribute value| and a + boolean require well-formed, run the following steps:

      -
    1. If the require well-formed flag is set (its value is true), and +
    2. If require well-formed is true, and attribute value contains characters that are not matched by the XML Char - production, then throw an exception; the serialization of this attribute value - would fail to produce a well-formed element serialization. + production, then throw an exception. + The serialization of attribute value would not be + well-formed. -
    3. If attribute value is null, then return the empty string. +
    4. If attribute value is null, then return the empty string. -
    5. Otherwise, attribute value is a string. Return the value of - attribute value, first replacing any occurrences of the following: +
    6. Otherwise, return attribute value, first replacing any occurrences of the + following:
      1. "&" with "&amp;" @@ -1048,112 +1098,141 @@

        Extensibility

      2. "<" with "&lt;" -
      3. ">" with "&gt;" +
      4. U+0009 CHARACTER TABULATION with "&#9;" + +
      5. U+000A LINE FEED (LF) with "&#xA;" + +
      6. U+000D CARRIAGE RETURN (CR) with "&#xD;"

      This matches behavior present in browsers, and goes above and beyond the grammar requirement in the XML specification's AttValue production by also replacing ">" characters.

    +

    Generating namespace prefixes

    +

    To generate a prefix given a - namespace prefix map map, a string new namespace, and a reference to - a generated namespace prefix index prefix index, the user agent must run the - following steps: + namespace prefix map map, a string new namespace, and a mutable + reference to an integer prefix index: +

      -
    1. Let generated prefix be the concatenation of the string "ns" and the +
    2. Let generated prefix be the concatenation of "ns" and the current numerical value of prefix index. -
    3. Let the value of prefix index be incremented by one. +
    4. Increment the value of prefix index by one. -
    5. Add to map the generated prefix given the - new namespace namespace. +
    6. Add generated prefix to map given new namespace.
    7. Return the value of generated prefix.
    +
    + +
    -

    XML serializing a Document node

    - - The algorithm for producing an XML serialization of a DOM node of type Document is - as follows: +

    XML serializing a Document node

    -

    If the require well-formed flag is set (its value is true), and this - node has no documentElement (the - documentElement attribute's value is null), then - throw an exception; the serialization of this node would not be a well-formed - document. +

    +

    The algorithm for XML serializing a Document node, given + a {{Document}} |node:Document|, + a string |namespace:string|, + a [=namespace prefix map=] |prefix map:namespace prefix map|, + a mutable reference to an integer |prefix index:mutable reference to an integer|, + and + a boolean require well-formed, + must run the following steps: -

    Otherwise, run the following steps:

      -
    1. Let serialized document be an empty string. +
    2. If require well-formed is true, and node's [=document element=] is + null, then throw an exception. + The serialization of node would not be well-formed. + +
    3. Otherwise: +
        +
      1. Let serialized document be the empty string. -
      2. For each child child of node, in tree order, run the - XML serialization algorithm on the child passing along the provided arguments, - and append the result to serialized document. +
      3. +

        [=set/For each=] child of node's [=tree/children=]: +

          +
        1. Append to serialized document the result of running the + XML serialization algorithm given |child|, inherited ns, map, + prefix index, and require well-formed. +
        -

        This will serialize any number of ProcessingInstruction and Comment - nodes both before and after the Document's documentElement node, including - at most one DocumentType node. (Text nodes are not allowed as children of the - Document.)

        +

        This will serialize any number of {{ProcessingInstruction}} and {{Comment}} + nodes both before and after the [=document element=], as well as at most one + {{DocumentType}} node. ({{Text}} nodes are not allowed as children of a {{Document}}.) -

      4. Return the value of serialized document. +
      5. Return serialized document. +
    +
    -

    XML serializing a Comment node

    +

    XML serializing a Comment node

    - The algorithm for producing an XML serialization of a DOM node of type Comment is as - follows: +
    +

    The algorithm for XML serializing a Comment node, given + a {{Comment}} |node:Comment|, + and + a boolean require well-formed, + must run the following steps: -

    If the require well-formed flag is set (its value is true), and - node's data contains characters that are not matched by the XML - Char production or contains "--" (two adjacent U+002D HYPHEN-MINUS - characters) or that ends with a "-" (U+002D HYPHEN-MINUS) character, then - throw an exception; the serialization of this node's data - would not be well-formed. - -

    Otherwise, return the concatenation of "<!--", node's - data, and "-->". +

      +
    1. If require well-formed is true, and node's [=CharacterData/data=] + contains characters that are not matched by the XML Char production or contains + "--" (two adjacent U+002D HYPHEN-MINUS characters) or ends with a + "-" (U+002D HYPHEN-MINUS) character, then throw an exception. + The serialization of node would not be well-formed. + +
    2. Otherwise, return the concatenation of "<!--", node's + [=CharacterData/data=], and "-->". +
    +
    - -

    XML serializing a Text node

    +

    XML serializing a Text node

    - The algorithm for producing an XML serialization of a DOM node of type Text is as - follows: +
    +

    The algorithm for XML serializing a Text node, given + a {{Text}} |node:Text|, + and + a boolean require well-formed, + must run the following steps:

      -
    1. If the require well-formed flag is set (its value is true), and - node's data contains characters that are not matched by the XML - Char production, then throw an exception; the serialization of this - node's data would not be well-formed. +
    2. Let markup be node's [=CharacterData/data=]. -
    3. Let markup be the value of node's data. +
    4. If require well-formed is true, and markup contains characters that + are not matched by the XML Char production, then throw an exception. + The serialization of node would not be well-formed.
    5. Replace any occurrences of "&" in markup by "&amp;". @@ -1164,96 +1243,104 @@

      Extensibility

    6. Replace any occurrences of ">" in markup by "&gt;". -
    7. Return the value of markup. +
    8. Return markup.
    +
    -

    XML serializing a DocumentFragment node

    +

    XML serializing a DocumentFragment node

    - The algorithm for producing an XML serialization of a DOM node of type - DocumentFragment is as follows: +
    +

    The algorithm for XML serializing a DocumentFragment node, given + a {{DocumentFragment}} |node:DocumentFragment|, + a string |namespace:string|, + a [=namespace prefix map=] |prefix map:namespace prefix map|, + a mutable reference to an integer |prefix index:mutable reference to an integer|, + and + a boolean require well-formed, + must run the following steps:

      -
    1. Let markup the empty string. +
    2. Let markup be the empty string. -
    3. For each child child of node, in tree order, run the - XML serialization algorithm on the child given namespace, - prefix map, a reference to prefix index, and flag - require well-formed. Concatenate the result to markup. +
    4. +

      [=set/For each=] child of node's [=tree/children=]: +

        +
      1. Append to markup the result of running the XML serialization algorithm + given |child|, inherited ns, map, prefix index, and + require well-formed. +
      -
    5. Return the value of markup. +
    6. Return markup.
    +
    -

    XML serializing a DocumentType node

    +

    XML serializing a DocumentType node

    - The algorithm for producing an XML serialization of a DOM node of type DocumentType - is as follows: +
    +

    The algorithm for XML serializing a DocumentType node, given + a {{DocumentType}} |node:DocumentType|, + and + a boolean require well-formed, + must run the following steps:

      -
    1. If the require well-formed flag is true and the node's - publicId attribute contains characters that are not matched by the XML - PubidChar production, then throw an exception; the serialization of this - node would not be a well-formed document type declaration. +
    2. If require well-formed is true, and node's [=DocumentType/public ID=] + contains characters that are not matched by the XML PubidChar production, then + throw an exception. + The serialization of node would not be well-formed. -
    3. If the require well-formed flag is true and the node's - systemId attribute contains characters that are not matched by the XML - Char production or that contains both a """ (U+0022 QUOTATION MARK) and a - "'" (U+0027 APOSTROPHE), then throw an exception; the serialization of this - node would not be a well-formed document type declaration. +
    4. If require well-formed is true, and node's [=DocumentType/system ID=] + contains characters that are not matched by the XML Char production or that contains + both a """ (U+0022 QUOTATION MARK) and a "'" (U+0027 APOSTROPHE), + then throw an exception. + The serialization of node would not be well-formed. -
    5. Let markup be an empty string. +
    6. Let markup be the empty string. -
    7. Append the string "<!DOCTYPE" to markup. +
    8. Append "<!DOCTYPE" to markup.
    9. Append " " (U+0020 SPACE) to markup. -
    10. Append the value of the node's name - attribute to markup. For a node belonging to an HTML document, the - value will be all lowercase. +
    11. Append node's [=DocumentType/name=] to markup. + For a node belonging to an HTML document, the + name will be all lowercase. -
    12. If the node's publicId is not the empty string then append +
    13. If node's [=DocumentType/public ID=] is not the empty string, then append the following, in the order listed, to markup:
      1. " " (U+0020 SPACE); -
      2. The string "PUBLIC"; +
      3. "PUBLIC";
      4. " " (U+0020 SPACE); -
      5. """ (U+0022 QUOTATION MARK); - -
      6. The value of the node's publicId attribute; - -
      7. """ (U+0022 QUOTATION MARK). +
      8. the [=serialization of the ID=] node's [=DocumentType/public ID=].
      -
    14. If the node's systemId is not the empty string and the - node's publicId is set to the empty string, then append the +
    15. If node's [=DocumentType/system ID=] is not the empty string and + node's [=DocumentType/public ID=] is the empty string, then append the following, in the order listed, to markup:
      1. " " (U+0020 SPACE); -
      2. The string "SYSTEM". +
      3. "SYSTEM".
      -
    16. If the node's systemId is not the empty string then append +
    17. If node's [=DocumentType/system ID=] is not the empty string, then append the following, in the order listed, to markup:
      1. " " (U+0020 SPACE); -
      2. """ (U+0022 QUOTATION MARK); - -
      3. The value of the node's systemId attribute; - -
      4. """ (U+0022 QUOTATION MARK). +
      5. the [=serialization of the ID=] node's [=DocumentType/system ID=].
    18. Append ">" (U+003E GREATER-THAN SIGN) to markup. -
    19. Return the value of markup. +
    20. Return markup. +
    +
    + +
    +

    The serialization of the ID |id:string| is the result of the following steps: +

      +
    1. If |id| contains """ (U+0022 QUOTATION MARK), let |q| be + "'" (U+0027 APOSTROPHE), and let |q| be """ (U+0022 QUOTATION MARK) + otherwise. +
    2. Return the concatenation of |q|, |id|, and |q|.
    +
    -

    XML serializing a ProcessingInstruction node

    +

    XML serializing a ProcessingInstruction node

    - The algorithm for producing an XML serialization of a DOM node of type - ProcessingInstruction is as follows: +
    +

    The algorithm for XML serializing a ProcessingInstruction node, given + a {{ProcessingInstruction}} |node:ProcessingInstruction|, + and + a boolean require well-formed, + must run the following steps:

      -
    1. If the require well-formed flag is set (its value is true), and - node's target contains a ":" (U+003A COLON) - character or is an ASCII case-insensitive match for the string "xml", then - throw an exception; the serialization of this node's - target would not be well-formed. - -
    2. If the require well-formed flag is set (its value is true), and - node's data contains characters that are not matched by the XML - Char production or contains the string "?>" (U+003F QUESTION MARK, - U+003E GREATER-THAN SIGN), then throw an exception; the serialization of this - node's data would not be well-formed. +
    3. If require well-formed is true, and node's + [=ProcessingInstruction/target=] contains a ":" (U+003A COLON) + character or is an ASCII case-insensitive match for "xml", then + throw an exception. + The serialization of node would not be well-formed. + +
    4. If require well-formed is true, and node's [=CharacterData/data=] + contains characters that are not matched by the XML + Char production or contains "?>" (U+003F QUESTION MARK, + U+003E GREATER-THAN SIGN), then throw an exception. + The serialization of node would not be well-formed.
    5. Let markup be the concatenation of the following, in the order listed:
      1. "<?" (U+003C LESS-THAN SIGN, U+003F QUESTION MARK); -
      2. The value of node's target; +
      3. node's [=ProcessingInstruction/target=];
      4. " " (U+0020 SPACE); -
      5. The value of node's data; +
      6. node's [=CharacterData/data=];
      7. "?>" (U+003F QUESTION MARK, U+003E GREATER-THAN SIGN).
      -
    6. Return the value of markup. +
    7. Return markup.
    +
    @@ -1324,95 +1427,19 @@

    Extensibility

    Dependencies

    - The HTML specification [[!HTML5]] defines the following terms used in this document: + The HTML specification [[!HTML]] defines the following terms used in this document: - The DOM specification [[!DOM4]] defines the following terms used in this document: - - - - The following terms used in this document are defined by [[DOM]]: - -
      -
    • The ShadowRoot interface -
    - The following terms used in this document are defined by [[XML10]]: - - The ECMAScript [[ECMA-262]] (commonly "JavaScript") specification defines these terms: - - - - The Web IDL [[WebIDL]] specification defines: - -
    @@ -1477,7 +1492,7 @@

    Acknowledgements

    for their useful comments.

    Special thanks to Ian Hickson for first defining the innerHTML and outerHTML - attributes, and the insertAdjacentHTML method in [[HTML5]] and his useful comments. + attributes, and the insertAdjacentHTML method in [[HTML]] and his useful comments.

    diff --git a/respecConfig.js b/respecConfig.js index 5700f99..9b698cd 100644 --- a/respecConfig.js +++ b/respecConfig.js @@ -7,7 +7,7 @@ var respecConfig = { { name: "Travis Leithead", company: "Microsoft", mailto: "travis.leithead@microsoft.com", companyURL: "http://www.microsoft.com", w3cid: "40117" } ], edDraftURI: "https://w3c.github.io/DOM-Parsing/", - xref: ["webidl", "html"], + xref: "web-platform", //format: "markdown", shortName: "DOM-Parsing", wg: ["Web Platform Working Group"], @@ -17,16 +17,14 @@ var respecConfig = { wgPublicList: "www-dom", wgPatentURI: ["https://www.w3.org/2004/01/pp-impl/83482/status"], subjectPrefix: "DOM-Parsing", + github: "w3c/DOM-Parsing", otherLinks: [{ key: "Test Suites", data: [ - { href: "http://w3c-test.org/domparsing/" }, - { href: "http://w3c-test.org/html/syntax/" } + { href: "http://wpt.live/domparsing/" }, + { href: "http://wpt.live/html/syntax/" } ]}, { key: "Participate", data: [ - { value: 'We are on Github.', href: 'https://github.com/w3c/DOM-Parsing' }, - { value: 'Bugzilla Bug list.', href: 'https://www.w3.org/Bugs/Public/buglist.cgi?component=DOM%20Parsing%20and%20Serialization&list_id=44989&product=WebAppsWG&resolution=---' }, - { value: 'Github Issues.', href: 'https://github.com/w3c/DOM-Parsing/issues' }, - { value: 'Commit history.', href: 'https://github.com/w3c/DOM-Parsing/commits' }, + { value: 'Bugzilla Bug list.', href: 'https://www.w3.org/Bugs/Public/buglist.cgi?component=DOM%20Parsing%20and%20Serialization&list_id=44989&product=WebAppsWG&resolution=---' }, { value: 'Mailing list.', href: 'http://lists.w3.org/Archives/Public/www-dom/' } ]} ]