Hi, I am having some problems removing children from an xml node.
I had:
Code:
node = xmldoc.getElementsByTagName('types')[0]
for child in node.childNodes:
print child.toxml()
node.removeChild(child)
That just printed a few blank lines and did nothing. Then I tried:
Code:
node = xmldoc.getElementsByTagName('types')[0]
for child in node.childNodes:
for grandchild in child.childNodes:
print grandchild.toxml()
child.removeChild(grandchild)
That emptied the children but still left them there.
eg
Code:
<types>
<type>jpg</type>
<type>png</type>
<type>gif</type>
</type>
to
Code:
<types>
<type/>
<type/>
<type/>
</type>
I would like to completely empty types.
Any suggestions?
edit: solved
Code:
node = xmldoc.getElementsByTagName('types')[0]
while len(node.childNodes) > 0:
child = node.childNodes[0]
print child.toxml()
node.removeChild(child)
Bookmarks