Differences between DTD and XSD.

 Posted by Ddd on 2/8/2011 | Category: Web Services, Remoting Interview questions | Views: 5616 | Points: 40

DTD : Document Type Definition
XSD : Xml Schema Definition:

Both are a set of rules which define the logical structure(schema) of an Xml Document. example: what is the root element, child element, data types of the elements, attributes,primary key,order of the elements are defined using DTD or XSD.

Differences are:-

1)DTD 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.

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

2. XSD enables you to create your own data types,DTD does not enable you to define your own customized data types,

3. XSD also allows you to specifies restriction on data .
example: <price></price> tag. we can write only digits here.

In DTD, no such restrictions.

4:Data Types in XSD
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.

DTD has #PCDATA as the data type for the elements.(it is used for string datatype)

XSD is used in large XML Data ex: ADO.NET DataSets, Web Services.
DTD is more suitable for small XML Data ex:bookname,companyname etc.

Asked In: Many Interviews | Alert Moderator 

Comments or Responses

Login to post response