Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable logging in Java Xerces ("[Fatal Error] :1:1: Content is not allowed in prolog.")

Tags:

java

xml

xerces

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?

like image 517
tlrobinson Avatar asked Oct 16 '09 00:10

tlrobinson


2 Answers

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

like image 41
Kevin Avatar answered Sep 19 '22 07:09

Kevin


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

parser.setErrorHandler(null);
like image 72
Dave Avatar answered Sep 22 '22 07:09

Dave