title: Parsing multi-level XML with Google App Script XmlService
body: <p>I'm having trouble getting to the child elements to the <code>&lt;result&gt;</code> tag.</p>
  
  <p>The code:</p>
  
  <pre><code>var xml = '\
    &lt;document&gt;\
      &lt;currentTime&gt;2013-09-05 09:47:06&lt;/currentTime&gt;\
      &lt;result&gt;\
        &lt;one&gt;2013-09-05 09:47:06&lt;/one&gt;\
        &lt;two&gt;2013-09-20 14:30:13&lt;/two&gt;\
        &lt;three&gt;2013-09-02 14:12:22&lt;/three&gt;\
        &lt;four&gt;2505&lt;/four&gt;\
      &lt;/result&gt;\
      &lt;cachedUntil&gt;2013-09-05 10:28:40&lt;/cachedUntil&gt;\
    &lt;/document&gt;';
  
  var document = XmlService.parse(xml);
  var entries = document.getRootElement().getChildren();
  Logger.log(entries.length);
  for (var i = 0; i &lt; entries.length; i++) {
    Logger.log("%s -&gt; %s",entries[i].getName(),entries[i].getText());
  }
  </code></pre>
  
  <p>Running this code returns the following in the logger as I expected:</p>
  
  <pre><code>[13-09-05 13:54:18:815 EAT] 3.0
  [13-09-05 13:54:18:815 EAT] currentTime -&gt; 2013-09-05 09:47:06
  [13-09-05 13:54:18:816 EAT] result -&gt;                                       
  [13-09-05 13:54:18:816 EAT] cachedUntil -&gt; 2013-09-05 10:28:40
  </code></pre>
  
  <p>I get 3 elements and I'm able to run the <code>getName()</code> and <code>getText()</code> methods just fine. However, if I try to get the children of a specific element like <code>&lt;result&gt;</code> with the line <code>var results = entries.getChildren();</code> right after I define entries, I get the runtime  error "TypeError: Cannot find function getChildren in object [Element: ]". What the deuce?</p>
  
  <p>I don't get what's going on here (obviously). <code>getRootElement()</code> returns an Element type. <code>getChildren()</code> returns an array of Elements. Where is <code>entries</code> getting turned into something that isn't an Element and is there a better way to parse this document? I feel like I'm missing something really stupid here.</p>