You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-users@xalan.apache.org by Gary L Peskin <ga...@firstech.com> on 2002/07/02 00:03:38 UTC

RE: Xalan To StringBuffer

Sorry for the delay.  It's been a hectic day (so far)!  You'll get
faster results if you send messages like this to the Xalan-J-Users list.

I'd do it like this:

 java.io.ByteArrayOutputStream baos = new
java.io.ByteArrayOutputStream();
 javax.xml.transform.Result result = new
javax.xml.transform.stream.StreamResult(baos);
 StringBuffer sb = new StringBuffer(baos.toString());
 baos.close();

HTH,
Gary

> -----Original Message-----
> From: Scott Purcell [mailto:spurcell@vertisinc.com] 
> Sent: Monday, July 01, 2002 9:01 AM
> To: garyp@firstech.com
> Subject: Xalan To StringBuffer
> 
> 
> Hello Gary,
> I hate to bother you, but I am running into a issue that I 
> can't seem to find an answer for. I am working with Xalan and 
> I have the need to transform a document using xalan (web 
> based app) but instead of putting the result to the screen, I 
> need to somehow put the result into a stringbuffer. Is this 
> even remotely doable? I have the following code that works to 
> the screen, but I cannot seem to get it turned into a StringBuffer.
> 
> (Below out is the PrintWriter out object.);
> 
> 
>  public StringBuffer transformJob(String xmlpath, String xslpath)
>     {
> 
>         StringBuffer sb = new StringBuffer();
>         File xmlfile= new File(xmlpath);
>         File xslfile = new File(xslpath);
>                                                     
>         try {
>             javax.xml.transform.Source xmlSource = new 
> javax.xml.transform.stream.StreamSource(xmlfile);
>             javax.xml.transform.Source xsltSource = new 
> javax.xml.transform.stream.StreamSource(xslfile);
>             
>             javax.xml.transform.Result result = new 
> javax.xml.transform.stream.StreamResult(out);
>             
>             javax.xml.transform.TransformerFactory transFact 
> = javax.xml.transform.TransformerFactory.newInstance();
>             javax.xml.transform.Transformer trans = 
> transFact.newTransformer(xsltSource);
>             trans.setParameter("bgcolor", bg);
>             trans.setParameter("fgcolor", fg);
>             
>             trans.transform(xmlSource, result);
>         } catch (javax.xml.transform.TransformerException te) {
>             te.printStackTrace();
>             
>         }
> 
> 
> 
> 
> Scott Purcell | Developer | VERTIS | 555 Washington Ave. 4th 
> Floor | St. Louis, MO 63101 | T 314.588.0720 | F 314.588.0735 
> | spurcell@vertisinc.com | http://www.vertisinc.com
> 
> Vertis is a global powerhouse for integrated marketing and 
> advertising solutions that seamlessly combine advertising, 
> direct marketing, media, imaging and progressive technology. 
> Vertis' products and services include: consumer and media 
> research, media planning and placement, creative services, 
> digital media production, targetable insert programs, fully 
> integrated direct marketing programs, circulation-building 
> newspaper products and eMarketing.
> 
> 
>