属性定义attribute
语法格式:
<!ATTLIST 元素名 属性名1 属性值类型 设置说明 属性名1 属性值类型 设置说明 属性名1 属性值类型 设置说明 属性名1 属性值类型 设置说明 >
属性声明举例:
<!ATTLIST 商品 类别 CDATA #required <!--必须的--> 颜色 CDATA #IMPLIED <!--可选的--> >
#FIXED 固定值
#FIXED "页面作者" (不用写)
默认属性(不写的话使用默认值)
属性值类型:
CDATA/ENUMERATED/ID/ENTITY
DTD案例:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE CATALOG [ <!ENTITY AUTHOR "John Doe"> <!ENTITY COMPANY "JD Power Tools,Inc."> <!ENTITY EMAIL "jd@jd-tools.com"> <!ELEMENT CATALOG (PRODUCT+)> <!ELEMENT PRODUCT (SPECIFICATIONS+,OPTIONS?,PRICE+,NOTES?)> <!ATTLIST PRODUCT NAME CDATA #IMPLIED CATEGORY (HandTool|Table|Shop-Professional) "HandTool" PARTNUM CDATA #IMPLIED PLANT (Pittsburgh|Milwaukee|Chicago) "Chicago" INVENTORY (InStock|Backordered|Discontinued) "InStock"> <!ELEMENT SPECIFICATIONS (#PCDATA)> <!ATTLIST SPECIFICATIONS WEIGHT CDATA #IMPLIED POWER CDATA #IMPLIED> <!ELEMENT OPTIONS (#PCDATA)> <!ATTLIST OPTIONS FINISH (Metal|Polished|Matte) "Matte" ADAPTER (Included|Optional|NotApplicable) "Included" CASE (HardShell|Soft|NotApplicable) "HardShell"> <!ELEMENT PRICE (#PCDATA)> <!ATTLIST PRICE MSRP CDATA #IMPLIED WHOLESALE CDATA #IMPLIED STREET CDATA #IMPLIED SHIPPING CDATA #IMPLIED> <!ELEMENT NOTES (#PCDATA)> ]>
<CATALOG>
<PRODUCT>
<SPECIFICATIONS >aa</SPECIFICATIONS>
<OPTIONS>hh</OPTIONS>
<PRICE>34</PRICE>
<NOTES>hh</NOTES>
</PRODUCT>
</CATALOG>