XPathによるノードアクセス(j2se1.5から)
http://java.sun.com/j2se/1.5.0/docs/api/javax/xml/xpath/package-summary.html
import javax.xml.xpath.XPath; import javax.xml.xpath.XPathConstants; import javax.xml.xpath.XPathExpressionException; import javax.xml.xpath.XPathFactory; import org.w3c.dom.NodeList; import org.xml.sax.InputSource; public class XpathTest { public static void main(String[] args) throws XPathExpressionException { XPath xpath = XPathFactory.newInstance().newXPath(); String expression = "/widgets/widget/dimensions"; InputSource inputSource = new InputSource(ClassLoader.getSystemResourceAsStream("hoge/widgets.xml")); NodeList nodes = (NodeList)xpath.evaluate(expression, inputSource, XPathConstants.NODESET); System.out.println(nodes); } }