title: Split XML based on member tag value
body: <p>I have an xml which looks like</p>
  
  <pre><code>&lt;?xml version="1.0"?&gt;
  &lt;company&gt;
      &lt;staff&gt;
          &lt;firstname&gt;John&lt;/firstname&gt;
          &lt;lastname&gt;Player&lt;/lastname&gt;
          &lt;nickname&gt;JP&lt;/nickname&gt;
          &lt;salary&gt;1000&lt;/salary&gt;
      &lt;/staff&gt;
      &lt;staff&gt;
          &lt;firstname&gt;Peter&lt;/firstname&gt;
          &lt;lastname&gt;Shaw&lt;/lastname&gt;
          &lt;nickname&gt;PS&lt;/nickname&gt;
          &lt;salary&gt;2000&lt;/salary&gt;
      &lt;/staff&gt;
  &lt;/company&gt;
  </code></pre>
  
  <p>I need to pick only when firstname is Peter i.e. my o/p should be:</p>
  
  <pre><code>        &lt;staff&gt;
              &lt;firstname&gt;Peter&lt;/firstname&gt;
              &lt;lastname&gt;Shaw&lt;/lastname&gt;
              &lt;nickname&gt;PS&lt;/nickname&gt;
              &lt;salary&gt;2000&lt;/salary&gt;
          &lt;/staff&gt;
  </code></pre>
  
  <p>I am using XPath for it and the sample code looks like:</p>
  
  <pre><code>XPathFactory factory = XPathFactory.newInstance();
      XPath xpath = factory.newXPath();
      XPathExpression expr = xpath.compile("./company[staff/firstname = 'Peter']");
  
      Object result = expr.evaluate(doc, XPathConstants.NODESET);
      System.out.println("Print  " + result);  //comes as com.sun.org.apache.xml.internal.dtm.ref.DTMNodeList@ef0cdb
      NodeList nodes = (NodeList) result; 
      System.out.println("Size"+ nodes.getLength()); // comes as 0
      for (int i = 0; i &lt; nodes.getLength(); i++) {
          System.out.println(nodes.item(i).getNodeValue());
      }
  </code></pre>
  
  <p>Kindly provide guidance</p>