kostja
kostja

Reputation: 61568

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.

Upvotes: 3

Views: 1826

Answers (2)

StaxMan
StaxMan

Reputation: 116572

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

Upvotes: 0

kschneid
kschneid

Reputation: 5694

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.

Upvotes: 4

Related Questions