Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2002-03-26
4
Medium Priority
?
171 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 600 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses

886 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