myClass.dtd
<!ELEMENT class (stu+)>
<!ELEMENT stu (name,sex,age)>
<!ELEMENT name (#PCDATA)>
<!ELEMENT sex (#PCDATA)>
<!ELEMENT age (#PCDATA)>
myClass.xml
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE class SYSTEM "myClass.dtd">
<class>
<stu>
<name>杨过</name>
<sex>男</sex>
<age>20</age>
<area>11平</area>
</stu>
<stu>
<name>李莫愁</name>
<sex>女</sex>
<age>38</age>
</stu>
</class>
编写一个解析工具
<html>
<head>
<!--自己编写一个简单的解析工具,去解析xml dtd是否配套-->
<script language="javascript">
<!--
var xmldoc = new ActiveXObject("Microsoft.XMLDOM");
xmldoc.validateOnParse = "true";//开启检验
xmldoc.load("myClass.xml");//指定检验哪个xml文件
document.writeln("错误的信息是:"+xmldoc.parseError.reason);
document.writeln("错误的行号是:"+xmldoc.parseError.line);
-->
</script>
</head>
</html>