[英]Parse all values from a XML element using Google Apps Script?
I am trying to parse forex values (all of them) for http://indicador.eof.cl/rss XML feed into a Gooogle Sites trough Google Apps Script. 我正在尝试通过Google Apps脚本将http://indicador.eof.cl/rss XML提要的外汇值(全部)解析为Gooogle站点。
The script as follow> 脚本如下>
function doGet(){
var response = UrlFetchApp.fetch("http://indicador.eof.cl/rss").getContentText();
var parsedResponse = Xml.parse(response, false);
var root = parsedResponse.getElement();
var entries = root.getElement('channel').getElements("item");
for (var i=0; i<entries.length; i++) {
var e = entries[i];
var title = e.getElement("title").getText();
var description = e.getElement("description").getText();
}
var app = UiApp.createApplication();
var TopVar = app.createHorizontalPanel();
TopVar.add(app.createLabel(title).setStyleAttribute("fontSize","12px"));
TopVar.add(app.createLabel(description).setStyleAttribute("fontSize","12px"));
app.add(TopVar);
return app;
}
The issue is the code just bring me the first value no all of them, what i am forgetting? 问题是代码只是给我带来了第一个价值,而没有一个,我忘记了什么?
Best Regards, 最好的祝福,
Try to move TopVar.add(...);
尝试移动TopVar.add(...);
lines inside for loop : for循环内的行:
var app = UiApp.createApplication();
var TopVar = app.createHorizontalPanel();
for (var i=0; i<entries.length; i++) {
var e = entries[i];
var title = e.getElement("title").getText();
var description = e.getElement("description").getText();
TopVar.add(app.createLabel(title).setStyleAttribute("fontSize","12px"));
TopVar.add(app.createLabel(description).setStyleAttribute("fontSize","12px"));
}
Actually, I know nothing about google-apps-script. 实际上,我对google-apps-script一无所知。 But your current code logic seems a bit off. 但是您当前的代码逻辑似乎有些偏离。 It doesn't make use of values of local variables declare inside for loop ( e
, title
, and description
). 它不使用for循环内部声明的局部变量的值( e
, title
和description
)。 Value of those variables changed in every iteration without any code using it. 这些变量的值在每次迭代中都会更改,而无需使用任何代码。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.