Java tutorial
import java.util.ArrayList; import java.util.List; import org.w3c.dom.Element; import org.w3c.dom.Node; import org.w3c.dom.NodeList; public class Util { public static List<String> getTextValuesByTagName(Element element, String tagName) { NodeList nodeList = element.getElementsByTagName(tagName); ArrayList<String> list = new ArrayList<String>(); for (int i = 0; i < nodeList.getLength(); i++) { list.add(getTextValue(nodeList.item(i))); } return list; } public static String getTextValue(Node node) { StringBuffer textValue = new StringBuffer(); int length = node.getChildNodes().getLength(); for (int i = 0; i < length; i++) { Node c = node.getChildNodes().item(i); if (c.getNodeType() == Node.TEXT_NODE) { textValue.append(c.getNodeValue()); } } return textValue.toString().trim(); } }