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  a va2s  .  c  om
     * 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) {
        String retval = "";
        NodeList children = node.getChildNodes();
        for (int i = 0; i < children.getLength(); i++) {
            Node next = children.item(i);
            if (next instanceof Text) {
                retval = next.getNodeValue();
            }
        }
        return retval;
    }
}

Related

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