I am using a java application to invoke xslt to convert xml. The xslt file generates a message and terminates the process if some condition occurs. However, my java application was not able to catch the error message generated by xslt, it only catches an exception with general information - "Removal oriented".
Here is my Java code:
SAXTransformerFactory saxTFactory = ((SAXTransformerFactory) tFactory);
// Create a TransformerHandler for stylesheet.
File f2 = new File(styleSheetPath);
TransformerHandler tHandler2 = saxTFactory.newTransformerHandler (new StreamSource (f2));
XMLReader reader = XMLReaderFactory.createXMLReader ();
reader.setContentHandler(tHandler2);
reader.setProperty("http://xml.org/sax/properties/lexical-handler", tHandler2);
CharArrayWriter outputWriter = new CharArrayWriter();
Result result = new StreamResult(outputWriter);
tHandler2.setResult(result);
try
{
reader.parse(new InputSource(new StringReader(XMLinput)));
}
catch(Exception ee)
{
dsiplay(ee.getMessage())
throw ee;
}
How can I catch an error message from xslt?
I tried to write a class:
private class MyErrorHandler extends DefaultHandler {
public void error(SAXParseException e)
{
System.out.println("error method "+e.getMessage());
}
public void fatalError(SAXParseException e)
{
System.out.println("fatal error method "+e.getMessage());
}
public void warning(SAXParseException e)
{
System.out.println("warning method "+e.getMessage());
}
and
MyErrorHandler myHandler = new MyErrorHandler();
reader.setErrorHandler(myHandler);
This did not work.
Do you have any suggestions?
Jing