- From: Geoffrey Thomas <notifications@github.com>
- Date: Mon, 26 Aug 2024 14:11:12 -0700
- To: w3c/DOM-Parsing <DOM-Parsing@noreply.github.com>
- Cc: Subscribed <subscribed@noreply.github.com>
- Message-ID: <w3c/DOM-Parsing/issues/85@github.com>
In the course of figuring out a workaround to #84, I decided to looked for some other mechanism that does actually set the "require well-formed" parameter to true when serializing. My reading is that [`outerHTML`](https://html.spec.whatwg.org/multipage/dynamic-markup-insertion.html#the-outerhtml-property)'s getter runs [the fragment serializing algorithm](https://html.spec.whatwg.org/multipage/dynamic-markup-insertion.html#fragment-serializing-algorithm-steps) with the "require well-formed" parameter set to true, and the fragment serializing algorithm specifically produces an XML serialization if the node document is XML, and serializing an XML node [serializes its children by specifically calling XML serialization](https://w3c.github.io/DOM-Parsing/#dfn-xml-serializing-an-element-node), preserving the "require well-formed" flag in the recursive call. That is, getting `.outerHTML` on a XML node with an unserializable child should fail. (Note also that `outerHTML` is documented as "In the case of an XML document, throws a [`"InvalidStateError"`](https://webidl.spec.whatwg.org/#invalidstateerror) [`DOMException`](https://webidl.spec.whatwg.org/#dfn-DOMException) if the element cannot be serialized to XML.") But if you try the following code ```javascript const xmlDoc = document.implementation.createDocument(null, null); const rootNode = xmlDoc.createElement("root"); xmlDoc.appendChild(rootNode); const childNode = document.createElement("child"); childNode.innerHTML = '<meta property="og:description" content="I forgot to "escape" this value">'; xmlDoc.adoptNode(childNode); rootNode.appendChild(childNode); const result = rootNode.outerHTML; console.log(result); console.log(new DOMParser().parseFromString(result, "text/xml").querySelector('parsererror').innerHTML); ``` in Firefox, Safari, and Chrome, `.outerHTML` does not throw and returns not-well-formed XML, and you can see that `DOMParser` does not like it. Am I missing something in the specification that provides for this behavior? I realize I'm doing something tricky by adopting an HTML element into XML, but my reading of the [adoption process](https://dom.spec.whatwg.org/#concept-node-adopt-ext) is that it change's the node's node document, and this is what triggers serializing as XML. In any case, I'm getting `.outerHTML` of an actual XML node, which should recursively serialize as XML. I mentioned this over at https://bugzilla.mozilla.org/1914813 and was told that even if this is an implementation bug but all the major implementations happen to do the same thing, the right thing to do is to update the spec, so I'm filing this here. -- Reply to this email directly or view it on GitHub: https://github.com/w3c/DOM-Parsing/issues/85 You are receiving this because you are subscribed to this thread. Message ID: <w3c/DOM-Parsing/issues/85@github.com>
Received on Monday, 26 August 2024 21:11:16 UTC