Troubles while parsing with python very large xml file

后端 未结 3 1594
醉酒成梦
醉酒成梦 2021-01-15 05:55

I have a large xml file (about 84MB) which is in this form:


    ...
    ....
    ...
         


        
3条回答
  •  感动是毒
    2021-01-15 06:04

    Try with lxml which is more easy to use.

    #!/usr/bin/env python
    from lxml import etree
    
    with open("myfile.xml") as fp:
        tree = etree.parse(fp)
        root = tree.getroot()
    
        print root.tag
    
        for book in root:
            print book.text
    

提交回复
热议问题