import xml.etree.ElementTree
root=xml.etree.ElementTree.parse('testXml.xml')
book=root.findall('person')
for book_list in book:
    for note in book_list:
        print(note.tag+':'+note.text)

 


f = open('testJson.json','a',encoding="utf-8")
for each in root1.getiterator("person"):
tempDict = each.attrib
for childNode in each.getchildren(): # 利用getchildren方法得到子节点
tempDict[childNode.tag] = childNode.text # tag获取节点名,text获取节点值
tempJson = json.dumps(tempDict,ensure_ascii=False)
print(tempJson)
f.write(tempJson + '\n')
f.close()

xml格式转成json格式,使用Python

 

相关文章:

  • 2022-12-23
  • 2022-01-27
  • 2022-12-23
  • 2022-12-23
  • 2021-04-21
  • 2021-08-03
  • 2021-12-06
猜你喜欢
  • 2021-08-05
  • 2022-12-23
  • 2021-11-22
  • 2021-08-06
  • 2022-12-23
  • 2021-04-18
相关资源
相似解决方案