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 "Fitzharris, Walter M. (LNG-DAY)" <Wa...@lexisnexis.com> on 2003/10/08 17:13:20 UTC

2 SAX filter chain questions

Does anyone know:

1. How to use a custom entity resolver with a chain of sax filters?  In
desperation, I have tried to set my custom resolver for all filters in the
chain, but it doesn't get called when the DTD is encountered in the XML doc.
If I use just the reader alone, it calls my custom resolver.

2. Any answers to my original mail repeated below.

The stack trace follows, with edits by me in [WMF:] :

Now setting up SAX filter chain 
now constructing catalog [WMF: This is the entity resolver object] ...
Filter chain setup took 2 secs
Now running SAX filter chain on SJC-09021.xml
java.io.FileNotFoundException: X:[WMF: path removed by me for
security]...dtd (The system cannot find the file specified)
	at java.io.FileInputStream.open(Native Method)
	at java.io.FileInputStream.<init>(FileInputStream.java:103)
	at java.io.FileInputStream.<init>(FileInputStream.java:66)
	at
sun.net.www.protocol.file.FileURLConnection.connect(FileURLConnection.java:6
9)
	at
sun.net.www.protocol.file.FileURLConnection.getInputStream(FileURLConnection
.java:156)
	at java.net.URL.openStream(URL.java:960)
	at org.apache.xerces.impl.XMLEntityManager.startEntity(Unknown
Source)
	at org.apache.xerces.impl.XMLEntityManager.startDTDEntity(Unknown
Source)
	at org.apache.xerces.impl.XMLDTDScannerImpl.setInputSource(Unknown
Source)
	at
org.apache.xerces.impl.XMLDocumentScannerImpl$DTDDispatcher.dispatch(Unknown
Source)
	at
org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown
Source)
	at org.apache.xerces.parsers.DTDConfiguration.parse(Unknown Source)
	at org.apache.xerces.parsers.DTDConfiguration.parse(Unknown Source)
	at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
	at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
	at org.xml.sax.helpers.XMLFilterImpl.parse(XMLFilterImpl.java:371)
	at org.xml.sax.helpers.XMLFilterImpl.parse(XMLFilterImpl.java:371)
	at org.xml.sax.helpers.XMLFilterImpl.parse(XMLFilterImpl.java:371)
	at org.xml.sax.helpers.XMLFilterImpl.parse(XMLFilterImpl.java:371)
	at org.xml.sax.helpers.XMLFilterImpl.parse(XMLFilterImpl.java:371)
	at
org.apache.xalan.transformer.TrAXFilter.parse(TrAXFilter.java:134)
	at
org.apache.xalan.transformer.TrAXFilter.parse(TrAXFilter.java:134)
	at
org.apache.xalan.transformer.TrAXFilter.parse(TrAXFilter.java:134)
	at
org.apache.xalan.transformer.TrAXFilter.parse(TrAXFilter.java:134)
	at
com.lxnx.fab.ce.xeldm.infra.FormatterSAXFilterMain.main(FormatterSAXFilterMa
in.java:149)
Exception in thread "main" 

Walt Fitzharris
Lexis Nexis
937-865-6800 X54641

>  -----Original Message-----
> From: 	Fitzharris, Walter M. (LNG-DAY)  
> Sent:	Friday, June 20, 2003 10:30 AM
> To:	'xalan-j-users@xml.apache.org'
> Cc:	'brett@oreilly.com'
> Subject:	xmlfilters with parameters
> 
> What happens if you want to use a chain of filters, but you want to pass a
> parameter to one of the stylesheets?
> 
> 1) Here's some code that works, but my question is: why doesn't it need to
> recurse a la the xml filter example?
> Notice that in this code, the reader, not the last filter in the chain,
> calls parse().  I really didn't understand why the last filter in the
> chain called parse() anyway (see xmlfilter example in xalan
> release)...it's non-intuitive for me...it would seem that if they were
> truly chained, the front guy in the chain would read (parse) and the last
> guy in the chain would write...like the old "telephone game".
> 
> 2) Another question: does this code retain the benefits of being able to
> process huge XML docs, or has it been tainted by the rewiring to add the
> transformer con parameter?
> 
>       // Create an XMLFilter for each stylesheet
>       XMLFilter xmlFilter1 = saxTFactory.newXMLFilter(new
> StreamSource("filter1.xsl"));
>       XMLFilter xmlFilter2 = saxTFactory.newXMLFilter(new
> StreamSource("filter2.xsl"));
>       XMLFilter xmlFilter3 = saxTFactory.newXMLFilter(new
> StreamSource("filter3.xsl"));
> 
>       // Get a transformer for this xsl, so can set the parm for it.
>       TransformerHandler tHandler = saxTFactory.newTransformerHandler(new
> StreamSource("filter4p.xsl"));
>       Transformer t = tHandler.getTransformer();
>       t.setParameter("fParam", "FormatterFunctions");
>       
>       // Create a serializer for the final output of the chain of xsls.
>       Serializer serializer = SerializerFactory.getSerializer
>  
> (OutputPropertiesFactory.getDefaultMethodProperties("xml"));        
>       serializer.setOutputStream(System.out);
> 
>       // Link up the chain
> 	XMLReader reader = XMLReaderFactory.createXMLReader();
>       xmlFilter1.setParent(reader);
>       xmlFilter2.setParent(xmlFilter1);
>       xmlFilter3.setParent(xmlFilter2);
>       xmlFilter3.setContentHandler(tHandler);
>       tHandler.setResult(new SAXResult(serializer.asContentHandler()));
>       
>       // Now go!
>       reader.parse(new InputSource("input.xml"));
> 
> 
> Walt Fitzharris
> Lexis Nexis
> 937-865-6800 X54641
>