dom2dom: producing specialized nodes 2005-10-11 - By Stéphane Conversy
Le 10 oct. 05, � 22:00, Joseph Kesselman a �crit :
>> if I pass a document Node, I get an error during the transformation >> process, it denies the creation of a new element directly under the >> document node. > > Document nodes became relatively immutable in DOM Level 2 (though > that's > relaxed slightly in DOM Level 3) for reasons related to subclassing of > the > DOM. If you're working with a DOM that does not permit altering the > Document node's root element, you can't pass in a Document node and > have > this work. > > I believe there is an outstanding wishlist item to change DOMResult so > we > could pass in a DOMImplementation and possibly a DocumentType (or > retrieve > those from a sample Document node) , and use the > DOMImplementation.createDocument() method to properly create a new DOM > tree. But I don't think that's been implemented yet. This shouldn't be > hard > to code up; if someone wants to sketch a solution and submit it, > that'd be > great...
I do not have much time, if I run into performance problem because of this 2 steps procedure, I may have a look at it...
> > Workaround: Build into a DocumentFragment, and postprocess to > re-instantiate the root element in a new document and use importNode to > migrate the element's contents into that new element node. If the new > DOM > is in the same implementation as the old one, most DOMs are able to > migrate > the nodes over without having to recreate them, so this is annoying > but not > expensive.
Actually, when Batik's JSVGCanvas.setDocument(Document) is called, Batik checks if the passed document is its own implementation. If so it uses it as is, otherwise it clones it, as you suggest to do.
> > If I remember correctly, DOM Level 3 may (or may not, implementation > dependent due to the same subclassing issues) permit creating an empty > Document node and then adding to it. We'll still want the > build-via-DOMImplementation support added, though. > > ______________________________________ > 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 > -- st�phane conversy http://www.tls.cena.fr/~conversy
|
|