title: Java XPath: Get all the elements that match a query
body: <p>I want to make an XPath query on this XML file (excerpt shown):</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;!-- MetaDataAPI generated on: Friday, May 25, 2007 3:26:31 PM CEST --&gt;
  &lt;Component xmlns="http://xml.sap.com/2002/10/metamodel/webdynpro" xmlns:IDX="urn:sap.com:WebDynpro.Component:2.0" mmRelease="6.30" mmVersion="2.0" mmTimestamp="1180099591892" name="MassimaleContr" package="com.bi.massimalecontr" masterLanguage="it"&gt;
  ...
      &lt;Component.UsedModels&gt;
          &lt;Core.Reference package="com.test.test" name="MasterModel" type="Model"/&gt;
          &lt;Core.Reference package="com.test.massimalecontr" name="MassimaleModel" type="Model"/&gt;
          &lt;Core.Reference package="com.test.test" name="TravelModel" type="Model"/&gt;
      &lt;/Component.UsedModels&gt;
  ...
  </code></pre>
  
  <p>I'm using this snippet of code:</p>
  
  <pre><code>DocumentBuilderFactory domFactory = DocumentBuilderFactory.newInstance();
  domFactory.setNamespaceAware(true);
  DocumentBuilder builder = domFactory.newDocumentBuilder();
  Document document = builder.parse(new File("E:\\Test branch\\test.wdcomponent"));
  XPathFactory factory = XPathFactory.newInstance();
  XPath xpath = factory.newXPath();
  
  xpath.setNamespaceContext(new NamespaceContext() {
  ...(omitted)
  
  System.out.println(xpath.evaluate(
      "//d:Component/d:Component.UsedModels/d:Core.Reference/@name", 
      document));
  </code></pre>
  
  <p>What I'm expecting to get:</p>
  
  <pre><code>MasterModel
  MassimaleModel
  TravelModel
  </code></pre>
  
  <p>What I'm getting:</p>
  
  <pre><code>MasterModel
  </code></pre>
  
  <p>It seems that only the first element is returned. How can I get all the occurrences that matches my query?</p>