You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by Jason Pell <ja...@gmail.com> on 2010/12/10 23:23:42 UTC
Chain a xmlstreamwriter to a xmlstreamreader
Hi,
Not strictly cxf but I was hoping for a solution to this to use in cxf interceptors so thought I would ask.
I know it's possible to chain a reader to a writer. But what I want to do is take the xmlstreamreader opened by the staxininterceptor and run a xsl transformation that would result in a outgoing xmlstreamwriter. I want to chain this writer to a new reader to replace the original reader so none of the interceptors after are the wiser?
I have done some searching but stax is new for me and not sure if this is an easy ask or a pain or impossible?
Any pointers or ideas will be gratefully received
Sent from my iPhone
Re: Chain a xmlstreamwriter to a xmlstreamreader
Posted by Daniel Kulp <dk...@apache.org>.
On Friday 10 December 2010 5:23:42 pm Jason Pell wrote:
> Hi,
> Not strictly cxf but I was hoping for a solution to this to use in cxf
> interceptors so thought I would ask.
>
> I know it's possible to chain a reader to a writer. But what I want to do
> is take the xmlstreamreader opened by the staxininterceptor and run a xsl
> transformation that would result in a outgoing xmlstreamwriter. I want to
> chain this writer to a new reader to replace the original reader so none
> of the interceptors after are the wiser?
The only way I can really think to do this is by transforming the
XMLStreamReader into a DOM and wrappering the DOM with a new XMLStreamReader.
(or use a temporary file and input/output streams if very large). There are
a bunch of utilities in our org.apache.cxf.staxutils package that can help.
If you have the XMLStreamReader, you can do:
Source source = new StaxSource(reader);
to create a javax.xml.transform.Source object to feed into the XSLT.
Transform to a DOMSource or StreamSource. Grab the DOM or Stream and call
the StaxUtils.createXMLStreamReader(...) with it and reset the content in the
message.
Hope that helps!
Dan
>
> I have done some searching but stax is new for me and not sure if this is
> an easy ask or a pain or impossible?
>
> Any pointers or ideas will be gratefully received
>
> Sent from my iPhone
--
Daniel Kulp
dkulp@apache.org
http://dankulp.com/blog