1

Hi all lets assume a sample POM.xml file ,

 <?xml version="1.0" encoding="UTF-8" standalone="no"?>
<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">
<modelVersion>4.0.0</modelVersion>
<packaging>pom</packaging>
<groupId>com.xyz.app</groupId>
<artifactId>com.xyz.app</artifactId>
<version>1.0.55-SNAPSHOT</version>
<dependencies>
    <!-- Compile Dependencies -->
    <dependency>
        <groupId>com.xyz.app</groupId>
        <artifactId>com.xyz.app.random1</artifactId>
        <version>1.0.2-SNAPSHOT</version>
        <scope>compile</scope>
    </dependency>
    <dependency>
        <groupId>com.xyz.app</groupId>
        <artifactId>com.xyz.app.random2</artifactId>
        <version>1.0.7-SNAPSHOT</version>
        <scope>compile</scope>
    </dependency>
    <dependency>
        <groupId>com.xyz.app</groupId>
        <artifactId>com.xyz.random3</artifactId>
        <version>1.0.2-SNAPSHOT</version>
        <scope>compile</scope>
    </dependency>
    <dependency>
        <groupId>com.xyz.app</groupId>
        <artifactId>com.xyz.app.random4</artifactId>
        <version>1.0.7-SNAPSHOT</version>
        <scope>compile</scope>
    </dependency>
</dependencies>

`

Now i want to update the version of the dependencies to the latest one . I have the latest depndencies in a dictionary where the key is the dependencies and the values is the latest version .

Now i am trying to access each dependency element using the following code

root = etree.parse("C:\Temp\python workspace\pom.xml")
root = etree.tostring(root)
root = etree.XML(root)
for parent in root.xpath('//dependency'):
  children = parent.getchildren()
  for child in children:
      print child.text

But i'am not getting any output , could some one point out what i'am doing wrong here ?

Learner
  • 177
  • 1
  • 2
  • 16
  • 3
    You're not getting any output due to the same reason explained here: http://stackoverflow.com/questions/31177707/parsing-xml-to-get-element-value-using-lxml/31178720#31178720 – har07 Nov 07 '15 at 08:03
  • Thank you :@har07 it worked :) – Learner Nov 07 '15 at 08:17

0 Answers0