JS访问XML的简单例子
来源:互联网 发布:java 释放mysql连接池 编辑:程序博客网 时间:2024/04/30 11:00
JS_XML.htm
<html>
<head>
<script>
var iIndex=-1;
var objectDoc=new ActiveXObject("MSXML2.DOMDocument.3.0");
objectDoc.load("Root.xml");
var objectItem=objectDoc.selectNodes("/Root/Item");
function getNode(objectDoc,strPath)
{
var returnValue="";
var strValue=objectDoc.selectSingleNode(strPath);
if(strValue)returnValue=strValue.text;
return returnValue;
}
function getDataNext()
{
iIndex++;
if(iIndex>objectItem.length-1)iIndex=0;
document.forms[0].ProductTag.value=getNode(objectDoc,"/Root/Item["+iIndex+"]/ProductTag");
document.forms[0].Price.value=getNode(objectDoc,"/Root/Item["+iIndex+"]/PricePer");
document.forms[0].Quantity.value=getNode(objectDoc,"/Root/Item["+iIndex+"]/Quantity");
document.forms[0].Total.value=getNode(objectDoc,"/Root/Item["+iIndex+"]/Subtotal");
}
function getDataPrev()
{
iIndex--;
if(iIndex<0)iIndex=objectItem.length-1;
document.forms[0].ProductTag.value=getNode(objectDoc,"/Root/Item["+iIndex+"]/ProductTag");
document.forms[0].Price.value=getNode(objectDoc,"/Root/Item["+iIndex+"]/PricePer");
document.forms[0].Quantity.value=getNode(objectDoc,"/Root/Item["+iIndex+"]/Quantity");
document.forms[0].Total.value=getNode(objectDoc,"/Root/Item["+iIndex+"]/Subtotal");
}
function init()
{
document.all.XMLTitle.innerText=getNode(objectDoc,"/Root/Cigarette");
document.all.XMLDate.innerText=getNode(objectDoc,"/Root/Date");
}
</script>
</head>
<body onload="init();getDataNext()">
<form>
<div id="XMLTitle"></div>
<br>
<table border="0">
<tr><td>产品名称</td><td><input type="text" name="ProductTag"></td></tr>
<tr><td>产品价格</td><td><input type="text" name="Price"></td></tr>
<tr><td>产品数量</td><td><input type="text" name="Quantity"></td></tr>
<tr><td>金额合计</td><td><input type="text" name="Total"></td></tr>
</table>
<br>
<div id="XMLDate"></div>
<br>
<input type="button" value="<<" onClick="getDataPrev();">
<input type="button" value=">>" onClick="getDataNext();">
</form>
</body>
</html>
Root.xml
<?xml version="1.0" encoding="gb2312"?>
<Root>
<Cigarette>实时价格一览表</Cigarette>
<Item id="1">
<ProductTag>石林(软包)</ProductTag>
<PricePer>3.50</PricePer>
<Quantity>100</Quantity>
<Subtotal>350.00</Subtotal>
<Description>NULL</Description>
</Item>
<Item id="2">
<ProductTag>桂花(白、软包)</ProductTag>
<PricePer>2.50</PricePer>
<Quantity>10</Quantity>
<Subtotal>25.00</Subtotal>
<Description>NULL</Description>
</Item>
<Item id="3">
<ProductTag>一品黄山(硬包)</ProductTag>
<PricePer>5.50</PricePer>
<Quantity>1000</Quantity>
<Subtotal>5500.00</Subtotal>
<Description>NULL</Description>
</Item>
<Item id="4">
<ProductTag>红山茶(硬包)</ProductTag>
<PricePer>3.50</PricePer>
<Quantity>1</Quantity>
<Subtotal>3.50</Subtotal>
<Description>NULL</Description>
</Item>
<Date>08/17/2004</Date>
</Root>
- JS访问XML的简单例子
- JS访问XML的简单例子
- SpringMVC静态文件(图片)访问+js访问 简单小例子
- 简单JS getElementsByName的例子
- JS访问meta和css的例子
- js通过xmldom调用xslt对xml排序输出的一个简单例子.
- 跨域访问的简单例子
- 最简单的Phoenix 访问 HBase例子
- 一个jsp访问mysql的简单例子
- 一个简单的XML Schema的例子
- 一个简单的XML Schema的例子
- 一个简单的XML Schema的例子
- 一个简单的XML Schema的例子
- 一个简单的XML Schema的例子
- Oozie的workflow的xml简单例子
- 客户端JS操作xml的例子
- DOM进行XML读写的简单例子
- 利用XML开发留言板简单的例子
- Linux 核心--6.进程间通讯机制
- LET'S BUILD A COMPILER!(1)
- LET'S BUILD A COMPILER!(2)
- Makefile简单实战
- LET'S BUILD A COMPILER!(3)
- JS访问XML的简单例子
- LET'S BUILD A COMPILER!(4)
- LET'S BUILD A COMPILER!(5)
- Linux嵌入式实时操作系统开发与设计(十)
- 表达式,转换和计算,用C语言描述--Part1
- 表达式,转换和计算,用C语言描述--Part2
- 表达式,转换和计算,用C语言描述--Part3
- 表达式,转换和计算,用C语言描述--Part4(源代码)
- Web上JS利用XMLHTTP实现下载