java - How to quiet org.w3c.dom.Document? -
i have 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 test methods, if pass method malformed xml file sorts of error output on console:
[fatal error] :1:1: content not allowed in prolog.
[fatal error] :1:1: premature end of file.
i assume culprit docbuilder.parse(xmlfile). i'd able disable default output , "silence" document builder, , don't see setter methods on object allow me that. have remedies here or stuck this?
use documentbuilder.seterrorhandler set implementation of errorhandler. don't confused package name. though says "org.xml.sax" 1 want. think can use defaulthandler because javadoc says ignores errors , warnings. if still verbose, can supply own implementation.
documentbuilder db = documentbuilderfactory.newinstance().newdocumentbuilder(); db.seterrorhandler(new defaulthandler());
Comments
Post a Comment