title: Python ElementTree - Inserting a copy of an element
body: <p>I have the following xml code:</p>
  
  <pre><code>&lt;data factor="1" name="ini" value="342" /&gt;
  </code></pre>
  
  <p>I want to copy the same information, but with a different name. i.e., The final output should be:</p>
  
  <pre><code>&lt;data factor="1" name="ini" value="342" /&gt;
  &lt;data factor="1" name="raw_ini" value="342" /&gt;
  </code></pre>
  
  <p>I tried to do the following:</p>
  
  <pre class="lang-py prettyprint-override"><code>model_tag = tree.findall(data_path) #I make sure that data_path is correct.
  len_tags = len(model_tag)
  i = 0
  while i &lt; len_tags: 
      tipo_tag = model_tag[i]
      if tipo_tag.attrib['name']=='ini':
          aux_tag = copy.deepcopy(tipo_tag) #I tried also with copy.copy(tipo_tag).
          aux_tag.attrib['name'] = 'raw_ini'
          model_tag.append(aux_tag)
  
  tree.write(dir_output) 
  </code></pre>
  
  <p>If I use "copy.deepcopy" I don't have an extra element. The output is:</p>
  
  <pre><code>&lt;data factor="1" name="ini" value="342" /&gt;
  </code></pre>
  
  <p>If I use "copy.copy", just change the name of the element. The output is:</p>
  
  <pre><code>&lt;data factor="1" name="raw_ini" value="342" /&gt;
  </code></pre>
  
  <p>Any Idea of what am I doing wrong?</p>