Java Utililty Methods XML Node Text Value

List of utility methods to do XML Node Text Value

Description

The list of methods to do XML Node Text Value are organized into topic(s).

Method

StringgetTextContent(final Node xmlNode)
get Text Content
return xmlNode == null ? null : xmlNode.getTextContent();
StringgetTextContent(Node baseNode)
Get XML Node text content.
Node child = baseNode.getFirstChild();
if (child != null && child.getNodeType() == Node.TEXT_NODE) {
    return child.getNodeValue();
return "";
StringgetTextContent(Node e)
get Text Content
StringBuilder sb = new StringBuilder();
NodeList children = e.getChildNodes();
if (children != null) {
    for (int i = 0; i < children.getLength(); i++) {
        Node n = children.item(i);
        if (n.getNodeType() == Node.TEXT_NODE) {
            sb.append(n.getNodeValue());
return sb.toString();
StringgetTextContent(Node element)
Extracts the text from the given element.
StringBuffer text = new StringBuffer();
NodeList childNodes = element.getChildNodes();
for (int i = 0; i < childNodes.getLength(); i++) {
    Node child = childNodes.item(i);
    if (child instanceof Text) {
        text.append(child.getNodeValue());
return text.toString();
StringgetTextContent(Node node)
get Text Content
for (int m = 0; m < node.getChildNodes().getLength(); m++) {
    Node child = node.getChildNodes().item(m);
    if (child.getNodeType() == Node.TEXT_NODE) {
        String childText = child.getNodeValue().trim();
        if (childText.length() > 0)
            return childText;
return null;
StringgetTextContent(Node node)
Returns the text content of a given Node.
if (node == null) {
    return null;
NodeList nl = node.getChildNodes();
for (int i = 0; i < nl.getLength(); i++) {
    Node childNode = nl.item(i);
    if (isTextNode(childNode)) {
        return childNode.getNodeValue();
...
StringgetTextContent(Node node)
This method return text value of node.
if (node != null) {
    return node.getTextContent();
return null;
StringgetTextContent(Node node)
get Text Content
StringBuilder sb = new StringBuilder();
for (Node textNode : getChildren("#text", node)) {
    sb.append(textNode.getNodeValue());
return sb.toString().trim();
StringgetTextContent(Node node)
based on public Java5 javadoc of org.w3c.dom.Node.getTextContent method
switch (node.getNodeType()) {
case Node.ELEMENT_NODE:
case Node.ATTRIBUTE_NODE:
case Node.ENTITY_NODE:
case Node.ENTITY_REFERENCE_NODE:
case Node.DOCUMENT_FRAGMENT_NODE:
    return mergeTextContent(node.getChildNodes());
case Node.TEXT_NODE:
...
StringgetTextContent(Node node)
get Text Content
NodeList list = node.getChildNodes();
String text = "";
int count = 0;
for (int i = 0; list != null && i < list.getLength(); i++) {
    String value = list.item(i).getNodeValue();
    if (value != null) {
        text += value;
        count++;
...