对Google电子表格的XML响应

时间:2015-03-02 12:12:58

标签: xml google-apps-script xml-parsing google-sheets google-apps

我正在使用UrlFetchApp.fetch来获取联系人的API数据库,响应是未格式化的XML。我想使用这些数据Eg,Names(A列),Company(B列)等创建一个电子表格。响应是50个格式如下:

<item><rating>0</rating><resume_preview/><candidate_id>97096654</candidate_id><name>Bradley Johnston</name><location>Bentley, WA</location><source>Company Referral</source><added>09-09-14</added><last_activity>09-09-14 (Heath C.): Added candidate to pipeline: Potential</last_activity><status>Potential</status><status_historical> </status_historical><action/><title>Engineering & IT</title><company>Internal Postings</company><item_id>61571959</item_id></item><item><rating>0</rating><resume_preview/><candidate_id>97274234</candidate_id><name>Jacksen Dulvarie</name><location>Ivanhoe, VIC</location><source>Careers Website</source><added>10-09-14</added><last_activity>18-09-14 (Andrew V.): Status change: Potential</last_activity><status>Potential</status><status_historical> </status_historical><action/><title>Law</title><company>Internal Postings</company><item_id>61627337</item_id></item>

每个“项目”或人都有字段:rating,resume_preview,candidate_id,name,location,source ...等,然后是“Item”,它再次出现。

我希望每个项目都有一行,并且它们位于相应的列标题中。

也许一组名字然后写入一列?

function loadOutposts(){"http://api.catsone.com/api/get_pipelines.....";


  var parameters = {method : "get", payload : ""};
  var xmlFeed = UrlFetchApp.fetch(url, parameters).getContentText();
  var outposts= new Array();
  var url = 
  var document = XmlService.parse(xmlFeed);



 var document = XmlService.parse(xmlFeed); 
 logChildren(document.getRootElement().getChildren());



}


function logChildren(elements){
 Logger.log(elements.length);
 for (var i = 0; i < elements.length; i++) {
  Logger.log("%s -> %s",elements[i].getName(),elements[i].getText());
  if(elements[i].getContentSize() > 1){
    var children = elements[i].getChildren();

    logChildren(children);
  }
 } 
}

0 个答案:

没有答案