Я почему-то не могу понять, как пройти через этот xml. Я могу получить данные из первых родительских узлов и дочерних узлов под ним, но не могу заставить его перейти ко второму родительскому узлу. Любая помощь будет большой. Я использую xmlReader.Loop через XML в Javascript
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 ниже:
<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>
Измените свой вопрос и опубликуйте образец XML, который вы пытаетесь проанализировать. – dartonw
Только что добавил, мои извинения! –
см. Этот пост, он должен помочь http://stackoverflow.com/questions/14782408/xml-jquery-reading – faljbour