Android XML Node Value Get getTextContent(Node n, StringBuffer buf)

Here you can find the source of getTextContent(Node n, StringBuffer buf)

Description

get Text Content

Declaration

public static void getTextContent(Node n, StringBuffer buf)
            throws DOMException 

Method Source Code

//package com.java2s;
import org.w3c.dom.DOMException;
import org.w3c.dom.Node;

public class Main {
    public static String getTextContent(Node n) throws DOMException {
        Node child = n.getFirstChild();
        if (child != null) {
            Node next = child.getNextSibling();
            if (next == null) {
                return hasTextContent(child) ? child.getNodeValue() : "";
            }//from  ww  w .j  a v  a2s  .c  o m
            StringBuffer buf = new StringBuffer();
            getTextContent(n, buf);
            return buf.toString();
        }
        return "";
    }

    public static void getTextContent(Node n, StringBuffer buf)
            throws DOMException {
        Node child = n.getFirstChild();
        while (child != null) {
            if (hasTextContent(child)) {
                String content = child.getNodeValue();
                if (content != null) {
                    buf.append(content);
                }
            }
            child = child.getNextSibling();
        }
    }

    public static boolean hasTextContent(Node child) {
        return child.getNodeType() != Node.COMMENT_NODE
                && child.getNodeType() != Node.PROCESSING_INSTRUCTION_NODE;
    }
}

Related

  1. getText(Node node, String tag)
  2. getText(Node node, String tag)
  3. getText(Node node, String tag)
  4. getTextContent(Node n)
  5. getTextContent(Node n)
  6. getTextContent(org.w3c.dom.Node element)
  7. getTextNodeValue(Node node)
  8. getXml(Node node)
  9. getXmlInt(Node node, String xmlLocalName, int defaultValue)