java 字符串转xml,在java中将字符串转换为XML输入流

本文档探讨了如何在Java环境中,利用FOP库将接收到的XML字符串转换为PDF文档。主要步骤包括将XML字符串转化为Reader,然后通过StreamSource进行转换操作。Transformer.transform()方法接受一个StreamSource作为输入,从而实现字符串到PDF的转换。
摘要由CSDN通过智能技术生成

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.

解决方案

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

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.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值