私はいくつかの詳細を含むxmlファイルを持っています.
<edata updated="2012:12:32.697" product_type_id="3" product_type="epack" headline="Gold Coast" destination="india" localised_destination="Gold Coast" headline_no_html="Gold Coast" price="372" />
<edata updated="2012:12:32.697" product_type_id="3" product_type="epack" headline="Gold Coast" destination="china" localised_destination="Gold Coast" headline_no_html="Gold Coast" price="450" />
これは、xml ファイル内のデータを失った例です。
ヘッダー部分の JavaScript
<script type="text/javascript">
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","edata.xml",false);
xmlhttp.send();
xmlDoc=xmlhttp.responseXML;
</script>
本体部分のコード
<div id="Frame2">
<script type="text/javascript">
function load()
{
alert("Page is loaded");
}
var x=xmlDoc.getElementsByTagName("edata");
document.write("<div>");
document.write(x[0].getAttribute('price'));
document.write("</div>");
</script>
</div>
私のコードは最初の div で最初の edata 値を取得していることに注意してください。条件によって中国の価格値を取得したいと考えています。