我无法为我正在编写的程序提出解决方案。我正在阅读 pom 文件中的礼仪,我将它们保存到字典中。将它们保存到字典后,我想以特定方式输出。如下:
我如何解析 pom 文件的代码:
for dep in depend:
infoList = []
counter += 1
for child in dep.getchildren():
infoList.append(child.tag.split('}')[1])
infoList.append(child.text)
#list where data is being stored
dependencyInfo[infoList[1]].update({infoList[2] : infoList[3],infoList[4] : infoList[5]})
#print statement of all the data
print("""%i Dependency where found in %s's pom file.""" % (counter,projectName))
print(dependencyInfo)
输出是
11 Dependency where found in my-application1's pom file.
defaultdict(<class 'dict'>, {'junit': {'artifactId': 'junit', 'version': '3.8.1'}, 'org.hibernate': {'artifactId': 'ejb3-persistence', 'version': '1.0.1.GA'}, 'javax.sql': {'artifactId': 'jdbc-stdext', 'version': '2.0'}, '
javax.transaction': {'artifactId': 'jta', 'version': '1.0.1B'}, 'mysql': {'artifactId': 'mysql-connector-java', 'version': '5.1.14'}, 'slf4j-api': {'groupId': 'org.slf4j', 'type': 'jar'}, 'org.slf4j': {'artifactId': 'slf4j
-simple', 'version': '1.6.1'}})
现在我想按如下方式重新排列数据
groupId = junit
artifactId = junit
version = 3.8.1
.
.
groupId = javax.transaction
artifactId = jta
version = 1.0.1B
月关宝盒
相关分类