2006/03/31 | JavaScript parse XML
类别(Other) | 评论(0) | 阅读(605) | 发表于 17:01

Framework of XML:

<?xml version="1.0" encoding="gb2312"?>
<guestbook>
<book date="2006-3-27">
<name>veteran</name>
<title>welcome to our guestbook</title>
<msg>
<![CDATA[
welcome to our
]]>
</msg>
</book>
<book date="2006-3-26">
<name>veteran</name>
<title>welcome to our guestbook</title>
<msg>
<![CDATA[
welcome to our
]]>
</msg>
</book>
</guestbook>

Js code:

<script language="javascript" for="window" event="onLoad">
var xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.async=false;
xmlDoc.load("guestbook.xml");

node=xmlDoc.selectNodes("/guestbook/book");
for(var i=0;i<node.length;i++){
len=node[i].childNodes.length;
document.write(node[i].getAttribute("date")+"<br>");
for(var j=0;j<len;j++){
document.write(node[i].childNodes[j].text+"<br>");
}
}
</script>

Download the xml file
0

评论Comments

日志分类
首页[185]
Flash[123]
ColdFusion[2]
Flex[2]
FlashMedia[3]
RIA[4]
Other[43]
Python[0]
Design[8]