I'm trying to capture xsl:message in java when calling my transform. Below is a snippet of my code.
final ArrayList<TransformerException> errorList = new ArrayList<TransformerException>();
ErrorListener errorListener = new ErrorListener() {
@Override
public void warning(TransformerException e) throws TransformerException {
//To change body of implemented methods use File | Settings | File Templates.
log.error(e.getMessage());
errorList.add(e);
}
@Override
public void error(TransformerException e) throws TransformerException {
//To change body of implemented methods use File | Settings | File Templates.
log.error(e.getMessage());
errorList.add(e);
}
@Override
public void fatalError(TransformerException e) throws TransformerException {
//To change body of implemented methods use File | Settings | File Templates.
errorList.add(e);
throw e;
}
};
...
try
{
transformer.setErrorListener(errorListener);
newDoc = transform(transformer, oldDoc);
}
catch (TransformerException e) {
log.error("Problem transforming normalized document into PUBS-XML", e);
throw e;
}
Unfortunately this is not working.
Is there a better way?
Thanks in advance!
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…