How to create a nodes every time i go through the loop in python
<p>I like to create a nodes every time when i go through a loop.But presently only the last value of the loop will be used. How can i achieve this using python. following is my example.</p>

<p>My xml :-</p>

<pre><code>&lt;person&gt;
&lt;user name="david" password="super"&gt;&lt;/user&gt;
&lt;user name="alen" password="boss"&gt;&lt;/user&gt;
&lt;user name="windeesal" password="sp"&gt;&lt;/user&gt;
&lt;/person&gt;
</code></pre>

<p>The python code:</p>

<pre><code>import xml.etree.ElementTree as ET

doc = ET.parse("users.xml")
root = doc.getroot() #Returns the root element for this tree.
root.keys()          #Returns the elements attribute names as a list. The names are returned in an arbitrary order
for child in root:
    name = child.attrib['name']
    password = child.attrib['password']

root = ET.Element("person")
user = ET.SubElement(root, "user")
user.set("username",username)
user.set("password",password)

tree = ET.ElementTree(root)
myxml = tree.write("new.xml")

print myxml 
</code></pre>

<p>Out put of the code contain only last value of loop :(</p>

<pre><code>&lt;person&gt;
&lt;user password="sp" username="windeesal" /&gt;
&lt;/person&gt;
</code></pre>

<p>how to create the nodes every time i go through the loop then join the results and write them to the file .? am really a beginner please give me a detail explanation. Thank you very much . </p>
