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 3In 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.
Elements in DTD.
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
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) >
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.
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
Next Page: XML - Elements in Document Type Definitions (DTD) - Page 2