Tutorials
XML
XML - Elements in Document Type Definitions (DTD)
XML - Elements in Document Type Definitions (DTD) - Page 2
XML - Elements in Document Type Definitions (DTD) - Page 3.
.
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 >
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
SYNTAX: < !ELEMENT element_name ANY >
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 >
The various order and qualification governing symbols are listed in the table append below
|
TYPE |
VALUE |
CONTEXT |
DESCRIPTION |
|
| |
Choice |
Either one child element or another can occur |
|
|
() |
Group |
Groups related elements together |
|
|
, |
Sequence |
Element must follow another element |
|
|
? |
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) >
Next Page: XML - Elements in Document Type Definitions (DTD) - Page 3