Exforsys

Home arrow Technical Training arrow XML Tutorials

XML - Elements in Document Type Definitions (DTD) Page - 2

Page 2 of 3
Author : Exforsys Inc.     Published on: 14th Jun 2006

XML - Elements in Document Type Definitions (DTD)

.

.

Ads

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

ORDER

QUALIFIER

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) >

Ads

Thus,
< name >
< first_name >Nick< /first_name >
< /name >

as well as

< name >
< last_name >Price< /last_name >
< /name >

are valid.

Read Next: XML Advantages


 
This tutorial is part of a XML Tutorials tutorial series. Read it from the beginning and learn yourself.

XML Tutorials

 

Comments