xml之dtd约束

dtd分类:
 内部dtd:在xml内部定义dtd
 外部dtd:在外部文件中定义dtd
  * 本地dtd文件:<!DOCTYPE students SYSTEM "student.dtd">
  * 网络dtd文件:<!DOCTYPE students PUBLIC "名称空间" "student.dtd">

dtd示例:

1 <!ELEMENT students (student*) >
2 <!ELEMENT student (name,age,sex)>
3 <!ELEMENT name (#PCDATA)>
4 <!ELEMENT age (#PCDATA)>
5 <!ELEMENT sex (#PCDATA)>
6 <!ATTLIST student number ID #REQUIRED> 
student.dtd
 1 <?xml version="1.0" encoding="UTF-8" ?>
 2 <!DOCTYPE students SYSTEM  "student.dtd">
 3 
 4 <students>
 5     <student number="s0001">
 6         <name>张三</name>
 7         <age>22</age>
 8         <sex></sex>
 9     </student>
10     <student number="s0002">
11         <name>李四</name>
12         <age>32</age>
13         <sex></sex>
14     </student>
15 </students>
student.xml

 

posted @ 2017-03-31 17:34  Garvey  阅读(128)  评论(0编辑  收藏  举报