Java XML Element Get Value getTextValue(Element element, String name)

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

Description

get Text Value

License

Open Source License

Declaration

public static String getTextValue(Element element, String name) 

Method Source Code


//package com.java2s;
// Released under the terms of the CPL Common Public License version 1.0.

import org.w3c.dom.*;

public class Main {
    public static String getTextValue(Element element, String name) {
        Element namedElement = getElementByTagName(element, name);
        return getElementText(namedElement);
    }//from w  w  w .j  a  v a 2  s  . c o m

    public static Element getElementByTagName(Element element, String name) {
        NodeList nodes = element.getElementsByTagName(name);
        if (nodes.getLength() == 0)
            return null;
        else
            return (Element) nodes.item(0);
    }

    public static String getElementText(Element namedElement) {
        if (namedElement == null) {
            return null;
        }
        String text = namedElement.getTextContent();
        return (text.isEmpty()) ? null : text;
    }
}

Related

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