Search code examples
javaxmlfiltersaxstax

Is there a way to build a StAX filter chain?


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.


Solution

  • 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.