Java XML Element Get Value getValue(Element element)

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

Description

Get the text value for the specified element.

License

Apache License

Parameter

Parameter Description
element The Element

Return

The value String or null

Declaration

public static String getValue(Element element) 

Method Source Code

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

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

import org.w3c.dom.Text;

public class Main {
    /**//w  w  w  . ja  va2 s.  co  m
     * Get the text value for the specified element.  If the element is null, or the element's body is empty then this
     * method will return null.
     *
     * @param element The Element
     * @return The value String or null
     */
    public static String getValue(Element element) {
        if (element != null) {
            Node dataNode = element.getFirstChild();
            if (dataNode != null) {
                return ((Text) dataNode).getData();
            }
        }
        return null;
    }
}

Related

  1. getUniqueElement(Element root, String elementName)
  2. getUniqueSubnode(Element rootNode, String name)
  3. getValue(Element e, String tagName)
  4. getValue(Element el)
  5. getValue(Element element)
  6. getValue(Element element)
  7. getValue(Element element, String tag)
  8. getValue(Element pElement)
  9. getValueFromElement(Element element, String tagName)