A document type definition (DTD) defines a legitimate XML document building block. It uses a series of legitimate elements to define the structure of the document.
DTDs can be declared in an XML document in rows or as an external reference.
In a DTD, an XML element is declared through an element declaration. The element declaration uses the following syntax:
<?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 >
! 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
PCDATA means the parsed character data (Parsedcharacter), PCDATA is the text that will be parsed by the parser. The text will be examined by the parser entity and tagged
CDATA means character data (Characterdata). CDATA is text that will not be parsed by the parser
<! ELEMENT Note (#PCDATA |to|from|header|message) *[can be suffixed with:?, *, +]>
The above example declares that the "note" element can contain 0 or more occurrences of PCDATA, "to", "from", "header", or "message".
declaring properties
The property declaration uses the following syntax:
<! Attlist element Name Property Name property type default Value >
The following are the options for the property type:
Type description
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 default value parameter can use the following values:
Value explanation
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
Declaring entities
Grammar:
<! Entity entity name "Value of Entities" >