• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

StreamSource/StreamResult

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello everyone,
I am doing a XSLT program using Trax API.
My requirement is
StreamSource xmlStreamSource = new StreamSource(XML_SOURCE_FILE);
StreamResult result = new StreamResult(new FileOutputStream(OUTPUT_FILE));
Instead of giving the file names in the constructor, I have to give a String object.
Eg, String s = "<1></1>"
String "s" should be the input.
The sameway StreamResult should also send result to String Object.
I couldn't find answer for this. Can anyone help me.
Thank you,
Sachi
 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have the same issue. Guys has anyone done this before?
 
varnika Raman
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Found the answer.

StringWriter stringWriter=new StringWriter();
// Create the result stream for the transform
StreamResult result = new StreamResult(stringWriter);
// Create a Transformer to serialize the document
TransformerFactory tFactory =TransformerFactory.newInstance();
Transformer transformer = tFactory.newTransformer();
// Transform the document to the result stream
transformer.transform(domSource, result);
return stringWriter.toString();
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic