When should I choose SAX over StAX?

爱⌒轻易说出口 提交于 2019-11-26 18:47:53

问题


Streaming xml-parsers like SAX and StAX are faster and more memory efficient than parsers building a tree-structure like DOM-parsers. SAX is a push parser, meaning that it's an instance of the observer pattern (also called listener pattern). SAX was there first, but then came StAX - a pull parser, meaning that it basically works like an iterator.

You can find reasons why to prefer StAX over SAX everywhere, but it usually boils down to: "it's easier to use".

In the Java tutorial on JAXP StAX is vaguely presented as the middle between DOM and SAX: "it's easier than SAX and more efficient than DOM". However, I never found any clues that StAX would be slower or less memory efficient than SAX.

All this made me wonder: are there any reasons to choose SAX instead of StAX?

来源:https://stackoverflow.com/questions/7521803/when-should-i-choose-sax-over-stax

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