I need to generate a XML document, using specific data from a spreadsheet.
I'm using GoogleScript, but I don't see any libraries to help me generate XML. (The standard XML Service only parses XML)
Am I forced to do this by-hand or am I missing something?
Can you recommend any libraries or Javascript functions that might assist in generating XML?
Thanks
Microsoft XML Notepad is an application that allows you to create and edit XML documents quickly and easily. With this tool, the structure of your XML data is displayed graphically in a tree structure. The interface presents two panes: one for the structure, and one for the values.
Click File > Save As, and select the location where you want to save the file. , point to the arrow next to Save As, and then click Other Formats. In the File name box, type a name for the XML data file. In the Save as type list, click XML Data, and click Save.
You can build XML documents using HtmlService templates. You can also create documents with the Xml service by starting with an empty document (Xml.parse('') or something similar) and then manipulating it with Xml.element() and the like, but I'd suspect that the first idea is much easier.
Recently I found an ability to generate XML using a XML
class (not Xml
) which exists in GAS. An example is following
function makeXML() {
var xml = new XML('<a/>');
xml['@attrib1'] = 'atribValue';
xml.data = 'dataValue';
xml.data.sub_data = 'subDataValue';
return xml.toString();
}
function doGet(e) {
var app = UiApp.createApplication();
app.add(app.createLabel(makeXML()));
return app;
}
The output for this script is <a attrib1="atribValue"> <data> dataValue <sub_data>subDataValue</sub_data> </data> </a>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With