It's hard for me to parse the XML from the boardgamegeek request so that I can populate the Google worksheet with data. Here is an example of bgg xml:
<boardgames termsofuse="http://boardgamegeek.com/xmlapi/termsofuse">
<boardgame objectid="423">
<yearpublished>1995</yearpublished>
<minplayers>3</minplayers>
<maxplayers>6</maxplayers>
<playingtime>300</playingtime>
<name primary="true" sortindex="1">1856</name>
</boardgame>
</boardgames>
And here is the Google Apps Script that I wrote to analyze it:
var url = 'http://www.boardgamegeek.com/xmlapi/boardgame/' + bggCode;
var bggXml = UrlFetchApp.fetch(url).getContentText();
var document = XmlService.parse(bggXml);
var root = document.getRootElement();
var entries = new Array();
entries = root.getChildren('boardgame');
for (var x = 0; x < entries.length; i++) {
var name = entries[x].getAttribute('name').getValue();
var yearpublished = entries[x].getAttribute('yearpublished').getValue();
var minplayers = entries[x].getAttribute('minplayers').getValue();
var maxplayers = entries[x].getAttribute('maxplayers').getValue();
}
Logger.log(entries);
I am currently getting a for-loop error caused by NULL entries. If I comment on the loop and register what bggXml looks like, it looks the same as in the example above. However, writing the variables further, I get the following:
document => [Document: No DOCTYPE declaration, Root is [Element: <boardgames/>]]
root => [Element: <boardgames/>]
entries => [[Element: <boardgame/>]]
entries[2] => undefined
Since bggXml looks exactly as I would expect, but the document does not work, I assume the problem is parsing?
pr0t0 source
share