一个简单的 XML解析例子,弄了半天终于可以运行了,记下来;还有点问题,大家帮忙看看;
文档类型定义(myfile.dtd)
<!ELEMENT myfile (title, author)>
<!ELEMENT title (#PCDATA)>
<!ELEMENT author (#PCDATA)>
XML文件(myfile.xml)
<?xml version="1.0" encoding="GB2312"?>
<!DOCTYPE myfile SYSTEM "myfile.dtd">
<myfile>
<title>XML轻松学习手册</title>
<author>ajie</author>
</myfile>
测试页面(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>
</html>
问题:
1,
<?xml version="1.0" standalone="yes" encoding="GB2312"?>
<myfile>
<title>XML轻松学习手册</title>
<author>ajie</author>
</myfile>
把myfile.html改成这样时,到这句nodes = xmlDoc.documentElement.childNodes时报错,提示“缺少对象”;
2,standalone="yes"换成standalone="no"一样的错误
3,
<?xml version="1.0" encoding="GB2312"?>
<myfile>
<title>XML轻松学习手册</title>
<author>ajie</author>
</myfile>
把myfile.html改成这样时可以运行正常;
对这个standalone很是无奈,谁帮忙讲解下;