首页 > 代码库 > XML内部DTD约束

XML内部DTD约束

<?xml version="1.0" encoding="UTF-8"?>
<!-- 内部DTD  -->
<!-- XML:extensible markup language 可扩展标记语言  -->
<!-- DTD约束:document type definition 文档类型定义 -->
<!-- + 1~n  * 0~n  ? 0~1 -->
<!-- The markup declarations contained or pointed to by the
 document type declaration must be well-formed. 
 排错最佳方案:XML有错误  注释全部 一个一个排错 注意空格和叹号-->
 <!-- CDATA 说明属性   PCDATA 说明元素 -->
<!DOCTYPE product [
    <!ELEMENT product (item+)>
    <!ELEMENT item (name,price,color,size,stock)>
    <!ATTLIST item id CDATA #REQUIRED>
    <!ELEMENT name (#PCDATA)>
    <!ELEMENT price (#PCDATA)>
    <!ELEMENT color (#PCDATA)>
    <!ELEMENT size (#PCDATA)>
    <!ELEMENT stock (#PCDATA)>
]>
<product>
    <item id = "P001">
        <name>蜘蛛王皮鞋</name>
        <price>268</price>
        <color>黑色</color>
        <size>42</size>
        <stock>500</stock>
    </item>
    <item id = "P002">
        <name>好皮鞋</name>
        <price>88</price>
        <color>蓝色</color>
        <size>42</size>
        <stock>100</stock>
    </item>
</product>

 

XML内部DTD约束