Android XML Node Value Get getTextContent(Node n)

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

Description

get Text Content

Declaration

public static String getTextContent(Node n) 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() : "";
            }/* w  w w.  j  a v  a 2 s  .c  om*/
            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 n)
  2. getText(Node node, String tag)
  3. getText(Node node, String tag)
  4. getText(Node node, String tag)
  5. getTextContent(Node n)
  6. getTextContent(Node n, StringBuffer buf)
  7. getTextContent(org.w3c.dom.Node element)
  8. getTextNodeValue(Node node)
  9. getXml(Node node)