全体をまとめて保存することはできないかもしれませんが、具体的に必要な情報を取得して配列に整理し、その配列を保存することでデータを保存できます。
function getXML(Your_XML_URL) {
// Build the YQL query
var qryRSS = 'select * from rss where url=' + '"' + feed + '"';
// Initiate the YQL query
$.getJSON("http://query.yahooapis.com/v1/public/yql",
{
// These are the settings for your API call
q: qryRSS,
format: "json"
},
// Take the data you got from the YQL server and output it to the screen. The variable "data" holds the JSON you got back from the YQL server.
function (data) {
var myArrayName = [];
// Create an object for each entry. If you don't want every entry in the XML files you can change data.query.results.item.length to whatever number you want.
for (var i = 0; i < data.query.results.item.length; i += 1) {
var singleEntry = {};
dataLoc = data.query.results.item[i];
var singleEntry.title = dataLoc.title; //You would replace these
var singleEntry.pub = dataLoc.pubDate; //with the names of the tags
var singleEntry.image = dataLoc.thumbnail.url; //in your XML file.
var singleEntry.url = dataLoc.link;
var singleEntry.desc = dataLoc.description;
//Add your object to the array.
myArrayName.push(singleEntry);
}
localStorage.setItem("mySavedItem", JSON.stringify(myArrayName));
});
}
次に、その情報を後で取得できます。
var myXMLArray = JSON.parse(localStorage.getItem("mySavedItem"));
console.log(myXMLArray[0].title);
console.log(myXMLArray[2].pub);