Should be easy and obvious but I cant find a way - the XMLOutputFactory
accepts anly OutputStream
, Result
or another Writer
to generate a new XMLStreamWriter
.
What I have at hand is an XMLStreamReader
which has no methods for extracting a Result
or an OutputStream
.
If the solution would be easier using the Event API, that would be OK too.
Thank you
You could use a javax.xml.transform.Transformer
to convert a StAXSource
wrapping the reader to a StAXResult
wrapping the writer.
TransformerFactory tf = TransformerFactory.newInstance();
Transformer t = tf.newTransformer();
StAXSource source = new StAXSource(xmlStreamReader);
StAXResult result = new StAXResult(xmlStreamWriter);
t.transform(source, result);
Using the Event API you could also use the folloiwng:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With