在java中将字符串转换为XML输入流 [英] Convert a string to XML input stream in java
问题描述
我正在尝试使用FOP和Java生成PDF文档。
I'm trying to generate a PDF document using FOP and Java.
我收到XML作为字符串而不是文件。
I receive the XML as a string and not as a file.
如何将此XML字符串转换为XML输入流,以便我可以调用xslfoTransformer.transform(source,res);其中source是我的XML字符串作为输入流。
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.
请提供您的建议。
推荐答案
您可能希望将其转换为 Reader
,而不是 InputStream
。使用 StringReader 执行此操作。 StreamSource有一个带有Reader的构造函数,你可以将 StreamSource
传递给Transformer.transform()。
You probably want to convert it to a Reader
, not an InputStream
. Use StringReader to do this. StreamSource has a constructor that takes a Reader, and you can pass that StreamSource
to Transformer.transform().
我说你可能想要 Reader
而不是 InputStream
,因为String包含字符,而不是字节,还有 InputStream
是一个字节流,而 Reader
是一个字符流。
I say you probably want a Reader
rather than an InputStream
because a String holds characters, not bytes, and an InputStream
is a stream of bytes while a Reader
is a stream of characters.
这篇关于在java中将字符串转换为XML输入流的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!