我有 xml 文件,其中包含一些详细信息我想从中选择一些值我做了那个 javascript 但我不接近我的要求,我想从条件中选择值。
<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 值我想按条件获得中国价格值。