import sys
from xml.dom.minidom import Document
doc = Document()
configuration = doc.createElement("configuration")
xsl = doc.createProcessingInstruction("xml-stylesheet", "type=\"text/xsl\" href=\"configuration.xsl\"")
doc.appendChild(xsl)
prop = doc.createElement("property")
# START LOOP HERE
name = doc.createElement("name")
name_text = doc.createTextNode("my name")
name.appendChild(name_text)
prop.appendChild(name)
value = doc.createElement("value")
value_text = doc.createTextNode("my value")
value.appendChild(value_text)
prop.appendChild(value)
# END LOOP HERE
configuration.appendChild(prop)
doc.appendChild(configuration)
print doc.toprettyxml()
The output is as follows:
<?xml version="1.0" ?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
<configuration>
<property>
<name>
my name
</name>
<value>
my value
</value>
</property>
</configuration>