Requirement One: Can read the DTD file written by others, you can write better. For example PRODUCTS.DTD:
1 <!ENTITY AUTHOR "John Doe">2 <!ENTITY Company "JD Power Tools, Inc.">3 <!ENTITY Email "[Email protected]">4 5 <!ELEMENT CATALOG (product+)>6 7 <!ELEMENT PRODUCT8 (specifications+,options?,price+,notes?)>9 <!attlist PRODUCTTen NAME CDATA #IMPLIED One CATEGORY (handtool| table| shop-professional) "Handtool" A PARTNUM CDATA #IMPLIED - PLANT (pittsburgh| milwaukee| Chicago) "Chicago" - INVENTORY (instock| backordered| Discontinued) "Instock"> the - <!ELEMENT Specifications (#PCDATA)> - <!attlist Specifications - WEIGHT CDATA #IMPLIED + POWER CDATA #IMPLIED> - + <!ELEMENT OPTIONS (#PCDATA)> A <!attlist OPTIONS at FINISH (metal| polished| Matte) "Matte" - ADAPTER (included| optional| notapplicable) "Included" - Case (hardshell| Soft| notapplicable) "Hardshell"> - - <!ELEMENT Price (#PCDATA)> - <!attlist Price in MSRP CDATA #IMPLIED - wholesale CDATA #IMPLIED to STREET CDATA #IMPLIED + SHIPPING CDATA #IMPLIED> - the <!ELEMENT NOTES (#PCDATA)>
Requirement Two: Can write according to the DTD file that the person writes conforms to the standard XML file, Products.xml
1 <?XML version= "1.0" encoding= "Utf-8"?>2 <!DOCTYPE CATALOG SYSTEM "Products.dtd">3 <CATALOG>4 <PRODUCTNAME= "Refrigerator"CATEGORY= "Handtool"PLANT= "Chicago"INVENTORY= "Discontinued">5 <SpecificationsWEIGHT= "80kg"POWER= "1000w">This is a domestic Haier refrigerator</Specifications>6 < Price>1000</ Price>7 <NOTES>Take it lightly.</NOTES>8 </PRODUCT>9 </CATALOG>
Request three: Can test oneself writes the XML file is wrong, checkdtd.html
1 <HTML>2 <Head>3 <title>Test DTD</title>4 <Metahttp-equiv= "Content-type"content= "Text/html;charset=utf-8"/>5 <Scriptlanguage= "JavaScript">6 <!--7 //Create an XML parser8 varxmldoc= NewActiveXObject ("Microsoft.XMLDOM");9 //turn on the check functionTen Xmldoc.validateonparse=true; One //specifies which XML file to validate A Xmldoc.load ("Products.xml"); - //If there is an error message, the output - document.write ("error message ="+Xmldoc.parseError.reason+"<br/>"); the document.write ("the line number of the error ="+Xmldoc.parseError.line+"<br/>"); - - // - - </Script> + </Head> - </HTML>
When the above code is written, we should pay attention to the same encoding Utf-8
"PHP Basics" XML,DTD Instances