Writing inside of xml file by using javascript

Viewed 37

i have a simple javascript code im using an api for taking data . and im transforming it to xml languege and printing in html text area . But i need to take this data ,transform to xml languege and write this data to inside of xml file. Does anyone done this before ?

i tried so much ways to open xml file and edit it but u just can read it. I cant edit xml file

1 Answers

Javascript doesn't let you write data and then save it on the server. You need a backend that manage this type of thing.

You can generate an .xml file and make the user download it

xmlwrite let you create an XML file which can be saved then

var XMLWriter = require('xml-writer');
xw = new XMLWriter;
xw.startDocument();
xw.startElement('root');
xw.writeAttribute('foo', 'value');
xw.text('Some content');
xw.endDocument();

var file = new Blob([xw.toString()], {type: 'text/plain'});
save_button.href = URL.createObjectURL(file);
save_button.download = 'file.xml';

Where save_button id should be associated to an <a> tag such as <a href="" id="save_button">Download XML</a>

Related