|
XML - Elements in Document Type Definitions (DTD) |
|
Page 2 of 3
.
.
DECLARING ELEMENTS WITH MIXED CONTENT
At times it is required to declare elements with mixed content i.e. both data and other elements. In such situations the pipe symbol (|) is used.
SYNTAX < !ELEMENT parent (#CDATA or #PCDATA,child1,child2, . . . , childN) >
Example:
< bank >
This account is Active
< account >123456< /account >
This account is Closed
< account >423578< /account >
< /bank >
DECLARING ELEMENTS WITH ANY CONTENT
In Real world scenarios, the developer is many a times not sure about the exact document structure while creating the DTD. At such times, ANY keyword comes handy. An element declared as ANY can
- Contain child elements
- Contain character data
- Contain mixed content
SYNTAX: < !ELEMENT element_name ANY >
DECLARING ELEMENTS WITH NO CONTENT
Sometimes it is required that an elements has only attributes but no data. In such scenarios the EMPTY keyword is used.
SYNTAX : < !ELEMENT element_name EMPTY >
ELEMENT ORDER INDICATORS AND QUALIFIERS
The various order and qualification governing symbols are listed in the table append below
|
TYPE
|
VALUE
|
CONTEXT
|
DESCRIPTION
|
|
ORDER
|
|
|
Choice
|
Either one child element or another can occur
|
|
|
()
|
Group
|
Groups related elements together
|
|
|
,
|
Sequence
|
Element must follow another element
|
|
QUALIFIER
|
?
|
Optional
|
Elements appear once or not at all
|
|
|
*
|
Optional and Repeatable
|
Elements appear zero or more times
|
|
|
+
|
Required and Repeatable
|
Elements appear one or more times
|
EXAMPLES:
The pipe symbol (|) specifies choice. So occurrence of either of the chiold element is considered valid by the parser.
Following declaration specifies that name must contain either first_name or last_name
< !ELEMENT name (fist_name | last_name) >
Thus,
< name >
< first_name >Nick< /first_name >
< /name >
as well as
< name >
< last_name >Price< /last_name >
< /name >
are valid.
|