minidom nodes without a document?

Levente Sandor sandorlevi at yahoo.com
Mon Nov 24 02:38:20 CET 2003


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.

>>> import xml.dom.minidom
>>> doc = xml.dom.minidom.Document()
>>> foo = doc.createElement('foo')
>>> for i in range(3):
...     foo.appendChild(doc.createElement('bar'))
...
>>> doc.toxml()
'<?xml version="1.0" ?>\n'
>>> foo.toxml()
'<foo><bar/><bar/><bar/></foo>'
>>>

----
levi




More information about the Python-list mailing list