Java XML Node Text Value getTextContent(final Node node)

Here you can find the source of getTextContent(final Node node)

Description

get Text Content

License

Apache License

Declaration

public static String getTextContent(final Node node) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

public class Main {
    public static String getTextContent(final Node node) {
        boolean hasTextContent = false;
        final StringBuffer buffer = new StringBuffer();
        final NodeList nlist = node.getChildNodes();
        for (int i = 0; i < nlist.getLength(); i++) {
            final Node child = nlist.item(i);
            if (child.getNodeType() == Node.TEXT_NODE) {
                buffer.append(child.getNodeValue());
                hasTextContent = true;//from  w ww .j av  a 2s.  c  o m
            }
        }
        return hasTextContent ? buffer.toString() : null;
    }
}

Related

  1. getText(Node node)
  2. getText(Node node)
  3. getTextBefore(Node node)
  4. getTextBetween(Node node1, Node node2)
  5. getTextBuffer(Node e, StringBuilder sb)
  6. getTextContent(final Node node)
  7. getTextContent(final Node node, final String defaultValue)
  8. getTextContent(final Node node, final StringBuffer sb)
  9. getTextContent(final Node xmlNode)