"PHP Basics" XML,DTD Instances

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.