Help with SAXSource and javax.xml.transform.Transformer

A

Andreas

Hi!

I fail to catch events when transforming xml.
I have some code that successfully transforms an xml

... code ...
// Setup XSL transformer
TransformerFactory tFactory = TransformerFactory.newInstance();
Transformer transformer = tFactory.newTransformer(xslStreamSource);

// Setup XML result
ByteArrayOutputStream baos = new ByteArrayOutputStream();
BufferedOutputStream bos = new BufferedOutputStream(baos);
StreamResult transformResult = new StreamResult(bos);

// Do the transform
StreamSource ss = new StreamSource(source);
transformer.transform(ss, transformResult);
... end code ...

Now I need this code to perform some "side effects" when parsing the
original xml. I know it is possible to catch events in a ContentHandler
when parsing xml with XMLReader. I tried this with the following code.

... code ...
// Perform Sideeffects
InputSource is = new InputSource(source);
MyContentHandler mch = new MyContentHandler();
XMLReader reader = XMLReaderFactory.createXMLReader();
reader.setContentHandler(sch);
reader.parse(is);
... end code ...

Ok, so know I know that XMLReader.parse will fire events. Why can't I
use this reader with a SAXSource to catch these events when doing the
transform?

Something like:

... code ...
SAXSource ss = new SAXSource(reader, is);
transformer.transform(ss, transformResult);
... end code ...

Unfortunately this code doesn't produce any events

Any solution for this problem?

/Andreas
 
R

Raymond DeCampo

Andreas said:
Something like:

... code ...
SAXSource ss = new SAXSource(reader, is);
transformer.transform(ss, transformResult);
... end code ...

Unfortunately this code doesn't produce any events

Any solution for this problem?

Perhaps if you posted a short, self-contained code example (SSCCE) it
would be easier to help you.

Ray
 

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,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top