- From: Garret Wilson <garret@globalmentor.com>
- Date: Tue, 15 Jan 2002 08:05:20 -0500 (EST)
- 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 UTC