Java tutorial
//package com.java2s; import java.io.File; import java.io.FileInputStream; import java.util.Vector; import javax.xml.xpath.XPath; import javax.xml.xpath.XPathConstants; import javax.xml.xpath.XPathFactory; import org.w3c.dom.NodeList; import org.xml.sax.InputSource; public class Main { public static Vector<String> readXMLNode222(String xmlFile, String xpath) { try { XPathFactory factory = XPathFactory.newInstance(); XPath xPath = factory.newXPath(); // XPathExpression xPathExpression = // xPath.compile("/history"); File xmlDocument = new File(xmlFile); InputSource inputSource = new InputSource(new FileInputStream(xmlDocument)); // String root = xPath.evaluate("/", inputSource); NodeList nodes = (NodeList) xPath.evaluate(xpath, inputSource, XPathConstants.NODESET); Vector<String> vector = new Vector<String>(); for (int x = 0; x < nodes.getLength(); x++) { vector.add(nodes.item(x).getTextContent()); } return vector; } catch (Exception ex) { ex.printStackTrace(); return new Vector(); } } }