On 10.10.2007 16:35:13 pat wrote:
> On Wed, 10 Oct 2007 06:54:16 -0700 (PDT), AlliumPorrum wrote
> > Hi!
> > 
> > I'm just learning how to use FOP in a servlet, and all examples and
> > documents I have found show how to use URIResolver for reading the 
> > XML contents from a file in a web server to a Source object. Anyway 
> > in my case I'm not going to do so, I get this XML- document thru a 
> > Java interface as a String. BUT, Transformer.transform()- method 
> > can't take a String as a parameter, it needs a Source object.
> > 
> > So my question is; how in a world can I create a Source object from 
> > a Java String?? I have googled and browsed thru API's for hours now, 
> > and I just can't find the solution. Or have I understood something 
> > completely wrong with this issue...?
> > 
> 
> Hello,
> 
> Look at:
> javax.xml.transform.stream.StreamSource
> java.io.ByteArrayInputStream
> 
> From input String create byte[] to build ByteArrayInputStream instance which
> should be used to build StreamSource instance which has to be used in
> Transformer.transform(...) method ... that's it :-)

Please don't do that! I've seen too many developers who made mistakes
here because they didn't get the String-to-byte conversion right. After
all, this will result in two conversions, once String-to-byte and then
byte-to-String. That's unnecessary.

This is the correct way, if you want to get a JAXP Source object:

String xml = someXMLFromSomewhere;
Source src = new StreamSource(new java.io.StringReader(xml));

> Or upload the source data as InputStream from servlet (look at Servletrequest
> and HttpServletRequest) and follow previous instruction from proper point.
> 
>      Pat


Jeremias Maerki


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to