title: I want to search and the specific Nodes or elements in xml and create new xml from the select nodes
body: <p>I want to create new Xml file from the select nodes only i am using dom4j to parse and create new xml file. Example  lets assume Nodes Customer name = Joseph is the child of root element TRX i  want to show the whole elements  that contain joseph and create a new file</p>
  
  <pre><code>     enter code here
       File inputFile = new File("C:\\Users\\db2admin\\Desktop\\S4decs\\tlog01_004.xml");
       SAXReader reader = new SAXReader(true);
       reader.setValidation(false);
       reader.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
       Document document = reader.read(inputFile);
       document.getRootElement();
  
  
  
       document.selectNodes("//TRX[@type]='16'").size();
       document.selectNodes("/CUSTOMER").size();
  
  
  
  
       // Pretty print the document to System.out
       OutputFormat format = OutputFormat.createPrettyPrint();
       XMLWriter writer;
       writer = new XMLWriter( System.out, format );
       writer.write( document );
    } catch (DocumentException e) {
       e.printStackTrace();
    } catch (UnsupportedEncodingException e) {         
       e.printStackTrace();
    } catch (IOException e) {
       e.printStackTrace();
    }
  
  
  
  
   &lt;?xml version="1.0" encoding="UTF-8"?&gt;
   &lt;!DOCTYPE TRANSACTIONS SYSTEM "tlog.dtd"&gt;
   &lt;TRANSACTIONS storeid="4" sbs="780030" location="1"&gt;
   &lt;TRX type="16" term="742" trxnum="143895" saleperson="0" supervisor_id="152332149" storeid="4" sbs="780030" opcode="153135959"  date="20160915" endtime="111000"&gt;
   &lt;/TRX&gt;
   &lt;TRX type="31" term="742" trxnum="143896" starttime="095720" supervisor_id="152332149" storeid="4" sbs="780030" opcode="153135959" date="20160915" endtime="111001"&gt;
   &lt;CASHOPER managerid="153135959"&gt;
   &lt;PAYMENT id="1" amount="3000.00" descr="CASH" tndnumb="1" exchangetndid="0"&gt;
    &lt;/PAYMENT&gt;
    &lt;/CASHOPER&gt;
    &lt;LINKTRX linktype="8" prevstoreid="4" prevxactdate="2016-09-14" prevxacttime="22:58:29" prevtermid="0" prevxactid="7620" prevoperid="0"&gt;&lt;/LINKTRX&gt;
   &lt;/TRX&gt;
   &lt;TRX type="16" term="743" trxnum="65729" saleperson="0" supervisor_id="153136068" storeid="4" sbs="780030" opcode="152332262" date="20160915" endtime="111219"&gt;
  &lt;/TRX&gt;
  </code></pre>