Detailed description of dtd for xml constraint technology

Source: Internet
Author: User
DTD (Document Type Definition) is used to define the legal building module of an XML document. This article briefly introduces the usage of DTD. To learn the complete information, click the w3c tutorial below.

1. DTD official tutorial

#2. xml constraint technology:
DTD constraints: Syntax and functions are relatively simple. Appear first
Schema constraints: the syntax is relatively complex and the functions are relatively powerful. Similar to the xml syntax, Schema constraints appear to replace DTD constraints.

3. DTD introduction:

Document Type Definition (DTD) can define valid XML document building modules. It uses a series of legal elements to define the structure of a document. DTD can be declared in XML documents in a line or used as an external reference.

3.1 How to import a DTD:

1. internal import:

# Import method:# Instance:
  
  
  
  
  ]>
  
   
    
Tove
   
   
    
Jani
   
   
    
Reminder
   Don't forget me this weekend
  
(Row 2) defines this document as a document of the note (root tag) type.
(Row 3) the note element has four elements (tags): "to, from, heading, and body"
(Row 4) define the to element as the "# PCDATA" type
(The fifth line) defines the frome element as the "# PCDATA" type.
(Row 6) defines the heading element as "# PCDATA" type

(Row 7) defines the body element as "# PCDATA" type

External import method:
Local File:

# Import method:# Note. dtd file content:
   
   
   
   
   

Public External import: Generally, public external import is used for projects. for example, the xml file of ssh basically adopts this method.

# Import method:# For example, hibernate. cfg. xml:
3.2DTD syntax:

1. constraint labels
Syntax:

 
   Or
   
Category:
EMPTY tag: EMPTY. The element must be an empty element. for example: :
Common string: (# PCDATA ). It indicates that the content of an element must be a normal string (it cannot contain sub-tags ). For example:

ANY content: ANY. The content of an element can be any content (including sub-tags), for example:

Element content:

Sequence problems:
  : Number of subtags in sequence. problem: tag: required and only appears once. TAG +: at least one tag *: 0 or n. Tag? : 0 or 1 time. Declare content of the "not.../both..." type

2. constraint attributes:
Syntax:


  

Property type:

CDATA: a common string (en1 | en2 |...): indicates the ID of any value. it indicates that the attribute value must be unique in an xml document. The value cannot start with a number.

Default value:

# The REQUIRED attribute value is REQUIRED # The IMPLIED attribute is not REQUIRED # the FIXED value attribute is not REQUIRED, but the attribute value is FIXED.

3.3 The test is as follows:


  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  ]>
  
   
    
Tove
   
   
    
Jani
   
   
    
Reminder
   Don't forget me this weekend
   

The above is a detailed description of the dtd of xml constraint technology. For more information, see other related articles in the first PHP community!

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.