Here you can find the source of getChildData(Element e, String tag)
public static String getChildData(Element e, String tag)
//package com.java2s; import org.w3c.dom.Element; import org.w3c.dom.Node; import org.w3c.dom.NodeList; public class Main { public static String getChildData(Element e, String tag) { NodeList children = e.getElementsByTagName(tag); if (children == null || children.getLength() == 0) return null; return getChildData((Element) children.item(0)); }//from ww w . jav a2s.co m public static String getChildData(Element e) { NodeList eChildren = e.getChildNodes(); if (eChildren == null || eChildren.getLength() == 0) return null; // OK, now, find the text node and return it's value for (int index = 0; index < eChildren.getLength(); index++) { Node n = eChildren.item(index); if (n.getNodeType() == Node.TEXT_NODE) { return n.getNodeValue(); } } return null; } }