Java XML Element Value getElementValue(Element element)

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

Description

Get the value of the specified element

License

Apache License

Parameter

Parameter Description
element a parameter

Declaration

public static String getElementValue(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.NodeList;

public class Main {
    /**//from   ww w  . j a  v  a2  s. c o m
     * Get the value of the specified element
     *
     * @param element
     * @return
     */
    public static String getElementValue(Element element) {
        NodeList nl = element.getChildNodes();
        for (int i = 0; i < nl.getLength(); i++) {
            if (nl.item(i).getNodeType() == Node.TEXT_NODE) {
                return element.getFirstChild().getNodeValue();
            }
        }

        return null;
    }
}

Related

  1. getElementValue(Element elem, String path)
  2. getElementValue(Element element)
  3. getElementValue(Element element)
  4. getElementValue(Element element)
  5. getElementValue(Element element)
  6. getElementValue(Element element, String elementName)