title: nodejs elementtree npm xml parsing and merging
body: <p>I have a question on same module as I posted last time in below post. Seems like, it is quite difficult to deal with XML parsing. With elementTree having very mearge documentation.</p>
  
  <p>I have a below template_XML file:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;Tailoring xmlns="http://checklists.nist.gov/xccdf/1.2" id="xccdf_org.open-scap_tailoring_example"&gt;
  &lt;status&gt;incomplete&lt;/status&gt;
  &lt;version time="2013-01-15T16:00:00.000+02:00"&gt;1.0&lt;/version&gt;
      &lt;Profile id="PlaceHolder"&gt;
      &lt;title&gt;Tailoring for py_test&lt;/title&gt;
      &lt;select idref="xccdf_rule_name" selected="true"/&gt;
  &lt;/Profile&gt;
  &lt;/Tailoring&gt;
  </code></pre>
  
  <p>And a below sample_XML file:</p>
  
  <pre><code>&lt;Benchmark xmlns="http://checklists.nist.gov/xccdf/1.1" xmlns:xsi="www.w3.org/2001/XMLSchema-instance" id="SAP-HANA" resolved="1" xml:lang="en-US"&gt;
  &lt;status date="2016-03-17"&gt;draft&lt;/status&gt;
  &lt;title xmlns:xhtml="http://www.w3.org/1999/xhtml" xml:lang="en-US"&gt;Guide to the Secure Configuration of SAP HANA&lt;/title&gt;
  &lt;version&gt;0.1.28&lt;/version&gt;
  
  &lt;Profile id="profile1"&gt;
      &lt;title xmlns:xhtml="http://www.w3.org/1999/xhtml" xml:lang="en-US"&gt;text1&lt;/title&gt;
      &lt;select idref="This is rule 1" selected="true"/&gt;
      &lt;set-value idref="ssfs_master_key_timeout"&gt;20&lt;/set-value&gt;
  &lt;/Profile&gt; 
  
  &lt;Profile id="profile2"&gt;
      &lt;title xmlns:xhtml="http://www.w3.org/1999/xhtml" xml:lang="en-US"&gt;text2&lt;/title&gt;
      &lt;select idref="this is rule1" selected="true"/&gt;
      &lt;select idref="this is rule1" selected="true"/&gt;
      &lt;select idref="this is rule1" selected="true"/&gt;
  &lt;/Profile&gt;
  &lt;/Benchmark&gt;
  </code></pre>
  
  <p>I need to create a <strong>new_xml</strong> file, a <strong>copy of</strong> template_XML file.
  But want to replace "<strong>PlaceHolder</strong>" profile tag in <strong>new_xml</strong> file with the "<strong>profile2</strong>" tag of <strong>sample_XML</strong> file. Its a kind of merging of 2 xml file and creating a new one.
  Below is the code I have tried:</p>
  
  <pre><code>function call(id){
      var template_XML = 'C:\\MyDrive\\template_XML';
      var new_xml = 'C:\\MyDrive\\new_xml';
      data = fs.readFileSync(template_XML).toString();
      data1 = fs.readFileSync(sample_XML).toString();
      etree = et.parse(data);
      etree1 = et.parse(data1);
      var profile = etree.find('./Profile');  // Getting the profile sub-element.
      etree.getroot().remove(profile)         // Removing the sub-element. So that I can insert new profile from sample file
  
      var profiles = etree1.findall('./Profile'); // Find the required profile.
      for (var i = 0; i &lt; profiles.length; i++) {
          if(profiles[i].get('id') == 'profile2')
              var tmppro = profiles[i];
      }
      console.log(tmppro);
      etree.insert(3,tmppro);     // insert it. Failing
  
      var write = fs.openSync(new_xml, 'w');
      etree.write(write);                     // write it. Failing
  }
  </code></pre>
  
  <p>For one or the other reason, this code is not working in terms of "etree.insert" and "etree.write"</p>