title: Xpath select multiple attributes from same node
body: <p>From the xml, I need to get name and area for each node.</p>
  
  <p>I know the sample xpath like,</p>
  
  <p><code>XMLDependency/@name|XMLDependency/@area</code>, which gives comma separated values,</p>
  
  <p>Output:</p>
  
  <p><code>Name1, JKL, Name2, MNO</code></p>
  
  <p>XML:</p>
  
  <pre><code>&lt;DocBuild name="ABCD"&gt;
  &lt;XMLDependency name="Name1" product="Product ABC" area="JKL" /&gt;
  &lt;XMLDependency name="Name2" product="Product DEF" area="MNO" /&gt;
  &lt;XMLDependency name="Name3" product="Product GHI" area="PQR" /&gt;
  &lt;/DocBuild&gt;
  </code></pre>
  
  <p>Doubts:</p>
  
  <ul>
  <li><strike> How to handle if the <code>area</code> is not mandatory for node(value may present or absent).</strike></li>
  <li>Can we insert any static text between <code>name</code> and <code>area</code> so that we can parse the String using utilities ? </li>
  <li>Any Xpath expression apart from above to get the values to map ?(may be using adapter)</li>
  </ul>
  
  <p>Please help !</p>
  
  <p>[EDIT] :</p>
  
  <p>This is the Java program I started to use.</p>
  
  <pre><code>    XPath xPath = XPathFactory.newInstance().newXPath();
      NodeList nodeList = (NodeList) xPath.compile("//XMLDependency/@name|//XMLDependency/@area")
          .evaluate(element, XPathConstants.NODESET);
      List&lt;String&gt; nodes = new ArrayList&lt;String&gt;();
      for (int i = 0; i &lt; nodeList.getLength(); i++) {
          Node node = nodeList.item(i);
          nodes.add(node.getNodeValue());
      }
      System.out.println(nodes);
  </code></pre>
  
  <p>Handling by using node type and node value gets me first point solved.</p>