title: custom xml parse function for google spreadsheet
body: <p>I'm trying to replace the importXML function of googledocs because of its limit to use it only 50 items.</p>
  
  <p>The current formula would be:</p>
  
  <pre><code>=ImportXML($K$10,"sum(//row[@typeid='"B1&amp;"']/@quantity)")
  </code></pre>
  
  <p>Where the K10 cell contains an url to fetch the XML that looks like this:</p>
  
  <pre><code>&lt;eveapi version="2"&gt;
    &lt;currentTime&gt;2012-09-09 09:33:55&lt;/currentTime&gt;
    &lt;result&gt;
      &lt;rowset name="assets" key="itemID" columns="itemID,locationID,typeID,quantity,flag,singleton"&gt;
        &lt;row itemID="1003898262197" locationID="31001059" typeID="17167" quantity="1" flag="0" singleton="1" rawQuantity="-1"&gt;
          &lt;rowset name="contents" key="itemID" columns="itemID,typeID,quantity,flag,singleton"&gt;
        &lt;row itemID="1003962719504" typeID="253" quantity="3" flag="0" singleton="0"/&gt;
          &lt;/rowset&gt;
        &lt;/row&gt;
        &lt;row itemID="1003898281453" locationID="31001059" typeID="17408" quantity="1" flag="0" singleton="1" rawQuantity="-1"&gt;
          &lt;rowset name="contents" key="itemID" columns="itemID,typeID,quantity,flag,singleton"&gt;
        &lt;row itemID="1003962379527" typeID="253" quantity="3" flag="0" singleton="0"/&gt;
          &lt;/rowset&gt;
        &lt;/row&gt;
        &lt;row itemID="1003908898633" locationID="31001059" typeID="17175" quantity="1" flag="0" singleton="1" rawQuantity="-1"/&gt;
        &lt;row itemID="1003908901859" locationID="31001059" typeID="17174" quantity="1" flag="0" singleton="1" rawQuantity="-1"/&gt;
        &lt;row itemID="1003908954610" locationID="31001059" typeID="17177" quantity="1" flag="0" singleton="1" rawQuantity="-1"/&gt;
      &lt;/rowset&gt;
    &lt;/result&gt;
    &lt;cachedUntil&gt;2012-09-09 10:20:25&lt;/cachedUntil&gt;
  &lt;/eveapi&gt;
  </code></pre>
  
  <p>What i'm trying to do (as you perhaps can see from the ImportXML formula) is to get a sum of the quantity values of a particular typeID. The typeID would be an imput parameter of the function.</p>
  
  <pre><code>function _retrieveXML() {
    // https://api.eveonline.com/corp/AssetList.xml.aspx?keyID=688782&amp;vCode=q52TpGFTqNCziMMmZ7TYgpXCoGa7U0VBxyH7LuS6Ubtdakbi5t5UDMyf1U5WLpZA&amp;characterID=90127511
    var keyID = "xxxxxx"
    var vCode = "q52TpGFTqNCziMMmZ7TYgpXCoGa7U0VBxyH7LuS6Ubtdakbi5t5UDMyf1U5WLpZA"
    var characterID = "xxxxxxxx"
    var parameters = {
      method : "post",
      payload : "keyID=" + keyID + "&amp;vCode=" + vCode + "&amp;characterID=" + characterID
    };  
    var xmlFeed = UrlFetchApp.fetch("https://api.eveonline.com/corp/AssetList.xml.aspx",parameters);    
    var xmldoc = Xml.parse(xmlFeed.getContentText(), false);
    var records = xmldoc.eveapi.result.rowset.getElements("typeID");  
    var doc = SpreadsheetApp.getActiveSpreadsheet();
    var cell = doc.getRange('a1');
    var index = 0;  
    for (var i in xmldoc) {
      var row = xmldoc[i];
      cell.offset(index, 0).setValue(row[i]);
      }
      index++;
    }
  </code></pre>
  
  <p>I'm lost on how to get the information into a usable format for a google spreadsheet. How to retrieve a certain value of one of the objects (like typeID, quantity) and use them to retrieve another value in that same line.</p>
  
  <p>Any help is greatly appreciated.</p>