DTD XML Constraint document
A document type definition (DTD) defines a legitimate XML document building block that uses a series of legitimate elements to define the structure of a document. DTDs can be declared in an XML document in rows or as an external reference.
1. Internal Declaration Documents
<?xml version= "1.0"?>
<! DOCTYPE Note [
<! ELEMENT Note (to,from,heading,body) >
<! ELEMENT to (#PCDATA) >
<! ELEMENT from (#PCDATA) >
<! ELEMENT heading (#PCDATA) >
<! ELEMENT Body (#PCDATA) >
]>
<note>
<to>George</to>
<from>John</from>
<body>don ' t forget the meeting!</body>
</note>
The above DTD is explained as follows:
! DOCTYPE Note (second line) defines this document as a type of note.
! Element Note (line three) defines a note element with four elements: "To, from, heading, body"
! element to (line fourth) defines the to element as "#PCDATA" type
! Element from (line fifth) defines the from element as the "#PCDATA" type
! Element heading (line sixth) defines the heading element as the "#PCDATA" type
! Element body (line seventh) defines the BODY element as the "#PCDATA" type
2. External document Declaration
<?xml version= "1.0"?>
<! DOCTYPE Note SYSTEM "NOTE.DTD" >
<note>
<to>George</to>
<from>John</from>
<body>don ' t forget the meeting!</body>
</note>
This is the "NOTE.DTD" file that contains the DTD:
<! ELEMENT Note (to,from,heading,body) >
<! ELEMENT to (#PCDATA) >
<! ELEMENT from (#PCDATA) >
<! ELEMENT heading (#PCDATA) >
<! ELEMENT Body (#PCDATA)
3.XML Document Building Module
3.1 Elements
3.2 Properties
3.3 Entities
3.4 PCDATA
PCDATA means the parsed character data (parsed character).
You can think of character data as text between the opening and closing tags of an XML element.
PCDATA is the text that will be parsed by the parser. The text will be examined by the parser entity and tagged.
The labels in the text are treated as tokens, and the entities are expanded.
However, the parsed character data should not contain any &, <, or > characters; you need to use &, < and > Entities to replace them separately.
3.5 CDATA
CDATA means character data (character).
CDATA is text that will not be parsed by the parser. The labels in these texts are not treated as tokens, and the entities in them are not expanded.
4.DTD Document Structure
4.1 Elements
<! Element name Category >
<! Element elements name (element content) >
4.1.1 Empty Element
<! Element name Empty>
Elements of the 4.1.2 PCDATA
<! Element name (#PCDATA) >
4.1.3 Elements with any content
<! Element name Any>
4.1.4 Elements with child elements (sequences)
<! element name (child element name 1, child element name 2,.....) >
4.1.5 declare elements that appear only once
<! element name (child element name) >
4.1.6 declare elements that appear at least once
<! element name (child element name +) >
4.1.7 declaration occurs 0 or more times the element
<! element name (child element name *) >
4.1.8 declaration occurs 0 or one time element
<! element name (child element name?) >
4.1.9 Statement "non .../both ..." type of content
<! ELEMENT Note (To,from,header, (message|body)) >
4.1.10 declaring mixed-type content
<! ELEMENT Note (#PCDATA |to|from|header|message) *>
4.2 Properties: Attributes are declared through the Attlist declaration.
4.2.1 syntax
<! Attlist element Name Property Name property type default Value >
4.2.2 The following are options for attribute types:
CDATA value is character data (character)
(en1|en2|.) This value is one of the values in the enumeration list
ID value is a unique ID
IDREF value is the ID of another element
IDREFS value is a list of other IDs
NmToken value is a valid XML name
Nmtokens value is a list of valid XML names
Entity value is a solid
The entities value is a list of entities
NOTATION This value is the name of the symbol
XML: Value is a pre-defined XML value
The 4.2.3 default value parameter can use the following values:
Default value of the Value property
#REQUIRED property value is required
#IMPLIED properties are not required
The value of the #FIXED Value property is fixed
4.3 entities
4.3.1 syntax
Internal entity declaration: <! Entity entity name "Value of Entities" >
External entity declaration: <! Entity entities name SYSTEM "Uri/url" >
4.4 Example
<! DOCTYPE Tvschedule [
<! ELEMENT tvschedule (channel+) >
<! ELEMENT CHANNEL (banner,day+) >
<! ELEMENT BANNER (#PCDATA) >
<! ELEMENT Day (DATE, (holiday| programslot+) +) >
<! ELEMENT HOLIDAY (#PCDATA) >
<! ELEMENT DATE (#PCDATA) >
<! ELEMENT Programslot (time,title,description?) >
<! ELEMENT time (#PCDATA) >
<! ELEMENT TITLE (#PCDATA) >
<! ELEMENT DESCRIPTION (#PCDATA) >
<! Attlist tvschedule NAME CDATA #REQUIRED >
<! Attlist CHANNEL CHAN CDATA #REQUIRED >
<! Attlist programslot VTR CDATA #IMPLIED >
<! Attlist TITLE RATING CDATA #IMPLIED >
<! Attlist TITLE LANGUAGE CDATA #IMPLIED >
]>
The DTD for XML constrained documents