Solved

e.g. of dynamically creating XML and translating with XSL

Posted on 2002-03-26
4
152 Views
Last Modified: 2013-11-23
Hi,

In a servlet I currently create an XML file, translate it using XSL and output the result back to the browser.

Rather than create a physical file I want to just stream it.

I need an example of doing this to use as a guide for my app.  I am using JAXP, so please also do this for your example.

Thanks,

Matt
0
Comment
Question by:MatthewL
  • 2
4 Comments
 
LVL 2

Accepted Solution

by:
userquin earned 200 total points
ID: 6899680
Hi:

This example works fine using XALAN 2.2 instead JAXP:

Transformer transformer =
       TransformerFactory.newInstance().newTransformer(
         new SAXSource(XMLReaderFactory.createXMLReader(), new InputSource(new ByteArrayInputStream(xsl_data))));
     transformer.transform(
       new SAXSource(XMLReaderFactory.createXMLReader(), new InputSource(new ByteArrayInputStream(xml_data))),
       new StreamResult(out));

You can create your XML on the fly, use getBytes method from it string format.

"out" can be a ByteArrayOutputStream. Then put content-type to your JSP via response.setContentType and then write out.getBytes() to the user.

Bye.

J.
0
 
LVL 9

Expert Comment

by:Venci75
ID: 7923687
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:
PAQ'd and pts removed
Please leave any comments here within the next seven days.
 
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
 
Venci75
EE Cleanup Volunteer
0
 
LVL 1

Author Comment

by:MatthewL
ID: 7925924
Hi,

I had left it open, hoping that an answer with the JAXP parser would come.  I do appreciate userguin's answer though so points should go there.

Thanks,

Matt
0
 
LVL 2

Expert Comment

by:userquin
ID: 7942687
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now