Java XML Child Element Text getChildText(Element element, String tag)

Here you can find the source of getChildText(Element element, String tag)

Description

get Child Text

License

Open Source License

Declaration

public static String getChildText(Element element, String tag) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

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

public class Main {
    public static String getChildText(Element element, String tag) {
        String value = null;/* w ww .  j  a  v a 2 s.  c  o m*/
        NodeList nodeList = element.getElementsByTagName(tag);
        if (nodeList != null && nodeList.getLength() > 0) {
            Element el = (Element) nodeList.item(0);
            if (el.getFirstChild() != null) {
                value = el.getFirstChild().getNodeValue();
            }
        }
        return value;
    }
}

Related

  1. getChildElementValueByTagName(Element ele, String childEleName)
  2. getChildElementValueByTagName(Element parentElement, String childTag)
  3. getChildText(Element elem, String childTagName)
  4. getChildText(Element element, String defaultValue)
  5. getChildText(Element element, String nodeName)
  6. getChildText(Element element, String tag)
  7. getChildText(Element parent, String childLocalName, String childNamespaceURI)
  8. getChildText(Element parent, String childName)
  9. getChildText(Element parent, String childName)