Code example for DocumentBuilderFactory

Methods: isExpandEntityReferencesnewDocumentBuildersetExpandEntityReferences

0
 
    /** 
     * javax.xml.parsers.DocumentBuilderFactory#setExpandEntityReferences(boolean). 
     */ 
    public void test_setExpandEntityReferencesZ() { 
        dbf.setExpandEntityReferences(true);
        assertTrue(dbf.isExpandEntityReferences());
 
        Exception parseException = null;
        DocumentBuilder parser = null;
 
        try { 
            parser = dbf.newDocumentBuilder();
            ValidationErrorHandler errorHandler = new ValidationErrorHandler();
            parser.setErrorHandler(errorHandler);
 
            Document document = parser.parse(getClass().getResourceAsStream(
                    "/recipt.xml")); 
 
            parseException = errorHandler.getFirstException();
 
            assertNotNull(document);
 
        } catch (Exception ex) {
            parseException = ex;
        } 
        parser.setErrorHandler(null);
 
        if (parseException != null) {
            fail("Unexpected exception " + parseException.getMessage());
        } 
 
        dbf.setExpandEntityReferences(false);
        assertFalse(dbf.isExpandEntityReferences());
        try { 
            parser = dbf.newDocumentBuilder();
            ValidationErrorHandler errorHandler = new ValidationErrorHandler();
            parser.setErrorHandler(errorHandler);
 
            Document document = parser.parse(getClass().getResourceAsStream(
                    "/recipt.xml")); 
Contextual code suggestions in your IDE  Get Codota for Java