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
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