XML与DTD约束的例子- 产品目录DTD

IT程序员开发必备-各类资源下载清单,史上最全IT资源,个人收藏总结!

product.dtd文件:

<!--

   产品目录DTD

-->

<!ENTITY table "课桌">

<!ENTITY price "100.0">

<!ENTITY street "唐人街">

<!ENTITY % product "specifications+,options?">

<!ENTITY % category "(HandTool|Table|Shop-Professional)">

<!ELEMENT catalog (product+)>

<!ELEMENT product (%product;,price+,notes?)>

<!ELEMENT specifications (#PCDATA)>

<!ELEMENT options (#PCDATA) >

<!ELEMENT price (#PCDATA)>

<!ELEMENT notes (#PCDATA)>

<!ATTLIST catalog id ID #REQUIRED>

<!ATTLIST product name CDATA #IMPLIED

                  category %category; "HandTool"

                  partnum CDATA #IMPLIED

                  plant (Pittsburgh|Milwaukee|Chicago) "Chicago"

                  inventory CDATA #FIXED "InStock"

                  

>

<!ATTLIST specifications weight CDATA #IMPLIED 

                         power CDATA #IMPLIED                     

>

<!ATTLIST options finish (Metal|Polished|Matte) "Matte" 

                  adapter (Included|Optional|NotApplicable) "Included"

                  case (HardShell|Soft|NotApplicable) "HardShell"

>

<!ATTLIST price msrp CDATA #IMPLIED

wholesale CDATA "全部"

street CDATA #IMPLIED

shipping CDATA #IMPLIED

>

product.xml文件:

<?xml version="1.0" encoding="utf-8"?>

<!DOCTYPE catalog SYSTEM "product.dtd">

<catalog id="cata1">

   <product category="HandTool">

      <specifications weight="2.0kg">扳手</specifications>

      <price street="香港街">80.0</price>

      <notes>这是扳手</notes>

   </product>

   <product category="Table">

       <specifications>&table;</specifications>

       <price street="&street;" wholesale="部分">&price;</price>

   </product>

</catalog>


你可能感兴趣的:(XML与DTD约束的例子- 产品目录DTD)