What is the most memory efficient method to parse XML in java?

北慕城南 提交于 2020-02-01 07:22:30

问题


I have memory problems with the webapp responsible from parsing XML event and pushing them to our RabbitMQ bus. This webapp receives XML event in a servlet, we decode it and push it to our bus and then we acknowledge the sender. We are curently using org.xml.sax.helpers.DefaultHandler in java 5, but it seems that Stax (with XMLStreamReader) is much better and still easy to read, but we would need to migrate our code to java6 (see this question on SO). Does it worth it ?

What is the most memory efficient method to parse XML in java ? We are looking for a fast, memory efficient and easy to write/read code. Does this exist ?


回答1:


Event-driven parsers don't build up ASTs and are therefore fast and memory-efficient. The standard for XML would be defined by the SAX standard.

The Xerces implementation claims to be fast.




回答2:


NanoXML is a very small and lightweight XML parser which supports SAX parsing. It is a good alternative to Xerces.




回答3:


Beware of the answers mentioning Sax, as it is at the expense of significantly less usefulness. The most memory efficient sax parsing w/o sacrificing usability is vtd-xml. Here is the proof

Processing XML with Java – A Performance Benchmark http://sdiwc.us/digitlib/journal_paper.php?paper=00000582.pdf



来源:https://stackoverflow.com/questions/7332163/what-is-the-most-memory-efficient-method-to-parse-xml-in-java

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!