From: Ross on
On Jan 25, 10:31 pm, Thomas 'PointedEars' Lahn <PointedE...(a)web.de>
wrote:
> RobG wrote:
> > Ross wrote:
> >> On the idea that perhaps the fragment coming from the other document
> >> might not be easily appendable in a stricter interpretation of DOM, I
> >> looked around for info that might have to do with detaching or
> >> duplicating the element.   I found that if I clone the node it works
> >> in Safari then too :)
>
> >> So
> >>   dest.appendChild(el)
>
> >> becomes
> >>   dest.appendChild(el.cloneNode(true))
>
> >> Yay.  Hope that saves someone else the hour or two I wasted on trying
> >> to figure out why my script worked in one browser and not another.
>
> > The root issue was probably that you were appending nodes from a XML
> > document to an HTML document.
>
> No, the OP's assumptions are correct:
>
> ,-<http://www.w3.org/TR/DOM-Level-3-Core/core.html#ID-184E7107>
> |
> | appendChild  modified in DOM Level 3
> |
> |   Adds the node newChild to the end of the list of children of this node.
> |   If the newChild is already in the tree, it is first removed.
> |
> |   Parameters
> |
> |     newChild of type Node
> |       The node to add.
> |       If it is a DocumentFragment object, the entire contents of the
> |       document fragment are moved into the child list of this node
> | [...]
> |   Exceptions
> | [...]
> |     WRONG_DOCUMENT_ERR: Raised if newChild was created from a different
> |     document than the one that created this node.
>
> > Is there any reason to expect that cloning an XML node will *always*
> > produce an HTML node? In all browsers?
>
> No.  Although regarding W3C DOM Level 2+ Core there is no inherent
> difference between XML nodes and HTML nodes (both implement the Node
> interface) and Node::cloneNode() is described as "a generic copy
> constructor for nodes",
>
>   dest.appendChild(document.importNode(el, true));
>
> should be used instead which explicitly performs the necessary
> transformations regarding namespaces (HTML does not support namespaces,
> XML/XHTML does).
>
> <http://www.w3.org/TR/DOM-Level-3-Core/core.html#Core-Document-importNode>
>
> PointedEars
> --
> Anyone who slaps a 'this page is best viewed with Browser X' label on
> a Web page appears to be yearning for the bad old days, before the Web,
> when you had very little chance of reading a document written on another
> computer, another word processor, or another network. -- Tim Berners-Lee


More good info. Thanks for the insight.

- Ross.