Python xml 转 dict 转 json

浅浅的花香味﹌ 2022-09-12 05:51 370阅读 0赞
  1. import json
  2. import xmltodict
  3. d = xmltodict.parse("""
  4. <mydocument has="an attribute">
  5. <and>
  6. <many>elements</many>
  7. <many>more elements</many>
  8. </and>
  9. <plus a="complex">
  10. element as well
  11. </plus>
  12. </mydocument>
  13. """)
  14. print(json.dumps(d, indent=4))
  15. xml_res = xmltodict.unparse(d, pretty=True)
  16. print(xml_res)

发表评论

表情:
评论列表 (有 0 条评论,370人围观)

还没有评论,来说两句吧...

相关阅读