title: Rename object in lxml
body: <p>Let's assume we have a xml file like this:</p>
  <pre><code>&lt;annotation verified=&quot;yes&quot;&gt;
    &lt;folder&gt;Annotation&lt;/folder&gt;
    &lt;filename&gt;test_file&lt;/filename&gt;
    &lt;path&gt;voc/JPEGImages/test_file&lt;/path&gt;
    &lt;source&gt;
      &lt;database&gt;Unknown&lt;/database&gt;
    &lt;/source&gt;
    &lt;size&gt;
      &lt;width&gt;640&lt;/width&gt;
      &lt;height&gt;480&lt;/height&gt;
      &lt;depth&gt;3&lt;/depth&gt;
    &lt;/size&gt;
    &lt;segmented&gt;0&lt;/segmented&gt;
    &lt;object&gt;
      &lt;name&gt;old_name&lt;/name&gt;
      &lt;pose&gt;Unspecified&lt;/pose&gt;
      &lt;truncated&gt;0&lt;/truncated&gt;
      &lt;difficult&gt;0&lt;/difficult&gt;
      &lt;bndbox&gt;
        &lt;xmin&gt;15&lt;/xmin&gt;
        &lt;ymin&gt;164&lt;/ymin&gt;
        &lt;xmax&gt;206&lt;/xmax&gt;
        &lt;ymax&gt;344&lt;/ymax&gt;
      &lt;/bndbox&gt;
    &lt;/object&gt;
  &lt;/annotation&gt;
  </code></pre>
  <p>Now I want to change the name of all objects in a given xml file.</p>
  <p>I wrote the following function:</p>
  <pre><code>def _rename_objects(tree, path, new_name=&quot;new_name&quot;):
      root = tree.getroot()
      for rank in root.iter('object'):
          rank.text = str(new_name)
      tree.write(path)
  </code></pre>
  <p>What it does is, it places the text to object. How do I replace the value in 'name'? Unfortunately tree elements are not really printable for debugging.</p>
  <pre><code>&lt;Element 'object' at 0x11235d400&gt;
  </code></pre>
  <p>New values after <code>_rename_objects</code> look like this:</p>
  <pre><code>  &lt;segmented&gt;0&lt;/segmented&gt;
    &lt;object&gt;new_name&lt;name&gt;old_name&lt;/name&gt;
      &lt;pose&gt;Unspecified&lt;/pose&gt;
  </code></pre>