<p>I'm trying to generate customized xml files from a template xml file in python. </p>

<p>Conceptually, I want to read in the template xml, remove some elements, change some text attributes, and write the new xml out to a file.  I wanted it to work something like this:</p>

<pre><code>conf_base = ConvertXmlToDict('config-template.xml')
conf_base_dict = conf_base.UnWrap()
del conf_base_dict['root-name']['level1-name']['leaf1']
del conf_base_dict['root-name']['level1-name']['leaf2']

conf_new = ConvertDictToXml(conf_base_dict)
</code></pre>

<p>now I want to write to file, but I don't see how to get to 
ElementTree.ElementTree.write() </p>

<pre><code>conf_new.write('config-new.xml') 
</code></pre>

<p>Is there some way to do this, or can someone suggest doing this a different way? </p>

I'm not sure if converting the info set to nested dicts first is easier. Using ElementTree, you can do this:
```
```
import xml.etree.ElementTree as ET
doc = ET.parse("template.xml")
lvl1 = doc.findall("level1-name")[0]
lvl1.remove(lvl1.find("leaf1")
lvl1.remove(lvl1.find("leaf2")
# or use del lvl1[idx]
doc.write("config-new.xml")
```
```
ElementTree was designed so that you don't have to convert your XML trees to lists and attributes first, since it uses exactly that internally.
It also support as small subset of
XPath
.