Is there a way to build a StAX filter chain?

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-20 02:35:18

问题


Making custom transformations for different event types with StAX using EventFilter and StreamFilter I feel being forced into a procedural implementation - extract these events and process them, filter those events and process them, than put all the results back together and return.

SAX seems to have a really nice feature there - chainable filters based on XMLFilters.
I would prefer to keep my implementation StAX-based, but to somehow incorporate or emulate the chainable filters from SAX.

Can this be done with a reasonable effort and how? Is there an implementation already that I have missed?

Due to project limitations I have to stick to the JDK, so please do not suggest using a different library as an answer, but feel free to suggest one in the comments - I'd love to know what`s out there.


回答1:


Take a look at EventReaderDelegate and StreamReaderDelegate. These classes will allow you to wrap a parent event or stream reader so that you can interpose whatever logic you'd like.




回答2:


While you can use delegates, I think one of very few areas where SAX has edge over Stax is ability to construct efficients modular pipelines. Stax is more optimal for recursive-descent approaches, as well as partial data binding (can traverse stream; hand chunks to JAXB, continue, very simple, powerful).



来源:https://stackoverflow.com/questions/5566836/is-there-a-way-to-build-a-stax-filter-chain

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