I have tried running numerous Xalan examples involving SAX ContenHandlers and 
Transformations from JSP pages. In all cases I get the same result: no 
exceptions are throws, but the output that was supposed to be sent from the 
Content Handler is never sent to the brwoser. Following is sample code that 
failed. Any insights would be greatly appreciated, as I am at my wits end. 
Also, I am not subscribed to the email list. Please tell me how to subscribe.

Thanks,
Rechell Schwartz

 TransformerFactory tfactory = TransformerFactory.newInstance();
      SAXTransformerFactory stfactory = ((SAXTransformerFactory) tfactory);
      
      
      TransformerHandler handler  = stfactory.newTransformerHandler(new 
StreamSource(stylesheet1));

      // Set the result handling to be a serialization to System.out.
      Result result = new SAXResult(new MyHandler(out));
      handler.setResult(result);
      
     
      XMLReader reader=null;

      // Use JAXP1.1 ( if possible )
      try {
          javax.xml.parsers.SAXParserFactory factory=
              javax.xml.parsers.SAXParserFactory.newInstance();
          factory.setNamespaceAware( true );
          javax.xml.parsers.SAXParser jaxpParser=
              factory.newSAXParser();
          reader=jaxpParser.getXMLReader();
          
      } catch( javax.xml.parsers.ParserConfigurationException ex ) {
          throw new org.xml.sax.SAXException( ex );
      } catch( javax.xml.parsers.FactoryConfigurationError ex1 ) {
          throw new org.xml.sax.SAXException( ex1.toString() );
      } catch( NoSuchMethodError ex2 ) {
      }
      if( reader==null ) reader = XMLReaderFactory.createXMLReader();
      reader.setContentHandler(handler);
      
      // It's a good idea for the parser to send lexical events.
      // The TransformerHandler is also a LexicalHandler.
      reader.setProperty("http://xml.org/sax/properties/lexical-handler";, 
handler);
      
      // Parse the source XML, and send the parse events to the 
TransformerHandler.
      reader.parse(new InputSource(new StringReader(hand.detailresult)));

My Content Handler looks as follows:

public class MyHandler extends DefaultHandler {
private Writer out;
public MyHandler(JspWriter out) {this.out = out;}

        public void characters(char[] text, int start, int length) throws 
SAXException {
        try
        { out.write(text, start, length);
        out.flush();
        } catch (IOException e) {
           throw new SAXException(e);
        }


 }

}
      

Reply via email to