Here you can find the source of getText(Element elem, String name)
public static String getText(Element elem, String name)
//package com.java2s; //License from project: Open Source License import org.w3c.dom.Element; import org.w3c.dom.Node; import org.w3c.dom.NodeList; public class Main { public static String getText(Element elem, String name) { Element childElement = getFirstChildElement(elem, name); if (childElement == null) { return ""; }/*from www .j av a2 s.c om*/ Node node = childElement.getFirstChild(); return node == null ? "" : node.getTextContent(); } public static Element getFirstChildElement(Element elem, String name) { NodeList nodeList = elem.getChildNodes(); for (int i = 0; i < nodeList.getLength(); i++) { Node child = nodeList.item(i); if (child.getNodeType() == Node.ELEMENT_NODE && child.getNodeName().equals(name)) { return (Element) child; } } return null; } }