我的第二个示例是返回 [function getValue] 的示例,我正在尝试修复它,但我看不出问题出在哪里。
我一直在 google 脚本中搞乱 xmlparse,我想解析的 xml 将所有相关数据保存在元素的属性中。
下面是一些有效的代码(通过 log [ctrl]+[enter] 显示):
function dialogDisplay() {
var xmlstring = Xml.parse('<rowset name="characters" key="characterID" columns="name,characterID,corporationName,corporationID"><row name="Jonah Younbrog" characterID="90131303" corporationName="House of Praetor" corporationID="523373135"/><row name="Mador Younbrog" characterID="90149709" corporationName="House of Praetor" corporationID="523373135"/><row name="Marc Younbrog" characterID="747451028" corporationName="House of Praetor" corporationID="523373135"/></rowset>');
var attributes = xmlstring.getElement().getAttributes();
for (var i in attributes) {
Logger.log(attributes[i].getValue());
}
}
这是不起作用的代码,它还记录了元素名称(成功)并使用嵌套的 fors 来遍历 xml:
function fetchToLogger() {
var assetURL = "https://api.eveonline.com/account/characters.xml.aspx?keyID=1409941&vCode=xagxMH966J2EQinVpoFOBB5H1UidCwsjoTwtBKhhvMVZWqq6Jio4mkiBwv026Olc";
var assetstring = UrlFetchApp.fetch(assetURL).getContentText();
var xmlstring = Xml.parse(assetstring, false);
var elements = xmlstring.eveapi.result.getElements();
for (var a in elements) {
Logger.log(elements[a].getName().getLocalName());
var attributes = elements[a].getAttributes();
for (var x in attributes) {
Logger.log(attributes[x].getValue);
}
var subelements = elements[a].getElements();
for (var b in subelements) {
Logger.log(subelements[b].getName().getLocalName());
var subattributes = subelements[b].getAttributes();
for (var y in attributes) {
Logger.log(attributes[y].getValue);
}
}
}
}