Code example for Document

Methods: appendChild, createTextNode

0
                    final String qName)
            { 
                addTextIfNeeded(); 
                final Element closedEl = elementStack.pop();
                if (elementStack.isEmpty()) { // Is this the root element?
                    doc.appendChild(closedEl);
                } else { 
                    final Element parentEl = elementStack.peek();
                    parentEl.appendChild(closedEl);
                } 
            } 
 
            @Override 
            public void characters(final char ch[], final int start,
                    final int length) throws SAXException
            { 
                textBuffer.append(ch, start, length);
            } 
 
            // Outputs text accumulated under the current node 
            private void addTextIfNeeded() 
            { 
                if (textBuffer.length() > 0) {
                    final Element el = elementStack.peek();
                    final Node textNode = doc.createTextNode(textBuffer
                            .toString());
                    el.appendChild(textNode);
                    textBuffer.delete(0, textBuffer.length());
                } 
            }