私は XML コーディングの初心者であり、スキルの向上を支援するために現在サイトに取り組んでいます。ページのすべての構文が正しいと思いますが、機能していないようです。インデックス ページのコードと、使用しようとしている xml ファイルを次に示します。
<html>
<body>
<script type="text/javascript">
var link= "http://api.remix.bestbuy.com/v1/stores(area(55423,10))+products(name=playstation*)?show=storeId,name,products.sku,products.name&page=1&apiKey=ydpyq9h9cmpmzaakbawv9mzk";
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.open("GET","test.xml",false);
xmlhttp.send();
xmlDoc=xmlhttp.responseXML;
document.write("<table border='1'>");
var x = xmlDoc.getElementsByTagName("name");
for (i=0;i<5;i++)
{
document.write("<tr><td>");
document.write(x[i].getElementsByTagName("name")[0].childNodes[0].nodeValue);
document.write("Step 2");
document.write("</td><td>");
document.write(x[i].getElementsByTagName("distance")[0].childNodes[0].nodeValue);
document.write("</td></tr>");
}
document.write("</table>");
</script>
</body>
</html>
ベストバイリクエストのサンプルから得たXML
<stores warnings="Distances are in terms of miles (default). Your product criteria matches too many records. That exceeds number of records that we allow on the product side of a store-product query. We've automatically truncated the products down to the first 100. These results are not complete. Avoid this by narrowing the number of products in your query." currentPage="1" totalPages="1" from="1" to="10" total="10" queryTime="0.015" totalTime="0.153" canonicalUrl="/v1/stores(area("55423",10))+products(name="playstation*")?show=storeId,name,products.sku,products.name&apiKey=ydpyq9h9cmpmzaakbawv9mzk" partial="false">
<store>
<storeId>281</storeId>
<name>Richfield</name>
<products>
<product>
<sku>9984133</sku>
<name>Assassin's Creed Brotherhood - PlayStation 3</name>
</product>
<product>
<sku>7917141</sku>
<name>Assassin's Creed Greatest Hits - PlayStation 3</name>
</product>
<product>
<sku>2613621</sku>
<name>Assassin's Creed: Revelations - PlayStation 3</name>
</product>
<product>
<sku>3109269</sku>
<name>Assassin's Creed: Revelations Collector's Edition (Game Guide) - Xbox 360, PlayStation 3, Windows</name>
</product>
<product>
<sku>3109065</sku>
<name>Assassin's Creed: Revelations The Complete Official Guide (Game Guide) - Xbox 360, PlayStation 3, Windows</name>
</product>
<product>
<sku>9927337</sku>
<name>Batman: Arkham Asylum Game of the Year Edition - PlayStation 3</name>
</product>
<product>
<sku>3116162</sku>
<name>Batman: Arkham City (Signature Series Game Guide) - Windows, PlayStation 3, Xbox 360</name>
</product>
<product>
<sku>5260722</sku>
<name>Batman: Arkham City - Game of the Year Edition - PlayStation 3</name>
</product>
<product>
<sku>2173056</sku>
<name>Batman: Arkham City - PlayStation 3</name>
</product>
<product>
<sku>3550073</sku>
<name>Battlefield 3 (Game Guide) - Xbox 360, PlayStation 3, Windows</name>
</product>
</products>
</store>
</stores>