I modified pom.xml with python. Etree doesn't seem to be documented very well. It took a while to get everything working, but it seems to be working now.
As you can see in the following snippet, Maven uses the namespace http://maven.apache.org/POM/4.0.0 . The xmlns attribute in the root node directory defines the default namespace. The xmlns:xsi attribute also defines a namespace, but it is used only for xsi:schemaLocation .
<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">
To use tags of type profile in methods such as find , you must also specify a namespace. For example, you can write the following to find all profile -tags.
import xml.etree as xml pom = xml.parse('pom.xml') for profile in pom.findall('//{http://maven.apache.org/POM/4.0.0}profile'): print(repr(profile))
Another important thing is // here. Using your xml aboive file, */ will have the same result for this example. But for other tags, such as mappings , it would not work . Since * represents only one level, */child can be expanded to parent/tag or xyz/tag , but not to xyz/parent/tag .
I believe these are the main problems in your code above. You must use // insted from */ to allow any subitems instead of direct children. And you must specify a namespace. Using this, you can do something similar to find all the mappings:
pom = xml.parse('pom.xml') map = {} for mapping in pom.findall('//{http://maven.apache.org/POM/4.0.0}mappings' '/{http://maven.apache.org/POM/4.0.0}property'): name = mapping.find('{http://maven.apache.org/POM/4.0.0}name').text value = mapping.find('{http://maven.apache.org/POM/4.0.0}value').text map[name] = value
But specifying namespaces like the ones above is not very good. You can define a namespace map and pass it as the second argument to find and findall :
# ... nsmap = {'m': 'http://maven.apache.org/POM/4.0.0'} for mapping in pom.findall('//m:mappings/m:property', nsmap): name = mapping.find('m:name', nsmap).text value = mapping.find('m:value', nsmap).text map[name] = value