I have the following Java method:
private static Document documentFromFile(final File xmlFile)
{
Document document = null;
try
{
DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory
.newInstance();
DocumentBuilder docBuilder = docBuilderFactory
.newDocumentBuilder();
document = docBuilder.parse(xmlFile);
document.getDocumentElement().normalize();
}
catch(Exception exc)
{
// Handle exception...
}
return document;
}
In my test methods, if I pass this method a malformed XML file I get all sorts of error output on my console:
[Fatal Error] :1:1: Content is not allowed in prolog.
[Fatal Error] :1:1: Premature end of file.
I assume the culprit is docBuilder.parse(xmlFile)
. I'd like to be able to disable this default output and "silence" the document builder, and I don't see any setter methods on this object that allow me to do anything like that. Do I have an remedies here or am I stuck with this?