You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-users@xalan.apache.org by Andrew Welch <AW...@piper-group.com> on 2003/07/01 15:36:54 UTC

using xml filters after transformation

Hi all,

I have an xml filter chain culminating in a transform.  I have some XML filters that I want to use on the result of the transform, but I don’t want to write out the result of the transform and then read it back in for the last few xml filters... is there a way of adding them to the chain?


Basic code:

stf = (javax.xml.transform.sax.SAXTransformerFactory)tf.newInstance();

TransformerHandler th = stf.newTransformerHandler(...);
Transformer transformer = th.getTransformer();

AnXMLfilter filter = new AnXMLfilter();
            filter.setParent(XMLReaderFactory.createXMLReader("org.apache.crimson.parser.XMLReaderImpl"));
            
filter.setContentHandler(th);

th.setResult(result);
            
filter.parse(new InputSource(...));
            


I want to add say 'filter2' to run over the result of the transform, what is the best way of doing this?


cheers
andrew

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.491 / Virus Database: 290 - Release Date: 18/06/2003
 

Re: using xml filters after transformation

Posted by Joseph Kesselman <ke...@us.ibm.com>.



If by "xml filter" you mean SAX's XMLFilter interface...

The simplest approach to writing SAX filters is to just have a single
object implement ContentHandler and pass the filtered data to another
ContentHandler. Our SAXResult is set up to wrap itself around an
sax.ContentHandler, so it can happily talk to a filter of this type.

Unfortunately, sax.XMLFilter is intended to wrap itself around a
sax.XMLReader and to actually be able to control the operation via its
parse() method... so the metaphors collide.

Simplest workaround I can see right now would be to implement a
sax.XMLReader that wraps around a Transformer, and pass that to the
XMLFilter. That feels like it ought to be straightforward, and *might*
actually be something we'd want to ship as a standard Xalan utility
class...

______________________________________
Joe Kesselman, IBM Next-Generation Web Technologies: XML, XSL and more.
"The world changed profoundly and unpredictably the day Tim Berners Lee
got bitten by a radioactive spider." -- Rafe Culpin, in r.m.filk