title: Python create xml file dynamically
body: <p>i'm having trouble creating the xml file in python. My script at start loads a text file, read each line and check if the content contains a specific string, depending on it i want to create a tag  or  in the xml file.
  For that i'm using the <code>ElementTree</code> module.</p>
  
  <p>This the code</p>
  
  <pre><code>for line in myfile.read().splitlines():
      if 'EXTINF' in line:
          root = etree.Element("item")
          etree.SubElement(root, "title").text = line
      elif 'http' in line:
          etree.SubElement(root, "link").text = 'http:\\mysite.com\'
  tree = etree.ElementTree(root)
  tree.write('my\\path\\'+xml_file.xml)
  </code></pre>
  
  <p>The xml file contains only the last element iterated by for loop.</p>
  
  <p>The output i would like is:</p>
  
  <pre><code>&lt;item&gt;
      &lt;title&gt; "my title" &lt;/title&gt;
      &lt;link&gt; "http:\\mysite.com" &lt;/link&gt;
  &lt;/item&gt;
  
  &lt;item&gt;
      &lt;title&gt; "my title" &lt;/title&gt;
      &lt;link&gt; "http:\\mysite.com" &lt;/link&gt;
  &lt;/item&gt;
  
  &lt;item&gt;
      &lt;title&gt; "my title" &lt;/title&gt;
      &lt;link&gt; "http:\\mysite.com" &lt;/link&gt;
  &lt;/item&gt;
  </code></pre>
  
  <p>What's wrong?
  Thanks</p>