Q:

Add duplicate child tag in existing xml

sample.py
import xml.etree.cElementTree as ET
log_file=open("filename.xml","a")
root = ET.Element("VOD")
doc = ET.Element("SessionDetails")
root.append(doc)
tree = ET.ElementTree(root)
tree.write("filename.xml")

o/p on running sample.py 3 time
<?xml version="1.0"?>

-<VOD>

<SessionDetails/>

</VOD>

[Note :I am not getting below output]Desired o/p is if I run sample.py 3 times the o/p should be as below
-<VOD>

<SessionDetails/>
<SessionDetails/>
<SessionDetails/>

</VOD>

A:

I got result using below method 
First time XML creation
from xml.dom.minidom import getDOMImplementation
impl = getDOMImplementation()
newdoc = impl.createDocument(None, "VOD", None)
top_element = newdoc.documentElement
text = newdoc.createElement('SessionDetaild')
top_element.appendChild(text)
newdoc.writexml(open("filename.xml","w"))

For appending data in xml
import xml.dom.minidom as m
doc = m.parse("filename.xml")
valeurs = doc.getElementsByTagName("VOD").item(0)
element = doc.createElement("SessionDetaild")
valeurs.appendChild(element)
doc.writexml(open("filename.xml","w"))

Reference:
http://stackoverflow.com/questions/11074021/inserting-xml-nodes-in-an-existing-xml-document-with-python

