Solved

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

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Android studio getdrawable(int) is deprecated 4 46
allswap challenge 6 80
Weekend adv creator 3 14
eclipse apache tomcat admin console 52 73
Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

863 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

30 Experts available now in Live!

Get 1:1 Help Now