正在加载……
专注、离线、切勿分心
一、根据下面的DTD文档写出XML文件来,并通过验证(把下面的DTD写到单独的文件中)


myDTD.dtd
一、根据下面的DTD文档写出XML文件来,并通过验证(把下面的DTD写到单独的文件中)
<!DOCTYPE NEWSPAPER [
<!ELEMENT NEWSPAPER (ARTICLE+)>
<!ELEMENT ARTICLE (HEADLINE,BYLINE,LEAD,BODY,NOTES)>
<!ELEMENT HEADLINE (#PCDATA)>
<!ELEMENT BYLINE (#PCDATA)>
<!ELEMENT LEAD (#PCDATA)>
<!ELEMENT BODY (#PCDATA)>
<!ELEMENT NOTES (#PCDATA)>
<!ATTLIST ARTICLE AUTHOR CDATA #REQUIRED>
<!ATTLIST ARTICLE EDITOR CDATA #IMPLIED>
<!ATTLIST ARTICLE DATE CDATA #IMPLIED>
<!ATTLIST ARTICLE EDITION CDATA #IMPLIED>
<!ENTITY NEWSPAPER "Vervet Logic Times">
<!ENTITY PUBLISHER "Vervet Logic Press">
<!ENTITY COPYRIGHT "Copyright 1998 Vervet Logic Press">
]> 
<?xml version="1.0" encoding="utf-8"?>
<!ELEMENT NEWSPAPER (ARTICLE+)>
<!ELEMENT ARTICLE (HEADLINE,BYLINE,LEAD,BODY,NOTES)>
<!ELEMENT HEADLINE (#PCDATA)>
<!ELEMENT BYLINE (#PCDATA)>
<!ELEMENT LEAD (#PCDATA)>
<!ELEMENT BODY (#PCDATA)>
<!ELEMENT NOTES (#PCDATA)>
<!ATTLIST ARTICLE AUTHOR CDATA #REQUIRED>
<!ATTLIST ARTICLE EDITOR CDATA #IMPLIED>
<!ATTLIST ARTICLE DATE CDATA #IMPLIED>
<!ATTLIST ARTICLE EDITION CDATA #IMPLIED>
<!ENTITY NEWSPAPER "Vervet Logic Times">
<!ENTITY PUBLISHER "Vervet Logic Press">
<!ENTITY COPYRIGHT "Copyright 1998 Vervet Logic Press">

exam.xml testScript.html
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<exam>
        <student idcard="111" examid="222">
                <name>张三</name>
                <location>沈阳</location>
                <grade>89</grade>
        </student>
        <student idcard="333" examid="444">
                <name>李四</name>
                <location>大连</location>
                <grade>97</grade>
        </student>
</exam>

<script type="text/javascript">
//创建xml文档解析器对象
var xmldoc = new ActiveXObject("Microsoft.XMLDOM");
//开启xml校验
xmldoc.validateOnParse = "true";
//装载xml文档
xmldoc.load("test.xml");
//获取错误信息
var reason=xmldoc.parseError.reason;
var line=xmldoc.parseError.line
document.write("reason = "+reason+"line = "+line);
</script>
posted on 2018-06-14 10:00  正在加载……  阅读(252)  评论(0编辑  收藏  举报