I for some reason can not figure out how to loop through this xml. I can get data out from the first parent nodes and the children nodes below it, but can not get it to go to the second parent node. Any help would be great. I'm using xmlReader.
function saveData(dataObject) {
var GameData = Parse.Object.extend("AllGameData");
var GameData = new GameData();
dataObject.forEach(function (element, i) {
GameData.set(element.name, element.data);
});
GameData.save();
}
Parse.Cloud.httpRequest({
url: xmlURL,
success: function (httpResponse) {
var counter = 0;
xmlreader.read(httpResponse.text, function (err, xmldata) {
var state = xmldata.allcrosswords.StateCrossword.count();
for(var y = 0; y < state.length; y++) {
xmldata.allcrosswords.array[y].StateCrossword.array.forEach(function (element, i) {
xmldata.allcrosswords.StateCrossword.array[i].game.array.forEach(function (element, j) {
saveData(data);
counter++;
});
});
}
status.success("" + counter + " row(s) inserted.");
});
},
error: function (httpResponse) {
status.error('Request failed with response code ' + httpResponse.status);
}
});
XML is below:
<allcrosswords>
<StateCrossword UserId="223943">
<game game_name="History CrossWord">
<crossword_date_played>02/01/2014</crossword_date_played>
<words_wrong>2</words_wrong>
<total_score>110</total_score>
</game>
</StateCrossword>
<StateCrossword StateCrossword UserId="4894734">
<game game_name="Sports Crossword">
<crossword_date_played>04/16/2015</crossword_date_played>
<words_wrong>10</words_wrong>
<total_score>12</total_score>
</game>
</StateCrossword>
<StateCrossword StateCrossword UserId="6092735">
<game game_name="Movies Crossword">
<crossword_date_played>08/04/2014</crossword_date_played>
<words_wrong>12</words_wrong>
<total_score>0</total_score>
</game>
</StateCrossword>
</allcrosswords>