Create new xml using python
<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:
    username             = child.attrib['username']
    password             = child.attrib['password']
    grant_admin_rights   = child.attrib['grant_admin_rights']
    create_private_share = child.attrib['create_private_share']
    uid                  = child.attrib['uid']



root  = ET.Element("users")
user  = ET.SubElement(root, "user")
user.set("username",username)
user.set("password",password)
user.set("grant_admin_rights",grant_admin_rights)
user.set("create_private_share",create_private_share)
user.set("uid",uid)

tree = ET.ElementTree(root)
myxml = tree.write("new.xml")
</code></pre>

<p>output of this code :-</p>

<pre><code>&lt;users&gt;&lt;user create_private_share="no" grant_admin_rights="no" password="sp" uid
="1000" username="us" /&gt;&lt;/users&gt;
</code></pre>

<p>But am trying to make it like this :-</p>

<pre><code>&lt;users&gt;

&lt;user create_private_share="no" grant_admin_rights="no" password="sp" uid
="1000" username="us" &gt;&lt;group&gt;hfhfhf&lt;/group&gt; &lt;/user&gt;

&lt;/users&gt;
</code></pre>

<p>instead of this <code>&lt;user /&gt;</code>, am trying <code>&lt;user&gt; &lt;group&gt;fgfg&lt;/group&gt;  &lt;/user&gt;</code> . Thanks </p>
