minidom nodes without a document?

John J. Lee jjl at pobox.com
Tue Nov 25 14:03:24 EST 2003


mlh at furu.idi.ntnu.no (Magnus Lie Hetland) writes:

> In article <8b5e42a6.0311231738.6376d486 at posting.google.com>, Levente
> Sandor wrote:
> >mlh at furu.idi.ntnu.no (Magnus Lie Hetland) wrote in message
> >news:<slrnbs23vn.q61.mlh at furu.idi.ntnu.no>...
> >> Is it possible to build a minidom tree bottom-up without access to a
> >> document node? It seems that simply instantiating the various node
> >> classes doesn't quite do the trick...
> >
> >I'm not sure what you mean exactly by "without access to...". You need
> >a Document instance to create the elements, but they aren't added
> >automatically to it.
> >
> [snip]
> 
> Right. I understand this. Thanks to you and Martin for mentioning it,
> though :)
> 
> My problem is that I'm building the DOM as part of a bottom-up parse,
> where the various subtrees are build independently from each other,
> through callbacks that are set as part of the parser. So... For all of
[...]

You want DocumentFragment.

But Martin's right (of course): you still need a Document, and you
make fragments by calling Document.createDocumentFragment().

For a headache-inducing example of the use of this (my headache, not
yours, I hope ;-), see

http://wwwsearch.sf.net/DOMForm/


(the parser is in the file DOMForm/_js.py -- it gave me a headache
because everything prior to a chunk of embedded script in HTML has to
be available to the script through the document object, so sometimes
you have to append to a DocumentFragment, sometimes to a node in the
main Document tree)


John




More information about the Python-list mailing list