W3C home > Mailing lists > Public > www-dom@w3.org > October to December 2001

RE: setting document root element

From: Sander Bos <sander@x-hive.com>
Date: Mon, 12 Nov 2001 18:23:52 +0100
Message-ID: <41D11F414A26E942912B7E7696DC8E22061549@JAKARTA.xhive.archipel>
To: "www-dom list" <www-dom@w3.org>

> DOM Level 1 didn't specify how the root element was created, 
> but I believe
> it did say it couldn't be removed.
> 
> DOM Level 2 said the root element could be created only at 
> the time the
> document was created, and still didn't permit removing it. 
> The rationalle
> has to do with potentially using information about the root element's
> namespace and localname, along with the document type information, to
> select among different DOM implementations/subclasses.

In our implementation, we do not allow
	document.removeChild(document.getDocumentElement());
, however we do allow
	document.replaceChild(someElement,
document.getDocumentElement());
Since the replaceChild spec text does not say explicitly that part of
its action is removing the old child, I think this adheres to the
specification (and if it doesn't, then we break the spec).
We had two customers asking for this precisely because of the reason
given by Garret, namely that it is very annoying to have to copy over
attributes from another element (both did not want to change the
document element name). Their usage was for making a copy of a document:
	Document copyDoc = impl.createDocument(null, "dummy", null);
	Node copy = copyDoc.importNode(sourceDoc.getDocumentElement());
	copyDoc.replaceChild(copy, copyDoc.getDocumentElement());
Without replaceChild, this would take a lot more than three lines.

Kind regards,

--Sander.
Received on Monday, 12 November 2001 12:24:36 GMT

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