js取xml的数据2

 

新建站点“Phoenix”

在根目录下新建一个页面“js取xml的数据.html”:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>js取xml的数据</title>
<SCRIPT LANGUAGE="JavaScript" FOR="window" EVENT="onload">
start();
</SCRIPT>
<SCRIPT LANGUAGE="JavaScript">
var xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.async=false;//是否允許非同步下載,false为不允许
xmlDoc.load("xml/email.xml");
function start(){
var root=xmlDoc.documentElement;
todata.innerText=root.childNodes.item(0).text
fromdata.innerText=root.childNodes.item(1).text
ccdata.innerText=root.childNodes.item(2).text
subjectdata.innerText=root.childNodes.item(3).text
bodydata.innerText=root.childNodes.item(4).text
}
</SCRIPT>
</HEAD>

<BODY>
<B>To:</B><SPAN ID="todata"></SPAN><BR><!--通过这些ID,显示上面从xml里面取出来的数据-->
<B>From:</B> <SPAN ID="fromdata"></SPAN><BR>
<B>CC:</B> <SPAN ID="ccdata"></SPAN><BR>
<B>Subject:</B> <SPAN ID="subjectdata"></SPAN><BR>
<B>Body:</B> <SPAN ID="bodydata"></SPAN><BR>
</BODY>
</HTML>

 

在Phoenix下建一文件夹“xml”。文件夹xml里面新建一xml文件“email.xml”:

<?xml version="1.0" encoding="utf-8"?>
<EMAIL>
<TO>Bill_Pardi@hotmail.com</TO>
<FROM>Eric_Schurman@hotmail.com</FROM>
<CC>DHTML_in_Action@hotmail.com</CC>
<SUBJECT>Basic email</SUBJECT>
<BODY>This is an XML-based email.</BODY>
</EMAIL>
然后,运行页面“js取xml的数据.html”,将得到如下结果:

To:Bill_Pardi@hotmail.com
From: Eric_Schurman@hotmail.com
CC: DHTML_in_Action@hotmail.com
Subject: Basic email
Body: This is an XML-based email

 

这是用js去读xml里面的单个node的内容,下面将有读取多个的例子。
url_001=javascript:goURL(1);
&url_001=javascript:goURL(1);&txt02=http://www.knowsky.com&img_002=images/02.jpg&url_002=javascript:goURL(2);&txt03=http://www.knowsky.com&img_003=images/03.jpg&url_003=javascript:goURL(3);&txt04=http://www.knowsky.com&img_004=images/04.jpg&url_004=javascript:goURL(4);&txt05=http://www.knowsky.com&img_005=images/05.jpg&url_005=javascript:goURL(5);" /><PARAM NAME=quality VALUE=high><PARAM NAME=bgcolor VALUE=#C0E2D2><EMBED src="flash/flashview.swf" quality=high bgcolor=#C0E2D2 WIDTH="285" HEIGHT="190" ALIGN="" TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer"></EMBED></OBJECT>
&txt02=http://www.knowsky.com&txt03=http://www.knowsky.com&txt04=http://www.knowsky.com&txt05=http://www.knowsky.com&img_002=images/02.jpg&img_003=images/03.jpg&img_004=images/04.jpg&img_005=images/05.jpg&url_001=javascript:goURL(1);&url_002=javascript:goURL(2);&url_003=javascript:goURL(3);&url_004=javascript:goURL(4);&url_005=javascript:goURL(5);" /><PARAM NAME=quality VALUE=high><PARAM NAME=bgcolor VALUE=#C0E2D2><EMBED src="flash/flashview.swf" quality=high bgcolor=#C0E2D2 WIDTH="285" HEIGHT="190" ALIGN="" TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer"></EMBED></OBJECT>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

感谢一路走过的人

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值