title: How to get attribute value using XPath in Java?
body: <p>I have below XML to parse using XPath:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;schema&gt;
    &lt;element name="name_ele1" id="name_id_1" &gt;test name1&lt;/element&gt;
    &lt;element name="name_ele2" id="name_id_2" &gt;test name2&lt;/element&gt;
    &lt;element name="name_ele2" id="name_id_3" &gt;test name3&lt;/element&gt;
  &lt;/schema&gt;
  </code></pre>
  
  <p>I want to fetch "name" from the xml document based upon the Id I have passed but I am not able to get the required data instead query is returning blank.</p>
  
  <pre><code>XPathExpression expr = xpath.compile("/schema/element[@id='name_id_2']/name/text()");
  </code></pre>