> Ben C wrote:
>> There's been some dispute about this before, but my view is that HTML
>> validity is not required of bits of documents constructed by DOM, but if
>> it is, I'd be interested to know where in which spec this is stated.
>
> W3C DOM Level 2 HTML makes provisions for XHTML,
To be found here:
<http://www.w3.org/TR/DOM-Level-2-HTML/html.html#ID-5353782642>
<http://www.w3.org/TR/DOM-Level-2-HTML/html.html#ID-882764350>
> and I would be surprised if the XML DOM Specification would not do so for
> XML.
Apparently, there is no explicit XML DOM Specification but W3C DOM Level 2+
Core applies for both HTML DOM and XML DOM. Here for Node::appendChild():
,-<http://www.w3.org/TR/DOM-Level-3-Core/core.html#ID-184E7107>
|
| [...]
|
| Exceptions
|
| DOMException HIERARCHY_REQUEST_ERR: Raised if this node is of a type
| that does not allow children of the type of the newChild
| node, or if the node to append is one of this node's
| ancestors or this node itself, or if this node is of type
| Document and the DOM application attempts to append a
| second DocumentType or Element node.
(The first and third cases are relevant regarding validity.)
DOM Specifications for other markup languages (like the SVG DOM of the SVG
1.1 Specification [SVGDOM]) specify similar restrictions in order to ensure
that the resulting document tree (and therefore, its serialization) is
Valid.
But, AISB, it depends on the implementation to honor that.
X-Post & F'up2 comp.lang.javascript
PointedEars
___________
[SVGDOM] <http://www.w3.org/TR/SVG/svgdom.html>
But isn't that just for things like trying to give a #text node
children? I didn't think it was supposed to enforce validity in the much
stricter HTML sense.
And I'm pretty sure you don't get a HIERARCHY_REQUEST_ERR in any of the
main browsers if you put a div inside a span with appendChild.