Difference between DTD and XSD

Difference between DTD and XSD

DTD stands for Document Type Definition

XSD stands for Xml Schema Definition
Markup validation:

Can specify only the root element in the instance document. No ambiguous content support.
Markup validation:

Any global element can be root. No ambiguous content support.
Namespace support :

DTD does not support namespace instead it has its own set of keywords for defining a schema

!DOCTYPE for root tag
!ELEMENT for an element
!ATTLIST for an attribute
!ENTITY for defining variables.
Namespace support :

XSD uses its own set of namespaces and elements for defining the schema.
Code reuse:

Poorly supported. Can use parameter entities.
Code reuse:

Can reuse definitions using named types.
Datatype Support :

No real datatype support. DTD has only #PCDATA as the data type for the elements.(it is used for string datatype)
Datatype Support :

Provides flexible set of datatypes.

1. primitive / fundamental data types:
2. Custom Data types
i. complex type : a data type that contains child elements or attributes and
also the mixed contents
ii. simple type : a data type that contains only values.

Provides multi-field key cross references. No co-occurrence constraints.
Datatype Validation:

In DTD, no such restrictions
Datatype Validation:

XSD allows us to specify restriction on data .

Example: tag. we can write only digits here.

DTD is more suitable for small XML Data ex:bookname,companyname etc.

XSD is used in large XML Data ex: ADO.NET DataSets, Web Services.
Strongly / Weakly typed:

DTD is weaky typed.

DTD lacks strong typing capabilities, and has no way of validating the content to data types.

Strongly / Weakly typed:

XML Schema is strongly typed.

An XML Schema can define the data type of certain elements, and even constrain it to within specific lengths or values. This ability ensures that the data stored in the XML document is accurate.
Provisions of Inline Definitions:

DTD allows inline definitions.

This is good when working with small files, as it allows us to contain both the content and the schema within the same document, but when it comes to larger documents, this can be a disadvantage, as we pull content every time we retrieve the schema. This can lead to serious overhead that can degrade performance.
Provisions of Inline Definitions:

XML Schema does not allow inline definitions

No comments:

Post a Comment