minidom appendChild confusion

Marco marco.wahl at gmail.com
Fri Sep 23 12:16:29 CEST 2005


Hello!

Can anyone explain why the following code does not work?
(I'm using python2.4.)


Cheers,  Marco

--

# the following code does _not_ work.
# intended: put child-nodes as children to another node

from xml.dom.minidom import Document
doc = Document()
node1 = doc.createElement('one')
el1 = doc.createElement('e1')
el2 = doc.createElement('e1')
node1.appendChild(el1)
node1.appendChild(el2)
assert 2 == len(node1.childNodes) # ok

doc2 = Document()
node2 = doc2.createElement('two')

for el in node1.childNodes:
    node2.appendChild(el)

assert 2 == len(node2.childNodes), "node2 has an unexpected number of
children"




More information about the Python-list mailing list