//autor J. Santolaya 2008 //http://joanju.info import java.io.IOException; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; import org.w3c.dom.*; import org.xml.sax.SAXException; import javax.xml.xpath.*; import javax.xml.parsers.*; public class XPathSample { public static void main(String[] args){ try { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(true); DocumentBuilder builder; builder = factory.newDocumentBuilder(); Document document = builder.parse("libros.xml"); //create a XPath factory XPathFactory xfactory = XPathFactory.newInstance(); //create a XPath object thanks to XPath factory XPath xpath = xfactory.newXPath(); //now we need an expression to compile thanks to the xpath object XPathExpression expression = xpath.compile("//libro"); //evaluate the expression,we need the document and all the NODESET Object obj = expression.evaluate(document, XPathConstants.NODESET); //to find all the titles we can iterate throw a DOM Nodelist NodeList nodes = (NodeList) obj; for(int i=0; i