Java XML Element Get Value getTextValue(Element element)

Here you can find the source of getTextValue(Element element)

Description

Get the value of the first text child of an element.

License

Apache License

Parameter

Parameter Description
element Element whose text element we want

Return

String value or null.

Declaration


public static String getTextValue(Element element) 

Method Source Code


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

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

import org.w3c.dom.Node;

public class Main {
    /** Get the value of the first text child of an element.
         /*from   w w  w  . java2s .  co m*/
    @param element Element whose text element we want
    @return String value or null. */

    public static String getTextValue(Element element) {
        NodeList childs = element.getChildNodes();
        for (int i = 0; i < childs.getLength(); i++) {
            Node node = childs.item(i);
            if (Node.TEXT_NODE == node.getNodeType()) {
                return node.getNodeValue();
            }
        }
        return null;
    }
}

Related

  1. getTextValue(Element ele, String tagName)
  2. getTextValue(Element ele, String tagName)
  3. getTextValue(Element ele, String tagName)
  4. getTextValue(Element ele, String tagName)
  5. getTextValue(Element element)
  6. getTextValue(Element element, String name)
  7. getTextValue(Element element, String tagName)
  8. getTextValue(Element element, String tagName)
  9. getTextValue(Element node)