Parsing Large XML files w/ Ruby & Nokogiri

后端 未结 5 1566
眼角桃花
眼角桃花 2021-01-02 07:30

I have a large XML file (about 10K rows) I need to parse regularly that is in this format:


    10000         


        
5条回答
  •  北荒
    北荒 (楼主)
    2021-01-02 08:18

    I'd recommend using a SAX parser rather than a DOM parser for a file this large. Nokogiri has a nice SAX parser built in: http://nokogiri.org/Nokogiri/XML/SAX.html

    The SAX way of doing things is nice for large files simply because it doesn't build a giant DOM tree, which in your case is overkill; you can build up your own structures when events fire (for counting nodes, for example).

提交回复
热议问题