我的第二個例子是返回[function getValue]的那個,我試圖修復它,但是我看不到問題出在哪裏。getAttributes在嵌套時返回[function getValue]
我一直在xmlparse在谷歌腳本中亂搞,我想解析的xml保留所有相關數據的元素屬性。
下面是一些代碼,工程(通過日誌顯示[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());
}
}
這裏還有一點不代碼工作中,還記錄元素名稱(成功),並使用嵌套的維權經歷的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);
}
}
}
}
哈哈,原來如此,三江源非常多。 – Medicdude
@Medicdude不用客氣。請接受解答我的答案或Tomasz的答案(如果你認爲更好地解釋):) byez –