Parsing pom.xml for dependencies returns error – Argument 'element' has incorrect type
I am trying to retrieve all the dependencies from a pom.xml file but I ran into this error and cant see to figure it out.
Notes – The pom file is in the directory of the code and ive ran it with different pom files and same outcome.
My code
from lxml import etree from collections import defaultdict root = etree.parse('pom.xml') tree = etree.ElementTree(root) depend = tree.xpath("//*[local-name()='dependency']") dependencyInfo = defaultdict(dict) for dep in depend: infoList = [] for child in dep.getchildren(): infoList.append(child.tag.split('}')[1]) infoList.append(child.text) dependencyInfo[infoList[1]].update({infoList[2] : infoList[3],infoList[4] : infoList[5]}) dependencyInfo
The error
raceback (most recent call last): File "pomToExcel.py", line 7, in <module> tree = etree.ElementTree(root) TypeError: Argument 'element' has incorrect type (expected lxml.etree._Element, got lxml.etree._ElementTree)
Any direction I can take to fix this error would be awesome. Thank you.
The usual boilerplate is:
tree = etree.parse('pom.xml') root = tree.getroot()
and from there:
depend = root.xpath("//*[local-name()='dependency']")
etc. Try it and see if it works.