parsing large xml file with Python - etree.parse error

后端 未结 2 1033
长情又很酷
长情又很酷 2021-02-20 14:15

Trying to parse the following Python file using the lxml.etree.iterparse function.

\"sampleoutput.xml\"


  Item 1
         


        
2条回答
  •  礼貌的吻别
    2021-02-20 14:31

    The problem is that XML isn't well-formed if it doesn't have exactly one top-level tag. You can fix your sample by wrapping the entire document in tags. You also need the tags to match the query that you're using (description).

    The following document produces correct results with your existing code:

    
      
        Item 1
        Description 1
      
      
        Item 2
        Description 2
      
    
    

提交回复
热议问题