class XPathFinder {

	public List<String> queryTexts(String query) {
		try {
			XPathFactory factory = XPathFactory.newInstance();
			XPath xpath = factory.newXPath();
			XPathExpression expr = xpath.compile(query);
			NodeList result = (NodeList) expr.evaluate(doc,
					XPathConstants.NODESET);
			int length = result.getLength();
			List<String> ret = new ArrayList<String>(length);
			for (int i = 0; i < length; i++) {
				Node item = result.item(i);
				String text = item.getNodeValue();
				if (text == null && item.getChildNodes().getLength() > 0) {
					text = item.getFirstChild().getNodeValue();
				}
				ret.add(text);
			}
			return ret;
		} catch (XPathExpressionException e) {
			throw new RuntimeException(e);
		}
	}

}