Yes, but presumably a StreamResult actually serializes the result, and
the StreamSource reparses its input.

I suspect that using a DOM as the intermediate format rather than a
Stream will be faster; the DOMSource only needs to walk the DOM tree
while the StreamSource needs to reparse the input.

Not sure about which solution will use less memory..probably the stream
approach. A DOM representation certainly will take up more memory than
the serialized version, and I don't think the StreamResult will need
much working memory. I'm not sure how much memory the StreamSource will
use when reparsing the input, but still probably less than the DOM.

Ain't it nice to have choices :-)

On Thu, 2003-04-10 at 12:08, Foxy Shadis wrote:
> Result result = new StreamResult(new StringWriter());
> ...
> Source source = new StreamSource(new 
> StringReader(result.getWriter().toString()));
> --
> Let me know if anything along those lines helps. I have no idea what kind of 
> buffering StringWriter uses, so you may want to wrap it in a buffered 
> writer.
> 
> My preferred method is this:
> --
> StringWriter result = new StringWriter();
> ...
> transformer.transform(xmlSource, new StreamResult(result));
> ...
> Source source = new StreamSource(new StringReader(result.toString()));
> --
> Which is roughly equivalent but easier for me to work with.
> 
> 
> Swiftpaw Foxyshadis, wildlife artist
> [EMAIL PROTECTED] | http://foxyshadis.dyndns.org/
> 
> 
> 
> 
> >From: Simon Kitching <[EMAIL PROTECTED]>
> >
> >I expect that you could use a DOMResult, then get the root node of the
> >resulting DOM, and wrap a DOMSource around it:
> >
> >DOMResult result = new DOMResult();
> >transformer.transform(source, result);
> >
> >return new DOMSource(result.getNode());
> >
> >
> >On Wed, 2003-04-09 at 22:44, Andrew Welch wrote:
> > > Hi,
> > >
> > > Sorry if this is a faq...
> > >
> > > I have a custom uri resolver that I want to do a transform before 
> >passing the result back to the requesting stylesheet.  How do I go from a 
> >result to a source?  I  can write the result out and then read it back in, 
> >says as a string or bytes, but this seems unecessary... my knowledge of 
> >streams is really lacking :(
> > >
> > > code sample:
> > >
> > >  public Source resolve(String href, String base) throws 
> >TransformerException {
> > >    try {
> > >       URL context = new URL("file:///");
> > >       URL u = new URL(context, href);
> > >
> > >       InputStream is = new FileInputStream(u.toString());
> > >
> > >       TransformerFactory tf = TransformerFactory.newInstance();
> > >       Source xsl = new StreamSource(new 
> >File("C:\\test\\AddElementIdToStylesheet.xsl"));
> > >
> > >       Result result = new StreamResult(???);
> > >       ^^^what type of result do I need here?
> > >
> > >       Transformer transformer = tf.newTransformer(xsl);
> > >       transformer.transform(new StreamSource(is, u.toString()), result);
> > >
> > >       return ????;
> > >       ^^^how do I return the result as a source?
> > >    } catch (Exception ex) {
> > >       System.out.println(ex.toString());
> > >       ex.printStackTrace();
> > >    }
> > >   return null;
> > >  }
> > >
> > > cheers
> > > andrew
> > >
> 
> 
> _________________________________________________________________
> Protect your PC - get McAfee.com VirusScan Online  
> http://clinic.mcafee.com/clinic/ibuy/campaign.asp?cid=3963
> 
> 

Reply via email to