tags:

views:

293

answers:

2

My application expects that it will sometimes try to parse invalid XML documents. I currently catch the "SAXParseException: Content is not allowed in prolog." exception, which works fine. However, Xerces still feels the need to print it's own message to the console:

[Fatal Error] :1:1: Content is not allowed in prolog.

Is there any way to disable this?

+1  A: 

I believe it is printing to System.out or System.err by default. There is an ErrorHandler interface you can set on the Parser if you're interacting with the Xerces classes directly.

Otherwise, you can try setting the property org.apache.xerces.impl.Constants.ERROR_REPORTER_PROPERTY on the SAXParser with an instance of XMLErrorReporter

Kevin
A: 

I just recently came across the same need. Setting the ErrorHandler to null suppresses the Fatal Error print line.

parser.setErrorHandler(null);
Dave