title: Merge xml files with nested elements without external libraries
body: <p>I am trying to merge multiple XML files together using Python and no external libraries. The XML files have nested elements.</p>
  
  <p><strong>Sample File 1:</strong></p>
  
  <pre><code>&lt;root&gt;
    &lt;element1&gt;textA&lt;/element1&gt;
    &lt;elements&gt;
      &lt;nested1&gt;text now&lt;/nested1&gt;
    &lt;/elements&gt;
  &lt;/root&gt;
  </code></pre>
  
  <p><strong>Sample File 2:</strong></p>
  
  <pre><code>&lt;root&gt;
    &lt;element2&gt;textB&lt;/element2&gt;
    &lt;elements&gt;
      &lt;nested1&gt;text after&lt;/nested1&gt;
      &lt;nested2&gt;new text&lt;/nested2&gt;
    &lt;/elements&gt;
  &lt;/root&gt;
  </code></pre>
  
  <p><strong>What I Want:</strong></p>
  
  <pre><code>&lt;root&gt;
    &lt;element1&gt;textA&lt;/element1&gt;    
    &lt;element2&gt;textB&lt;/element2&gt;  
    &lt;elements&gt;
      &lt;nested1&gt;text after&lt;/nested1&gt;
      &lt;nested2&gt;new text&lt;/nested2&gt;
    &lt;/elements&gt;  
  &lt;/root&gt;  
  </code></pre>
  
  <p><strong>What I have tried:</strong></p>
  
  <p>From <a href="https://stackoverflow.com/a/11315257/1561176">this answer</a>. </p>
  
  <pre><code>from xml.etree import ElementTree as et
  def combine_xml(files):
      first = None
      for filename in files:
          data = et.parse(filename).getroot()
          if first is None:
              first = data
          else:
              first.extend(data)
      if first is not None:
          return et.tostring(first)
  </code></pre>
  
  <p><strong>What I Get:</strong></p>
  
  <pre><code>&lt;root&gt;
    &lt;element1&gt;textA&lt;/element1&gt;
    &lt;elements&gt;
      &lt;nested1&gt;text now&lt;/nested1&gt;
    &lt;/elements&gt;
    &lt;element2&gt;textB&lt;/element2&gt;
    &lt;elements&gt;
      &lt;nested1&gt;text after&lt;/nested1&gt;
      &lt;nested2&gt;new text&lt;/nested2&gt;
    &lt;/elements&gt;
  &lt;/root&gt;
  </code></pre>
  
  <p>I hope you can see and understand my problem. I am looking for a proper solution, any guidance would be wonderful.</p>
  
  <p>To clarify the problem, using the current solution that I have, nested elements are not merged.</p>