How to transform huge xml files in java?

前端 未结 7 1276
失恋的感觉
失恋的感觉 2021-01-12 07:04

As the title says it, I have a huge xml file (GBs)

  
  
     ...    
    ...          


        
7条回答
  •  梦毁少年i
    2021-01-12 07:23

    Since you're talking about GB's, I would rather prioritize the memory usage in the consideration. SAX needs about 2 times of memory as the document big is, while DOM needs it to be at least 5 times. So if your XML file is 1GB big, then DOM would require a minimum of 5GB of free memory. That's not funny anymore. So SAX (or any variant on it, like StAX) is the best option here.

    If you want the most memory efficient approach, look at VTD-XML. It requires only a little more memory than the file big is.

提交回复
热议问题