Extract And Process XML Using Apps Script

Here’s a short code snippet demonstrating how to retrieve and parse a XML file using Apps Script. First, here’s how to download and parse the file:

var url = "URL to XML";
var xml = UrlFetchApp.fetch(url).getContentText();
var xml_document = XmlService.parse(xml);
var xml_root = xml_document.getRootElement();

Once the file is downloaded, you can retrieve child elements by calling getChild/getChildren. GetChild returns the first instance of the named element, and getChildren returns an array listing every element instance:

var xml_items = xml_root.getChild("channel").getChildren("item");

And finally, here’s how to retrieve the text content of an element:

var title = new String(xml_item.getChild("title").getContent(0));

Setting Security Constraints (Or, Adding Admin-Only Areas In web.xml)

After having experimented with Go for the past few weeks, returning back to Java is a little bit annoying, especially when configuring web.xml and appengine-web.xml files. Golang has a clean, neat configuration file in app.yaml, and yet Java on App Engine has to deal with relatively heavyweight XML files.

For instance, this is the markup required to create an admin-only folder on J/GAE:

The markup alone is 2-3 times the size of the settings themselves! There needs to be a better way of handling this.