W3C home > Mailing lists > Public > www-dom@w3.org > January to March 1999

cloneNode and ownerDocument

From: Andrew M. Kuchling <akuchlin@cnri.reston.va.us>
Date: Thu, 25 Mar 1999 11:58:47 -0500 (EST)
Message-Id: <199903251658.LAA00865@amarok.cnri.reston.va.us>
To: www-dom@w3.org
Here's a question someone raised on the Python XML-SIG.  If N is a
node, and N.ownerDocument is some document D, is
N.cloneNode().ownerDocument also equal to D?  In other words, can
cloneNode() be used to make documentless nodes or subtrees that can be
moved across DOM document trees?

	On the subject of cloneNode(), the Level 1 spec says only that
the parent is null, but nothing about the value of ownerDocument for
the clone.  My suspicion is that N.cloneNode().ownerDocument is D,
because it's stated elsewhere that N.ownerDocument() is null when N is
a Document node, and having cloned nodes also have
 a null ownerDocument would be confusing in many ways.  For example,
you'd have no way of creating new nodes when dealing with a cloned
node or tree, because you'd have no .ownerDocument.createXXX() to
call.

	This question stems from a more general issue.  Moving or
copying subtrees from one Document to another seems to be a fairly
common request.  Am I correct in believing that such copying isn't
possible, and people should be using DocumentFragments in such cases?

-- 
A.M. Kuchling			http://starship.python.net/crew/amk/
    "You can't kill me."
    "We can. If we want to. You scarcely exist. You're a dream of a ghost of a
memory of someone who, one suspects, never existed in the first place."
    -- Abel and the Furies, in SANDMAN #66: "The Kindly Ones:10"
Received on Thursday, 25 March 1999 11:58:56 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Friday, 22 June 2012 06:13:46 GMT