用html显示xml中的数据

作者:网络 来源:佚名 更新时间:2008-05-08 10:22:59 点击:


收集最实用的网页特效代码!

1.将下面文件存为myfile.dtd
<!element myfile (title, author)>
<!element title (#pcdata)>
<!element author (#pcdata)>

2.然后建立xml文档myfile.xml:
<?xml version="1.0" encoding="gb2312"?>
<!doctype myfile system "myfile.dtd">
<myfile>
<title>xml轻松学习手册</title>
<author>ajie</author>
</myfile>

3.建立html文档myfile.html
<html>
<head>
<script language="javascript" for="window" event="onload">
var xmldoc = new activexobject("microsoft.xmldom");
xmldoc.async="false";
xmldoc.load("myfile.xml");
nodes = xmldoc.documentelement.childnodes;
title.innertext = nodes.item(0).text;
author.innertext = nodes.item(1).text;
</script>
<title>在html中调用xml数据</title>
</head>
<body bgcolor="#ffffff">
<b>标题: </b>
<span id="title"></span><br>
<b>作者: </b>
<span id="author"></span><br>
</body>