title: Reading Maven Pom xml in Python
body: <p>I have a pom file that has the following defined:</p>
  
  <pre><code>&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;4.0.0&lt;/modelVersion&gt;
  &lt;groupId&gt;org.welsh&lt;/groupId&gt;
  &lt;artifactId&gt;my-site&lt;/artifactId&gt;
  &lt;version&gt;1.0.0&lt;/version&gt;
  &lt;packaging&gt;pom&lt;/packaging&gt;
  
  &lt;profiles&gt;
      &lt;profile&gt;
          &lt;build&gt;
              &lt;plugins&gt;
                  &lt;plugin&gt;
                      &lt;groupId&gt;org.welsh.utils&lt;/groupId&gt;
                      &lt;artifactId&gt;site-tool&lt;/artifactId&gt;
                      &lt;version&gt;1.0&lt;/version&gt;
                      &lt;executions&gt;
                          &lt;execution&gt;
                              &lt;configuration&gt;
                                  &lt;mappings&gt;
                                      &lt;property&gt;
                                          &lt;name&gt;homepage&lt;/name&gt;
                                          &lt;value&gt;/content/homepage&lt;/value&gt;
                                      &lt;/property&gt;
                                      &lt;property&gt;
                                          &lt;name&gt;assets&lt;/name&gt;
                                          &lt;value&gt;/content/assets&lt;/value&gt;
                                      &lt;/property&gt;
                                  &lt;/mappings&gt;
                              &lt;/configuration&gt;
                          &lt;/execution&gt;
                      &lt;/executions&gt;
                  &lt;/plugin&gt;
              &lt;/plugins&gt;
          &lt;/build&gt;
      &lt;/profile&gt;
  &lt;/profiles&gt;
  &lt;/project&gt;
  </code></pre>
  
  <p>And I am looking to build a dictionary off the <code>name</code> &amp; <code>value</code> elements under <code>property</code> under the <code>mappings</code> element.</p>
  
  <p>So what I'm trying to figure out how to get all possible <code>mappings</code> elements (Incase of multiple build profiles) so I can get all <code>property</code> elements under it and from reading about <a href="http://docs.python.org/2/library/xml.etree.elementtree.html#supported-xpath-syntax" rel="noreferrer">Supported XPath syntax</a> the following should print out all possible text/value elements:</p>
  
  <pre><code>import xml.etree.ElementTree as xml
  
  pomFile = xml.parse('pom.xml')
  root = pomFile.getroot()
  
  for mapping in root.findall('*/mappings'):
      for prop in mapping.findall('.//property'):
          logging.info(prop.find('name').text + " =&gt; " + prop.find('value').text)
  </code></pre>
  
  <p>Which is returning nothing. I tried just printing out all the <code>mappings</code> elements and get:</p>
  
  <pre><code>&gt;&gt;&gt; print root.findall('*/mappings')
  []
  </code></pre>
  
  <p>And when I print out the everything from <code>root</code> I get:</p>
  
  <pre><code>&gt;&gt;&gt; print root.findall('*')
  [&lt;Element '{http://maven.apache.org/POM/4.0.0}modelVersion' at 0x10b38bd50&gt;, &lt;Element '{http://maven.apache.org/POM/4.0.0}groupId' at 0x10b38bd90&gt;, &lt;Element '{http://maven.apache.org/POM/4.0.0}artifactId' at 0x10b38bf10&gt;, &lt;Element '{http://maven.apache.org/POM/4.0.0}version' at 0x10b3900d0&gt;, &lt;Element '{http://maven.apache.org/POM/4.0.0}packaging' at 0x10b390110&gt;, &lt;Element '{http://maven.apache.org/POM/4.0.0}name' at 0x10b390150&gt;, &lt;Element '{http://maven.apache.org/POM/4.0.0}properties' at 0x10b390190&gt;, &lt;Element '{http://maven.apache.org/POM/4.0.0}build' at 0x10b390310&gt;, &lt;Element '{http://maven.apache.org/POM/4.0.0}profiles' at 0x10b390390&gt;]
  </code></pre>
  
  <p>Which made me try to print:</p>
  
  <pre><code>&gt;&gt;&gt; print root.findall('*/{http://maven.apache.org/POM/4.0.0}mappings')
  []
  </code></pre>
  
  <p>But that's not working either.</p>
  
  <p>Any suggestions would be great.</p>
  
  <p>Thanks,</p>