I am trying to send an xml file as an attachment in an email.
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?
I am thinking about using template literals(https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals) like
const myXmlString = `<ENVELOPE>
<HEADER>
<TALLYREQUEST>${myVarsValue}</TALLYREQUEST>
</HEADER>
<BODY></BODY>
</HEADER>
</ENVELOPE>`
And write a file
file.writeFileSync("./filesx.xml", myXmlString, function (err) {
if (err) throw err;
});
Is this still valid xml file?
I am trying to use this https://www.npmjs.com/package/xmlbuilder which generated xml like this:
var xml = builder.create('root')
.ele('xmlbuilder')
.ele('repo', {'type': 'git'}, 'git://github.com/oozcitak/xmlbuilder-js.git')
.end({ pretty: true});
But I don't know how to write this into a file.
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?
I tried this https://github.com/oozcitak/xmlbuilder-js/issues/227 but I get an error saying
<?xml version="1.0"?><root><example0/><example1/><example2/><example3/><example4/><example5/><example6/><example7/><example8/><example9/></root>
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