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>
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>