Magazine
 

XML : DTD

 

Declaring Zero or One Occurrence of an Element

<!ELEMENT element-name (child-name?)>

DTD Example:

<!ELEMENT color (Fill-Red?)>

The ‘?’ sign in the example above declares that the child element “Fill-Red” can occur zero or one time inside the “color” element.

Declaring either/or Content
DTD Example:

<!ELEMENT E-mail
(To,From,Subject,(Message|Body))>

The example above declares that the “E-mail” element must contain a “To” element, a “From” element, a “Subject” element, and either a “Message” or a “Body” element.
Declaring Mixed Content

DTD Example:

<!ELEMENT Email(#
PCDATA|To|From|Subject|Body)*>

The example above declares that the “E-mail” element can contain zero or more occurrences of a parsed character data, “To”, “From”, “Subject”, or “Body” elements.

4. DTD-Attributes

In a DTD, attributes are declared with an ATTLIST declaration.

Declaring Attributes

The ATTLIST declaration defines the element having a attribute with attribute name , attribute type , and attribute default value. An attribute declaration has the following syntax:

 
<!ATTLIST element-name attribute-name attribute-type default-value>

DTD example:

<!ATTLIST reciept type CDATA “check”>
XML example:
<reciept type=”check” />

Attribute-type

The attribute-type can be one of the following:

Type Description

CDATA The value is character data
(en1|en2|..) The value must be one from an
enumerated list
ID The value is a unique id
IDREF The value is the id of another element
IDREFS The value is a list of other ids
NMTOKEN The value is a valid XML name
NMTOKENS The value is a list of valid XML
names
ENTITY The value is an entity
ENTITIESThe value is a list of entities
NOTATION The value is a name of a notation
xml The value is a predefined xml value

Default-value

The default-value can be one of the following:
Value Explanation
value The default value of the attribute
#REQUIRED The attribute is required
#IMPLIED The attribute is not required
#FIXED value The attribute value is fixed

A Default Attribute Value

DTD Example:

<!ELEMENT Scale EMPTY>
<!ATTLIST Scale length CDATA “0”>

In the example above, the DTD defines a

Jan  2008 | Java Jazz Up |33
 
previous
index
next
 
View All Topics
All Pages of this Issue
Pages: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29,

30
, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53 , 54, 55, 56, 57,

58
, 59, 60, 61, 62, 63 , 64, 65 , 66 , 67 , 68 , 69 , 70 , 71 , 72 , 73 , 74 , 75 , 76 , 77 , 78 , 79 , 80 , 81 , 82 ,

83, 84 , 85 , 86, 87 , 88, 89 , 90 , 91 , 92 , 93 , 94 , 95 , 96 , 97 , 98 , 99 , 100 , 101 , 102 , 103, 104 , 105 ,

106, 107,

Download PDF