天天看点

java xml 内存,在Java中解析XML最有效的内存方法是什么?

java xml 内存,在Java中解析XML最有效的内存方法是什么?

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 ?

解决方案

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.