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

RE: setting document root element

From: Garret Wilson <garret@globalmentor.com>
Date: Tue, 15 Jan 2002 08:05:20 -0500 (EST)
Message-ID: <58000.192.91.75.29.1011099920.squirrel@globalmentor.com>
To: <www-dom@w3.org>
Cc: <sander@x-hive.com>
The latest DOM Level 2 Core still doesn't allow the document root element
to be set directly, so I guess the document.replaceChild() method reported
below is the only alternative.

Can someone verify that the DOM actually allows using document.replaceChild
() to change the document element?

Garret

>> 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 Tuesday, 15 January 2002 11:22:40 GMT

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