Python XML Parsing without root

前端 未结 3 886
庸人自扰
庸人自扰 2021-02-14 14:33

I wanted to parse a fairly huge xml-like file which doesn\'t have any root element. The format of the file is:




         


        
3条回答
  •  离开以前
    2021-02-14 15:00

    How about instead of editing the file do something like this

    import xml.etree.ElementTree as ET
    
    with file("xml-file.xml") as f:
        xml_object = ET.fromstringlist(["", f.read(), ""])
    

提交回复
热议问题