Code example for DocumentBuilder

Methods: newDocument

0
            SAXParserFactory factory = SAXParserFactory.newInstance();
            parser = factory.newSAXParser();
 
            DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
            DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
            doc = docBuilder.newDocument();
        } catch (ParserConfigurationException e) {
            throw new RuntimeException("Can't create SAX parser / DOM builder.", e);
        } 
 
        final Stack<Element> elementStack = new Stack<Element>();
        final StringBuilder textBuffer = new StringBuilder();
        DefaultHandler handler = new DefaultHandler2() {
            //DefaultHandler handler2 = new DefaultHandler() { 
 
            private Locator locator;
            boolean insideCdata = false;
 
            @Override 
            public void endCDATA() throws SAXException { 
                super.endCDATA();