Professional Documents
Culture Documents
DTD - Document Type Definition
DTD - Document Type Definition
DTD - Document Type Definition
DEFINITION
DONE BY:
HARINI.D
IV M.Sc SS
SYNOPSIS:
INTRODUCTION
DTD- DEFINITION
WHEN AND WHY USE DTD?
TYPES OF DTD DECLARATION
DTD- XML BUILDING BLOCKS
CONTENT MODEL
DATA TYPES
ELEMENT TYPE DECLARATIONS
ENTITY TYPE DECLARATIONS
ATTRIBUTE TYPE DECLARATION
SYNOPSIS:
A DTD defines the structure and the legal elements and attributes of an XML document.
It allows the developer to create a set of rules to specify legal content and place restrictions on
an XML file
If the XML document does not follow the rules contained within the DTD, a parser generates an
error
An XML document that conforms to the rules within a DTD is said to be valid.
WHEN AND WHY USE DTD?
With a DTD, independent groups of people can agree to use a standard
DTD for interchanging data.
With a DTD, you can verify that the data you receive from the outside world
is valid.
A single DTD ensures a common format for each XML document that
references it .
An application can use a standard DTD to verify that data that it receives
from the outside world is valid.
<?xml version="1.0"?>
<!DOCTYPE note [
<!ELEMENT note (to,from,heading,body)>
<!ELEMENT to (#PCDATA)>
<!ELEMENT from (#PCDATA)>
<!ELEMENT heading (#PCDATA)>
<!ELEMENT body (#PCDATA)>
]>
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend</body>
</note>
- INTERPRETATION OF DTD:
<?xml version="1.0"?>
<!DOCTYPE note SYSTEM "note.dtd">
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
DTD – XML BUILDING BLOCKS:
Elements
Attributes
Entities
PCDATA
CDATA
• ELEMENTS:
Elements are the main building blocks of both XML and HTML
documents.
Examples:
<body>some text</body>
<message>some text</message>
• ATTRIBUTES:
<img src="computer.gif" />
The name of the element is "img". The name of the attribute is "src".
The value of the attribute is "computer.gif". Since the element itself is
empty it is closed by a " /".
• ENTITIES:
Some characters have a special meaning in XML, like the less than sign (<) that
defines the start of an XML tag.
Most of you know the HTML entity: " ". This "no-breaking-space" entity is
used in HTML to insert an extra space in a document.
Think of character data as the text found between the start tag and the end
tag of an XML element.
Tags inside the text will be treated as markup and entities will be expanded.
However, parsed character data should not contain any &, <, or > characters;
these need to be represented by the & < and > entities,
respectively.
• CDATA:
EMPTY elements
ANY elements
MIXED elements
• EMPTY ELEMENT:
Syntax:
<!ENTITY entity-name "entity-value">
EXAMPLES:
DTD Example:
XML example:
<author>&writer;©right;</author>
• EXTERNAL ENTITY DECLARATION:
SYNTAX:
EXAMPLES
DTD Example:
XML example:
<author>&writer;©right;</author>
ATTRIBUTE TYPE DECLARATION
Invoice Element Declaration:
<?xml version=“1.0” ?>
<!ELEMENT employee (#PCDATA)
HTML Examples:
<h1> align=“center”>An XML Example<h1>
<table width=page> </table>