title: How to Split an XML file into multiple XML Files based on nodes
body: <p>I have an XML file as follows</p>
  
  <pre><code>&lt;?xml version="1.0&gt;
  &lt;EMR&gt;
    &lt;CustomTextBox&gt;
      &lt;Text&gt;WNL&lt;/Text&gt;
      &lt;Type&gt;TextBox&lt;/Type&gt;
      &lt;Width&gt;500&lt;/Width&gt;
      &lt;id&gt;txt1&lt;/id&gt;
    &lt;/CustomTextBox&gt;
  
    &lt;CustomTextBox&gt;
      &lt;Text&gt;WNL&lt;/Text&gt;
      &lt;Type&gt;TextBox&lt;/Type&gt;
      &lt;Width&gt;500&lt;/Width&gt;
      &lt;id&gt;txt2&lt;/id&gt;
    &lt;/CustomTextBox&gt;
  
    &lt;AllControlsCount&gt;
      &lt;Width&gt;0&lt;/Width&gt;
      &lt;id&gt;ControlsID&lt;/id&gt;
    &lt;/AllControlsCount&gt;
  &lt;/EMR&gt;
  </code></pre>
  
  <p>I want to split the xml file int o three. According to its nodes</p>
  
  <p>File 1:    </p>
  
  <pre><code>&lt;?xml version="1.0&gt;
  &lt;CustomTextBox&gt;
    &lt;Text&gt;WNL&lt;/Text&gt;
    &lt;Type&gt;TextBox&lt;/Type&gt;
    &lt;Width&gt;500&lt;/Width&gt;
    &lt;id&gt;txt1&lt;/id&gt;
  &lt;/CustomTextBox&gt;
  </code></pre>
  
  <p>File 2:</p>
  
  <pre><code>&lt;?xml version="1.0&gt;
  &lt;CustomTextBox&gt;
    &lt;Text&gt;WNL&lt;/Text&gt;
    &lt;Type&gt;TextBox&lt;/Type&gt;
    &lt;Width&gt;500&lt;/Width&gt;
    &lt;id&gt;txt2&lt;/id&gt;
  &lt;/CustomTextBox&gt;
  </code></pre>
  
  <p>File 3:</p>
  
  <pre><code>&lt;?xml version="1.0&gt;
  &lt;AllControlsCount&gt;
    &lt;Width&gt;0&lt;/Width&gt;
    &lt;id&gt;ControlsID&lt;/id&gt;
  &lt;/AllControlsCount&gt;
  </code></pre>
  
  <p>Also the nodes are dynamic, they may change. How can I split this xml file as multiple according to the nodes.  If anybody knows please share.</p>