1,建立一个学生名册的xml
<?xml version="1.0" encoding="gb2312"?>
<!DOCTYPE studentregister SYSTEM "C:\Users\Administrator\Desktop\Untitled10.dtd">
<studentregister>
<student number="A1">
<name>张三</name>
<sex>男</sex>
<age>20</age>
</student>
<student number="A2">
<name>李四</name>
<sex>女</sex>
<age>19</age>
</student>
<student number="A3">
<name>王二</name>
<sex>男</sex>
<age>21</age>
</student>
</studentregister>
对于dtd
<!DOCTYPE studentregister SYSTEM "C:\Users\Administrator\Desktop\Untitled10.dtd">是用来寻找所对应的外部dtd
加*允许出现0到多次
<?xml version="1.0" encoding="UTF-8"?>
<!ELEMENT studentregister (student*)>
<!ELEMENT student (name,sex,age)>
<!ATTLIST student number NMTOKEN #REQUIRED>
<!ELEMENT name (#PCDATA)>
<!ELEMENT sex (#PCDATA)>
<!ELEMENT age (#PCDATA)>
2.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE NEWSPAPER SYSTEM "C:\Users\Administrator\Desktop\Untitled12.dtd">
<NEWSPAPER>
<ARTICLE AUTHOR="we" EDITOR="we" DATE="rf" EDITION="rf">
<HEADLINE>&NEWSPAPE;</HEADLINE>
<BYLIVE>&PUBLISHER;</BYLIVE>
<LEAD>©RIGHT;</LEAD>
<BODY>rf</BODY>
<NOTES>rf</NOTES>
</ARTICLE>
</NEWSPAPER>
对应的dtd
<!ENTITY NEWSPAPE "vervet Logic Times">是实体的引用内容,在对应xml中,实体引用时记得加&,记得命名,记得最后加上“;”,
“+”表示1到多次出现;
<?xml version="1.0" encoding="UTF-8"?>
<!ELEMENT NEWSPAPER (ARTICLE+)>
<!ELEMENT ARTICLE (HEADLINE,BYLIVE,LEAD,BODY,NOTES)>
<!ELEMENT HEADLINE (#PCDATA)>
<!ELEMENT BYLIVE (#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 NEWSPAPE "vervet Logic Times">
<!ENTITY PUBLISHER "vervet Logic Press">
<!ENTITY COPYRIGHT "Copyright 1998 Vervet Logic Press">