Java tutorial
//package com.java2s; //License from project: Open Source License import java.util.Vector; import org.w3c.dom.Element; import org.w3c.dom.Node; import org.w3c.dom.NodeList; import org.w3c.dom.Text; public class Main { public static Vector<String> extractList(Element elem, String name) { NodeList nl = elem.getElementsByTagName(name); Vector<String> values = new Vector<String>(nl.getLength()); String retval = null; for (int n = 0; n < nl.getLength(); n++) { Element element = (Element) nl.item(n); retval = getSimpleElementText(element); if (retval != null) values.addElement(retval); } return values; } public static String getSimpleElementText(Element node) { if (node == null) return null; StringBuffer sb = new StringBuffer(); NodeList children = node.getChildNodes(); for (int i = 0; i < children.getLength(); i++) { Node child = children.item(i); if (child instanceof Text) { sb.append(child.getNodeValue()); } } return sb.toString(); } }