title: Python: Read and write namespaced XML using ElementTree
body: <p>This XML file is named <code>example.xml</code>:</p>
  
  <pre><code>&lt;?xml version="1.0"?&gt;
  &lt;project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"&gt;
  
    &lt;modelVersion&gt;14.0.0&lt;/modelVersion&gt;
    &lt;groupId&gt;.com.foobar.flubber&lt;/groupId&gt;
    &lt;artifactId&gt;uberportalconf&lt;/artifactId&gt;
    &lt;version&gt;13-SNAPSHOT&lt;/version&gt;
    &lt;packaging&gt;pom&lt;/packaging&gt;
    &lt;name&gt;Environment for UberPortalConf&lt;/name&gt;
    &lt;description&gt;This is the description&lt;/description&gt;    
    &lt;properties&gt;
        &lt;birduberportal.version&gt;11&lt;/birduberportal.version&gt;
        &lt;promotiondevice.version&gt;9&lt;/promotiondevice.version&gt;
        &lt;foobarportal.version&gt;6&lt;/foobarportal.version&gt;
        &lt;eventuberdevice.version&gt;2&lt;/eventuberdevice.version&gt;
    &lt;/properties&gt;
    &lt;!-- A lot more here, but as it is irrelevant for the problem I have removed it --&gt;
  &lt;/project&gt;
  </code></pre>
  
  <p>If I load the example.xml file above using ElementTree and print the root node:</p>
  
  <pre><code>&gt;&gt;&gt; from xml.etree import ElementTree
  &gt;&gt;&gt; tree = ElementTree.parse('example.xml')
  &gt;&gt;&gt; print tree.getroot()
  &lt;Element '{http://maven.apache.org/POM/4.0.0}project' at 0x26ee0f0&gt;
  </code></pre>
  
  <p>I see that Element also contains the namespace <code>http://maven.apache.org/POM/4.0.0</code>.</p>
  
  <p><em><strong>How do I:</em></strong></p>
  
  <ol>
  <li>Get the <code>foobarportal.version</code> text, increase it by one and write the XML file back while keeping the namespace the document had when loaded and also not change the overall XML layout.</li>
  <li>Get it to load using any namespace, not just <code>http://maven.apache.org/POM/4.0.0</code>. I still don´t want to strip the namespace, as I want the XML to stay the same except for changing <code>foobarportal.version</code> as in <strong>1</strong> above.</li>
  </ol>
  
  <p>The current way is not aware of XML but fulfills <strong>1</strong> and <strong>2</strong> above:</p>
  
  <ol>
  <li>Grep for <code>&lt;foobarportal.version&gt;(.*)&lt;/foobarportal.version&gt;</code></li>
  <li>Take the contents of the match group and i increase it by one</li>
  <li>Write it back.</li>
  </ol>
  
  <p>It would be nice to have an XML aware solution, as it would be more robust. The XML namespace handling of ElementTree is making it more complicated.</p>