Search code examples
javaxmlxsltxalan

Why does xalan not throw a TransformException error with malformed XML


In my unit tests I am trying to throw a TransformException error by sending some malformed xml to the org.apache.xalan.processor.TransformerFactoryImpl implementation of javax.xml.transform.Transformer

calling

transform(Source xmlSource,Result outputTarget) throws TransformerException

The console shows the following message, but no TransformerException is thrown

file:/filepath/MalformedInput.xml; Line #85; Column #16; XML document structures must start and end within the same entity.

Any ideas as to why it doesn't throw a TransformerException or how I can raise an Exception for this situation?

I have tried with saxon and a TransformerException is thrown, but i would prefer to use xalan

thanks


Solution

  • you need to specify an ErrorListener on your transformer (i believe you set this in the TransformerFactory).