Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I generate XML?

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

like image 465
user1511982 Avatar asked Aug 02 '12 14:08

user1511982


People also ask

What software creates XML files?

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.

How do I create an XML file from Excel?

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.


2 Answers

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.

like image 173
Corey G Avatar answered Oct 19 '22 20:10

Corey G


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>

like image 44
megabyte1024 Avatar answered Oct 19 '22 21:10

megabyte1024