Exforsys

Home arrow Technical Training arrow XML Tutorials

XML - Elements in Document Type Definitions (DTD)

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

XML - Elements in Document Type Definitions (DTD)

In this tutorial you will learn about Elements in DTD, Elements, child elements (nested elements), declaring elements with character data only, declaring elements with mixed content, declaring elements with any content, declaring elements with no content and element order indicators and qualifiers.

Ads

Elements in DTD.

ELEMENTS

Every element used in the valid XML document must be declared in the Document’s DTD.

SYNTAX : < !ELEMENT element_name content_specification >

element_name: Specifies name of the XML tag
Content_specification: Specifies the contents of the element which could of the following five types

I) Standard Content
II) Only Character Data
III) Mixed Content
IV) AnyType of Content
V) No Content

CHILD ELEMENTS (NESTED ELEMENTS)

Most Element declarations define one or more child elements.

For Example, < !ELEMENT customer (customer_name) >

Here , Element customer contains one and only one nested element i.e. customer_name

< !ELEMENT Address (Name, Street, City) >

Here, element Address contains three nested elements Name, Street and City respectively

SYNTAX: < !ELEMENT parent (child) >

OR

< !ELEMENT parent (child1,child2, . . . , childN) >

DECLARING ELEMENTS WITH CHARACTER DATA ONLY

Top level elements generally contain other elements but low-level elements may contain parsed character data. In XML, #PCDATA is the keyword to declare elements with parsed character data. An element declared as #PCDATA
Can contain character data
Can contain Entities such as <, >
Cannot contain other elements

SYNTAX < !ELEMENT element_name (#PCDATA) >

Example:

< !ELEMENT Street (#PCDATA) >

• Element Street contains the parsed character data

#CDATA is another keyword to declare character data. But unlike #PCDATA, whitespaces are retained as it is in #CDATA.

Ads

SYNTAX < !ELEMENT element_name (#CDATA) >

Example: < !ELEMENT City (#CDATA) >

Here, DTD declares the City element to contain character data.
In XML, document < City > London < /City >
The XML, parse will take take the data as “ London ” and not as “London”
as in the case of #PCDATA

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