I'm trying to generate a PDF document using FOP and Java.
I receive the XML as a string and not as a file.
How can I convert this XML string to an XML input stream so that I can call xslfoTransformer.transform(source, res); where source is my XML string as an Input stream.
Please provide your suggestions.
Use ByteArrayInputStream:
You probably want to convert it to a
Reader
, not anInputStream
. Use StringReader to do this. StreamSource has a constructor that takes a Reader, and you can pass thatStreamSource
to Transformer.transform().I say you probably want a
Reader
rather than anInputStream
because a String holds characters, not bytes, and anInputStream
is a stream of bytes while aReader
is a stream of characters.