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?
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
I just recently came across the same need. Setting the ErrorHandler to null suppresses the Fatal Error print line.
parser.setErrorHandler(null);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With