title: Create xml file in nodejs
body: <p>I am trying to send an xml file as an attachment in an email.</p>
  <p>I have a json from which I will create an xml. My question is, can I just write a string of tags into a file and is it a valid xml file?</p>
  <p>I am thinking about using template literals(<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals" rel="nofollow noreferrer">https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals</a>) like</p>
  <pre><code>  const myXmlString =   `&lt;ENVELOPE&gt;
      &lt;HEADER&gt;
          &lt;TALLYREQUEST&gt;${myVarsValue}&lt;/TALLYREQUEST&gt;
      &lt;/HEADER&gt;
      &lt;BODY&gt;&lt;/BODY&gt;
  &lt;/HEADER&gt;
  &lt;/ENVELOPE&gt;`
  </code></pre>
  <p>And write a file</p>
  <pre><code> file.writeFileSync(&quot;./filesx.xml&quot;, myXmlString, function (err) {
    if (err) throw err;
  });
  </code></pre>
  <p>Is this still valid xml file?</p>
  <p>I am trying to use this <a href="https://www.npmjs.com/package/xmlbuilder" rel="nofollow noreferrer">https://www.npmjs.com/package/xmlbuilder</a> which generated xml like this:</p>
  <pre><code>   var xml = builder.create('root')
    .ele('xmlbuilder')
      .ele('repo', {'type': 'git'}, 'git://github.com/oozcitak/xmlbuilder-js.git')
    .end({ pretty: true});
  </code></pre>
  <p>But I don't know how to write this into a file.</p>
  <p>Can I just use the first method or should I use the xmlbuilder? Even if the first method is ok, can someone tell me how I an write its result to a file?</p>
  <p>I tried this <a href="https://github.com/oozcitak/xmlbuilder-js/issues/227" rel="nofollow noreferrer">https://github.com/oozcitak/xmlbuilder-js/issues/227</a> but I get an error saying</p>
  <pre><code>    &lt;?xml version=&quot;1.0&quot;?&gt;&lt;root&gt;&lt;example0/&gt;&lt;example1/&gt;&lt;example2/&gt;&lt;example3/&gt;&lt;example4/&gt;&lt;example5/&gt;&lt;example6/&gt;&lt;example7/&gt;&lt;example8/&gt;&lt;example9/&gt;&lt;/root&gt;
  TypeError: Cannot read property 'match' of undefined
      at XMLStringifier.assertLegalChar (/Volumes/D/Vue admin node/card91_nodejs_boilerplate/node_modules/xmlbuilder/lib/XMLStringifier.js:209:32)
      at XMLElement.element (/Volumes/D/Vue admin node/card91_nodejs_boilerplate/node_modules/xmlbuilder/lib/XMLNode.js:127:25
  </code></pre>