Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Apr 25th, 2012  |  syntax: None  |  size: 1.15 KB  |  hits: 23  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Python: Read and write namespaced XML using ElementTree
  2. <?xml version="1.0"?>
  3. <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">
  4.  
  5.   <modelVersion>14.0.0</modelVersion>
  6.   <groupId>.com.foobar.flubber</groupId>
  7.   <artifactId>uberportalconf</artifactId>
  8.   <version>13-SNAPSHOT</version>
  9.   <packaging>pom</packaging>
  10.   <name>Environment for UberPortalConf</name>
  11.   <description>This is the description</description>    
  12.   <properties>
  13.       <birduberportal.version>11</birduberportal.version>
  14.       <promotiondevice.version>9</promotiondevice.version>
  15.       <foobarportal.version>6</foobarportal.version>
  16.       <eventuberdevice.version>2</eventuberdevice.version>
  17.   </properties>
  18.   <!-- A lot more here, but as it is irrelevant for the problem I have removed it -->
  19. </project>
  20.        
  21. >>> from xml.etree import ElementTree
  22. >>> tree = ElementTree.parse('example.xml')
  23. >>> print tree.getroot()
  24. <Element '{http://maven.apache.org/POM/4.0.0}project' at 0x26ee0f0>
  25.        
  26. tree.getroot().find('{http://maven.apache.org/POM/4.0.0}project')