title: How to get a particular tag value using Jdom
body: <p>I am trying to get a particular value from an XML using Jdom parser.
  Below is my xml:</p>
  
  <pre><code>&lt;recordTarget&gt;
      &lt;patientRole&gt;
        **&lt;id root="1.20.3.01.5.2" extension="a"/&gt;
        &lt;id root="1.2.0.5.1.3.2" extension="b"/&gt;**
        &lt;addr use=""&gt;&lt;country&gt;&lt;/country&gt;&lt;state&gt;&lt;/state&gt;&lt;city&gt;&lt;/city&gt;&lt;postalCode&gt;&lt;/postalCode&gt;&lt;streetAddressLine&gt;&lt;/streetAddressLine&gt;&lt;/addr&gt;
        &lt;telecom value="" use=""/&gt;
        &lt;telecom value="" use=""/&gt;
        &lt;patient&gt;
        &lt;/patient&gt;
        &lt;providerOrganization&gt;
        &lt;/providerOrganization&gt;
      &lt;/patientRole&gt;
    &lt;/recordTarget&gt;
  </code></pre>
  
  <p>Now from the above xml i would like to get the 'extension' attribute under the 'ID' tag in (Marked in asterik) which has value "3.2" in it and ignore the id tag which contain "5.2".</p>
  
  <p>I am able to get first value but i need to get the second id tag value.</p>
  
  <p>Below is my java code which gives me the first value of ID's extension:</p>
  
  <pre><code>XPathExpression&lt;Attribute&gt; expr = xFactory.compile(xPath, Filters.attribute(), null, defaultNs);
          Attribute attribute = expr.evaluateFirst(document);
          if (attribute != null) {
              return attribute.getValue();
          } else {
              return "";
          }
  </code></pre>