WebService (2)-DTD of the XML series, webservice-xml

Source: Internet
Author: User

WebService (2)-DTD of the XML series, webservice-xml
Source code download: Link: http://pan.baidu.com/s/1jGzSw5o password: ftgw A. Definition

Document Type Definition DTD (Document Type Definition) is used to detect whether XML complies with syntax rules.

Ii. Instance

Two Methods of document type declaration:

1. Internal Definition

Persons. xml file

<? Xml version = "1.0" encoding = "UTF-8"?> <! -- <! DOCTYPE root element [element Declaration]> --> <! DOCTYPE persons [<! -- Common control operator :?: 0-1; *: 0-N; +: 1-N; default: 1 --> <! ELEMENT persons (person +)> <! ELEMENT person (name, password, age)> <! -- # PCDATA is a term used by the XML parser to parse text data --> <! -- CDATA appears in the attribute declaration --> <! ELEMENT name (# PCDATA)> <! ELEMENT password (# PCDATA)> <! ELEMENT age (# PCDATA)> <! -- # The REQUIRED attribute value is REQUIRED --> <! -- # The IMPLIED attribute is not required --> <! -- # The FIXED value attribute value is FIXED --> <! -- The ID value is a unique id --> <! ATTLIST person id # REQUIRED> <! -- The CDATA value is character data --> <! ATTLIST person email CDATA # REQUIRED>]> <persons> <person id = "p1070541038" email = "452274335@qq.com"> <name> Zhao Li Jing </name> <password> 000000 </password> <age> 26 </age> <! -- <Id> p1070541038 </id> --> <! -- Incorrect syntax --> <! -- <Email> 452274335@qq.com </email> --> </person> <person id = "p2070541038" email = "552274335@qq.com"> <name> Zhao Li Kai </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 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 located outside the XML source file, it should be encapsulated in a DOCTYPE definition using the following syntax: --> <! 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> <id> studentid2 </id> <name> studentname2 </name> <age> studentage2 </age> </student> </students> </classroom>

Iii. Comments 1. Advantages:

Simple and Easy to write.

Check whether XML is valid

2. Disadvantages:
1) different from XML syntax
2) provides a limited number of data types, and users cannot customize the data types.

3) The domain name mechanism is not supported


Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.

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.