Code example for DocumentBuilder

Methods: newDocument

0
            parser = factory.newSAXParser();
            final DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory
                    .newInstance();
            final DocumentBuilder docBuilder = docBuilderFactory
                    .newDocumentBuilder();
            doc = docBuilder.newDocument();
        } catch (final 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();
        final DefaultHandler handler = new DefaultHandler()
        { 
            private Locator locator;
 
            @Override 
            public void setDocumentLocator(final Locator locator)
            { 
                this.locator = locator; // Save the locator, so that it can be