At 12:45 PM 8/7/2003 -0400, you wrote:




Officially, the DOM doesn't currently allow you to replace the document
element. (DOM Level 3 may relax that restriction), which makes this a bit
more complicated if you want a fully portable solution. There may also be
children of the Document other than the root element which would need to be
imported and inserted in the right places. And starting with a
DocumentFragment or NodeList, because it may not have a single root
element, also needs a bit of secial-casing.

This is a bit more code than I really want to rattle off right now, I'm
afraid.

So, you are saying the following code is invalid?

DOMImplementation domImpl = document.getImplementation();
Document doc = domImpl.createDocument("", "roottagname", null);
Node node = doc.importNode(document.getDocumentElement(), true);
doc.replaceChild(node, doc.getDocumentElement());

Where is this stated "officially"? The javadoc for Node#replaceChild() says nothing about it. Now, Document#importNode() mentions not being able to import a Document node or a Document type node, but a document element is simply an Element. getDocumentElement() is simply a convenience method to get the root element of the document. Once it is had, I don't know of any special status that it has? It is just an Element, isn't it?

BTW, this works fine in xerces-1.4.4. Will it not work in Xerces2? Or does it work there for backward compatibility, but might not work in other dom implementations? Again, I really don't see what is wrong with doing this?

Jake

______________________________________
Joe Kesselman, IBM Next-Generation Web Technologies: XML, XSL and more.
"The world changed profoundly and unpredictably the day Tim Berners Lee
got bitten by a radioactive spider." -- Rafe Culpin, in r.m.filk


--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to