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 Slinkster <js...@entropy-labs.com> on 2002/09/26 20:25:07 UTC
Problem getting XALAN SAXResult to recognize lexical handler
I've created a class:
public class SAXWriter extends javax.xml.transform.sax.SAXResult implements org.xml.sax.ContentHandler, org.xml.sax.ext.LexicalHandler {
which does this:
super.setHandler(this);
super.setLexicalHandler(this);
in its constructor.
It receives all the ContentHandler events, but none of the LexicalHandler events when I use the following code:
SAXWriter out = new SAXWriter(new File(destination, name.substring(0, name.length()-3)));
transformer.transform(appDef, out);
Strangely, I get both sets of events when I use the following code:
FileWriter o1 = new FileWriter(new File(tmpDir, name.substring(0, name.length()-3)+"Q"));
transformer.transform(appDef, new StreamResult(o1));
XMLReader reader = SAXParserFactory.newInstance().newSAXParser().getXMLReader();
SAXWriter out = new SAXWriter(new File(destination, name.substring(0, name.length()-3)));
reader.setContentHandler(out);
reader.setProperty("http://xml.org/sax/properties/lexical-handler", out);
reader.parse(new InputSource(new FileReader(new File(tmpDir, name.substring(0, name.length()-3)+"Q"))));
Is there a cleaner way of doing this? (I also don't like the fact that it looks up the DTD over the net when I do this, but I'm sure there's a XMLReader setting that fixes this. I'm more interested in learning the proper way to implement SAXResult classes).
appDef is a StreamSource that is repeatedly used.
My classpath has all of the jars from xalan-j_2_4_0 and they do not appear to be superceded by anything else in the classpath.
Thanks for your help,
JWS
Re: Problem getting XALAN SAXResult to recognize lexical handler
Posted by Joseph Kesselman <ke...@us.ibm.com>.
You're trying to use the Default Identity Transformation.
I honestly don't know whether that code (which is NOT Xalan's main-line
path, and which hasn't been pounded on as extensively) passes through all
the lexical events. It's known to lose some details; see bugzilla entry
5779.
(I"m not defending the result you say you're seeing; I'm just not
surprised by it.)
If you just want to parse, using the JAXP APIs rather than the TrAX APIs
will generally be more efficient and less likely to raise this sort of
question.
______________________________________
Joe Kesselman / IBM Research