Hello,
This is driving me crazy... I need to use XML filter chains with the JAXP
SAX parser as the parent of the entire chain because of the design of my
application.
But, this works inconsistently, sometimes it generates exceptions other
times it just creates a blank output file (with just the <?xml ...?>
header), other times it throws exceptions. Though, when I try different
approaches in experiments, or apply the same chain to my own specialized
XMLReader it all works perfectly.
Here's the smallest example that reproduces the problem:
SAXParserFactory spf = SAXParserFactory.newInstance();
SAXParser sp = spf.newSAXParser();
SAXTransformerFactory stf =
(SAXTransformerFactory)TransformerFactory.newInstance();
XMLFilter xsltFilter = stf.newXMLFilter(new StreamSource(new
File("transform.xsl")));
xsltFilter.setParent(sp.getXMLReader());
InputSource is = new InputSource(new StringReader(
"<hello a=\"b\"><there c=\"d\"/></hello>"
));
SAXSource cif = new SAXSource(xsltFilter, is);
// and send it, via an empty transform, to the output stream
Transformer transformer = stf.newTransformer();
FileOutputStream fos = new FileOutputStream(output);
transformer.transform(cif, new StreamResult(fos));
fos.close();
And for this, I use a simple transform:
<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml"/>
<xsl:template match="/">
<xsl:copy-of select="."/>
</xsl:template>
</xsl:stylesheet>
The generated exception appears below my signature.
Yet, a similar sample of code that doesn't use the identity transform at
the end (ie. the transformer is supplied the stylesheet) works perfectly.
After 5 hours experimenting with this (and even attempting to debug the
JAXP sources) I give up... can you see any errors in my code???, or
is there a bug in the libraries.
(oh, I sooo hope it isn't something really simple :)
I'm using the latest Sun JAX Pack.
Thanks for your help,
-Benjamin Johnston
javax.xml.transform.TransformerException: java.lang.RuntimeException:
java.lang.NullPointerException
at at --------- java.lang.RuntimeException: java.lang.NullPointerException at at org.apache.crimson.parser.Parser2.parse(Parser2.java:305) at at at at --------- java.lang.RuntimeException: java.lang.NullPointerException at at at at org.apache.crimson.parser.Parser2.parse(Parser2.java:305) at at at at Exception in thread "main"
org.apache.xalan.transformer.TransformerIdentityImpl.transform(TransformerI
com.blah blah blah...
org.apache.crimson.parser.Parser2.parseInternal(Parser2.java:524)
org.apache.crimson.parser.XMLReaderImpl.parse(XMLReaderImpl.java:442)
org.apache.xalan.transformer.TrAXFilter.parse(TrAXFilter.java:134)
org.apache.xalan.transformer.TransformerIdentityImpl.transform(TransformerI
com.blah blah blah...
org.apache.xalan.transformer.TransformerImpl.run(TransformerImpl.java:3170)
org.apache.xalan.transformer.TransformerHandlerImpl.endDocument(Transformer
org.apache.crimson.parser.Parser2.parseInternal(Parser2.java:508)
org.apache.crimson.parser.XMLReaderImpl.parse(XMLReaderImpl.java:442)
org.apache.xalan.transformer.TrAXFilter.parse(TrAXFilter.java:134)
org.apache.xalan.transformer.TransformerIdentityImpl.transform(TransformerI
com.blah blah blah...