Code example for DocumentBuilderFactory

Methods: newDocumentBuilder, setValidating

0
    } 
 
    public void test_newDocumentBuilder() { 
        // Ordinary case 
        try { 
            DocumentBuilder db = dbf.newDocumentBuilder();
            assertTrue(db instanceof DocumentBuilder);
            db.parse(getClass().getResourceAsStream("/simple.xml"));
        } catch(Exception e) {
            throw new RuntimeException("Unexpected exception", e);
        } 
 
        // Exception case 
        dbf.setValidating(true);
        try { 
            DocumentBuilder db = dbf.newDocumentBuilder();
        } catch(ParserConfigurationException e) {
            // Expected, since Android doesn't have a validating parser. 
        } 
    }