简体   繁体   中英

Which one to choose between SAX and STAX to read large xml files

I have a requirement where I can have 100 mb or bigger xml file having list of companies for which I need to add each company into a table from that xml file.

I was thinking of using SAX parser however I was also thinking of using stax parser. Can someone pls help me know which one should I use.

thx

StAX has a much more easier to use API, so I think it is a better choice. SAX has a low-level push API, which is not very nice to use (eg working with char[] ). StAX has a much nicer to use pull API.

Another potential advantage: using StAX you don't have read the whole document, you may stop if you have what you needed.

There is a nice - though quite old - comparison of the Java XML parsing APIs found here .

Using StAX will allow you to minimize the amount of data kept in memory to only the most recently parsed record. Once you insert that record into your table, you no longer need to keep it in memory.

If you use SAX you would (likely) have to parse the entire xml content into memory before inserting records into your table. While it would be possible to insert as you go (when encountering the closing element for a record), that is more complicated with SAX than StAX.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM