I have this xml model.
So I have to add some node (see the text commented) to this file. How I can do it?
I have writed this partial code but it doesn't work:
xmldoc=minidom.parse(directory)
child = xmldoc.createElement("map")
for node in xmldoc.getElementsByTagName("Environment"):
node.appendChild(child)
Thanks in advance.
I downloaded your sample xml file and your code works fine. Your problem is most likely with the line:
xmldoc=minidom.parse(directory)
, should this not be the path to the file you are trying to parse not to a directory? Theparse()
function parses an XML file it does not automatically parse all the XML files in a given directory.If you change your code to something like below this should work fine:
If you then execute the statement:
print xmldoc.toxml()
you will see that themap
element has indeed been added to theEnvironment
element:<Environment><map/></Environment>
.