-
Notifications
You must be signed in to change notification settings - Fork 1
/
parsexml.py
56 lines (36 loc) · 1.47 KB
/
parsexml.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
from xml.etree import ElementTree
def parse_xml(filename):
dep_list = []
POM_FILE= filename
namespaces = {'xmlns' : 'http://maven.apache.org/POM/4.0.0'}
tree = ElementTree.parse(POM_FILE)
root = tree.getroot()
deps = root.findall(".//xmlns:dependency", namespaces=namespaces)
for d in deps:
groupId = d.find("xmlns:groupId", namespaces=namespaces)
if groupId is None:
groupId_text = ""
else:
groupId_text = groupId.text
artifactId = d.find("xmlns:artifactId", namespaces=namespaces)
if artifactId is None:
artifactId_text = ""
else:
artifactId_text = artifactId.text
version = d.find("xmlns:version", namespaces=namespaces)
if version is None:
version_text = ""
else:
version_text = version.text
dep_list.append({"groupId": groupId_text,"artifactId": artifactId_text, "version": version_text})
return dep_list
def getGroupId(filename):
namespaces = {'xmlns' : 'http://maven.apache.org/POM/4.0.0'}
tree = ElementTree.parse(filename)
root = tree.getroot()
return root.find("xmlns:groupId", namespaces=namespaces).text
def getArtifactId(filename):
namespaces = {'xmlns' : 'http://maven.apache.org/POM/4.0.0'}
tree = ElementTree.parse(filename)
root = tree.getroot()
return root.find("xmlns:artifactId", namespaces=namespaces).text