简体   繁体   English

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

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

I have memory problems with the webapp responsible from parsing XML event and pushing them to our RabbitMQ bus. 我的webapp遇到内存问题,原因是解析XML事件并将其推送到RabbitMQ总线。 This webapp receives XML event in a servlet, we decode it and push it to our bus and then we acknowledge the sender. 此webapp在servlet中接收XML事件,我们对其进行解码并将其推送到我们的总线,然后我们确认发送者。 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). 我们目前正在Java 5中使用org.xml.sax.helpers.DefaultHandler ,但是Stax (使用XMLStreamReader)似乎要好得多,并且仍然易于阅读,但是我们需要将代码迁移到java6(请参见此问题) 。所以)。 Does it worth it ? 值得吗?

What is the most memory efficient method to parse XML in java ? 在Java中解析XML最有效的内存方法是什么? 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. 事件驱动的解析器不会建立AST,因此速度快且内存效率高。 The standard for XML would be defined by the SAX standard . XML的标准将由SAX标准定义。

The Xerces implementation claims to be fast. Xerces实现声称速度很快。

NanoXML is a very small and lightweight XML parser which supports SAX parsing. NanoXML是一个非常小巧轻便的XML解析器,它支持SAX解析。 It is a good alternative to Xerces. 它是Xerces的一个很好的选择。

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 . 不牺牲可用性的内存效率最高的sax解析是vtd-xml Here is the proof 这是证明

Processing XML with Java – A Performance Benchmark http://sdiwc.us/digitlib/journal_paper.php?paper=00000582.pdf 使用Java处理XML –性能基准http://sdiwc.us/digitlib/journal_paper.php?paper=00000582.pdf

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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