Code example for DocumentBuilder

Methods: parsesetErrorHandler

0
    public Document load(URL url, DocumentBuilder builder) {
        Document doc = null;
        Exception parseException = null;
        try { 
            LoadErrorHandler errorHandler = new LoadErrorHandler();
            builder.setErrorHandler(errorHandler);
            doc = builder.parse(url.openStream());
            parseException = errorHandler.getFirstException();
        } catch (Exception ex) {
            parseException = ex;
        } 
        builder.setErrorHandler(null);
        if (parseException != null) {
            // fail("Unexpected exception " + parseException.getMessage()); 
            throw new RuntimeException("Unexpected exception " + parseException.getMessage(), parseException);
        } 
        return doc;
    } 
 
    public void preload(String contentType, String docURI,
Stop searching for code, let great code find you!  Add Codota to your java IDE