Troubles while parsing with python very large xml file

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

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


    ...
    ....
    ...
         


        
3条回答
  •  一生所求
    2021-01-15 06:14

    There are 2 species of XML parsers (this applies to any language).

    1. DOM parsing (which is what you are using). In this type the whole XML file is read into a memory structures and then accessed by methods.

    2. SAX parsing. This is a parsing algorithm that reads each piece of XML in a step-wise fashion. This technique would allow you to better detect and deal with errors.

    In general DOM is easier than SAX because a lot of the gritty details are dealt with by its native methods.

    SAX is a bit more of a challenge because you have to code methods that the SAX parsing "runs" during is walk of the XML document.

提交回复
热议问题