アマゾン壱番書店プログラム
shopObj = new Object();
shopObj.count = 0;
shopObj.code = ["466298","466282","492054","466284","571582","571584"];
shopObj.getXMLData = function() {
var url = shopObj.code[shopObj.count]+".xml?cache="+(new Date()).getTime();
new Ajax.Request(url, { method: "get", onComplete:shopObj.show });
}
shopObj.show = function(httpObj) {
var xmlData = httpObj.responseXML;
var itemList = xmlData.getElementsByTagName("Item");
var bookTitle = itemList[0].getElementsByTagName("Title")[0].firstChild.nodeValue;
var bookLink = itemList[0].getElementsByTagName("DetailPageURL")[0].firstChild.nodeValue;
var bookPrice = itemList[0].getElementsByTagName("Amount")[0].firstChild.nodeValue;
var imageData = itemList[0].getElementsByTagName("SmallImage");
var bookImage = "none.gif";
if (imageData.length > 0) {
bookImage = imageData[0].getElementsByTagName("URL")[0].firstChild.nodeValue;
}
var n = shopObj.code[shopObj.count];
$("link"+n).href = bookLink;
$("img"+n).src = bookImage;
$("price"+n).innerHTML = bookPrice + "円";
$("cat"+n).innerHTML = bookTitle;
shopObj.count++;
if (shopObj.count < shopObj.code.length) shopObj.getXMLData();
}
window.onload = shopObj.getXMLData;
説明などは本書を参考にしてください。JavaScript以外のソースはデータをダウンロードするか本書を参照してください。