passing xml stream to xalan

S

Sandy

Hi,

I have some data stored in my internal data structure. I am writing this
data in an xml file and invoking xalan on this file to perform some
transformation.
After the transformation I want to put the data in Database so i m reading
the xml produced by xalan.

But as there are lot of IO operations so the application is very slow.
Is there any way to pass the xml stream (using the string buffer that I am
writing into XML file) directly to xalan

can somebody give me an example code.

Thanks in advance
 
N

Nigel Whitaker

Hello Sandy,

Answering in reverse order:
But as there are lot of IO operations so the application is very slow.
Is there any way to pass the xml stream (using the string buffer that I am
writing into XML file) directly to xalan

From the string buffer construct a Reader and use
this in the StreamSource constructor.

StringBuffer sb= ....;
Transformer t= TransformerFactory.newInstance().newTransformer();
t.transform(new StreamSource(new StringReader(sb.toString()), "buffer:sb"),
new StreamResult(new File("output.xml")));

While this avoids disk-io, it does not avoid the parsing/lexical
analysis overhead.
I have some data stored in my internal data structure. I am writing this
data in an xml file and invoking xalan on this file to perform some
transformation.

A more efficient technique could be to generate SAX ContentHandler
events as you traverse your internal data structure. You could
then feed this contentHandler into the SAXSource constructor:

Class DSToXML implements ContentHandler ....;
DSToXML reporter;
t.transform(new SAXSource(reporter), ...);

Hope this gives you a start,

Nigel
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top