Android XML Element Value Get getNodeValue(Element node)

Here you can find the source of getNodeValue(Element node)

Description

This will get the text value of an element.

Parameter

Parameter Description
node The node to get the text value for.

Return

The text of the node.

Declaration

public static String getNodeValue(Element node) 

Method Source Code

//package com.java2s;

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

public class Main {
    /**//from   w ww .  j av  a2s. co  m
     * This will get the text value of an element.
     *
     * @param node The node to get the text value for.
     * @return The text of the node.
     */
    public static String getNodeValue(Element node) {
        StringBuilder sb = new StringBuilder();
        NodeList children = node.getChildNodes();
        int numNodes = children.getLength();
        for (int i = 0; i < numNodes; i++) {
            Node next = children.item(i);
            if (next instanceof Text) {
                sb.append(next.getNodeValue());
            }
        }
        return sb.toString();
    }
}

Related

  1. getNodeValue(Element node)
  2. getText(Element parentNode)
  3. getTextNode(Element element)
  4. getTextTrim(Element elto)
  5. getTextTrim(Element elto)