Solved

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

Posted on 2002-03-26
4
157 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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to parse custom JSON to POJO java 4 73
Spring Framework HTTPSession management 1 34
more than one jdk and one jre 1 41
xampp tool 12 49
For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
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…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

772 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