R4R provide basic DTD Tutorials concept with
DTD Examples .
Through R4R you can develop DTD programming concept. R4R provide
DTD Interview Questions with answers.R4R provide DTD Languages study materials in easy way.
Introduction of DTD
DTD (Document Type Definition )is mostly used in XML for
validating an xml document with the help of some set of rules. DTD defines these
set of rules i.e. defines the legal building blocks of an XML document and
defines document structure with a list of legal elements and attributes. DTD also defines that an xml can contain what elements and in which
order, how the elements should be organized inside the other. It specifies that
an element can contain what attributes.
A DTD can be defined inside an XML document, or an external
reference can be declared.
- Internal DTD: This type of DTD can be included in the target xml file.
- External DTD: External dtd is nothing different from internal
dtd except defining definition in an external file. External DTD can be use
with more than one XML document.
Rules are given below-
1.The document type
declaration must be written in between the XML declaration and the root
element.
2.Keyword DOCTYPE must be
followed by the root element.
3.keyword DOCTYPE must be in
upper case.
Why use DTD?
DTD is very helpful in XML to make description of its own format.
Through DTD, independent groups of people can agree to use a standard DTD
for interchanging data. If you have used DTD in your application then you can
verify that the data you receive from the outside world is valid.You can also
use a DTD to verify your own data.
Difference between DTD and XML Schema-
- DTD can have only two types of data, the CDATA and the PCDATA. But in a
schema you can use all the primitive data type that you use in the programming
language and you have the flexibility of defining your own custom data types.
- Another difference between DTD and XML Schema, is namespace awareness, XML
Schema has, while DTD is not.
- XML Schema has ability to implement strong typing.
- XML Schema has a wealth of derived and built-in data types to validate
content.
- DTD has the ability to define DTDs inline, which XML Schema lacks
- DTD is good when working with small files, as it allows you to contain
both the content and the schema within the same document.
Advantage of DTD-
DTDs are easier to code and validate than an
XML schema. However, the advantages to using an DTD are shown in the following
list:
- Its support is ubiquitous due to its inclusion in the XML 1.0 standard.
- DTD define a document type rather than the types used by a namespace, thus
grouping all constraints for a document in a single collection.
- DTD allow the declaration of standard public entity sets for publishing
characters.
- DTD are terse compared to element-based schema languages and consequently
present more information in a single screen.
Disadvantage of DTD-
- DTD have no explicit support for newer features of XML, most importantly
namespaces.
- DTD use a syntax based on regular expression syntax, inherited from SGML,
to describe the schema.