Here you can find the source of getTextContentOfElement(Element elem, String tagName, boolean required)
public static String getTextContentOfElement(Element elem, String tagName, boolean required) throws IOException
//package com.java2s; //License from project: Apache License import java.io.IOException; import java.util.ArrayList; import java.util.List; import org.w3c.dom.Element; import org.w3c.dom.NodeList; public class Main { public static String getTextContentOfElement(Element elem, String tagName, boolean required) throws IOException { List<String> result = getTextContentOfElements(elem, tagName); if (result.isEmpty() && !required) return null; if (result.size() != 1) throw new IOException("expected exactly one " + tagName + " element"); return result.get(0); }/*from w w w . j a v a 2 s. c om*/ public static List<String> getTextContentOfElements(Element elem, String tagName) { List<String> result = new ArrayList<String>(); NodeList inputElems = elem.getElementsByTagName(tagName); for (int i = 0; i < inputElems.getLength(); i++) { Element childElem = (Element) inputElems.item(i); result.add(childElem.getTextContent()); } return result; } }