"WebService" (ii) the DTD of XML

Source: Internet
Author: User
Tags cdata control characters unique id xml parser

I. Definition

The document type defines a DTD, which is specifically used to detect whether the XML conforms to the syntax rules.

Two. Example

Two ways to declare a document type:

1. Internal definition

Persons.xml file

<?xml version= "1.0" encoding= "UTF-8"?><!--<! DOCTYPE root element [element declaration]>--><! DOCTYPE persons[<!--commonly used control characters:?  : 0-1 times;  *:0-n times; +:1-n times; Default: 1 times--><! ELEMENT persons (person+) ><! ELEMENT person (name, password, age) ><!--#PCDATA is a term used by the XML parser to parse the text data--><!--CDATA appears in the property declaration--><! ELEMENT name (#PCDATA) ><! ELEMENT password (#PCDATA) ><! ELEMENT Age (#PCDATA) ><!--#REQUIRED属性值是必需的--><!--#IMPLIED属性不是必需的--><!--The Value property values are fixed-- ><!--ID value is a unique ID--><! ATTLIST Person ID ID #REQUIRED ><!--CDATA value is character data (character)--><! attlist person Email CDATA #REQUIRED >]><persons><person id= "p1070541038" email= "[email protected ] "><name> Zhaoli </name><password>000000</password><age>26</age><!--< id>p1070541038</id>--><!--Error--><!--<email>[email protected]</email>-- ></person><person id= "p20705410"Email=" [email protected] "><name> Zhaoli </name><password>000000</password>< Age>26</age></person></persons>
2. External definition

CLASSROOM.DTD file

<?xml version= "1.0" encoding= "UTF-8"? ><! ELEMENT Classroom (name,grade,students) ><! Attlist Classroom ID #REQUIRED ><! ELEMENT name (#PCDATA) ><! ELEMENT Grade (#PCDATA) ><! ELEMENT students (student+) ><! ELEMENT Student (Id,name,age) ><! ELEMENT ID (#PCDATA) ><! ELEMENT name (#PCDATA) ><! ELEMENT Age (#PCDATA) >

Classroom.xml file

<?xml version= "1.0" encoding= "UTF-8"?><!--External Document declaration--><!--if the DTD is outside the XML source file, it should be encapsulated in a DOCTYPE by the following syntax Righteousness in:--><! DOCTYPE classroom  SYSTEM "CLASSROOM.DTD" ><classroom id= "Classroomid1" ><name>classname1</ name><grade>grade1</grade><students><student><id>studentid1</id>< Name>studentname1</name><age>studentage1</age></student><student><id> Studentid2</id><name>studentname2</name><age>studentage2</age></student> </students></classroom>

three. Reviews1. Advantages:

Simple and straightforward, easy to write.

To detect if XML is valid

2. Disadvantages:
1) different from XML syntax
2) Provide a limited number of data types that users cannot customize

3) does not support the domain name mechanism


"WebService" (ii) the DTD of XML

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.