Difference between DTD and XSD

     S.No   DTD                                XSD

     1      Abbreviation:                      Abbreviation:

            DTD stands for Document Type XSD stands             for   Xml     Schema
            Definition                   Definition

     2      Markup validation:                 Markup validation:

            Can specify only the root element Any global element can be root. No
            in the instance document. No ambiguous content support.
            ambiguous content support.

     3      Namespace support :                Namespace support :

            DTD does not support namespace XSD uses its own set of namespaces
            instead it has its own set of and elements for defining the schema.
            keywords for defining a schema

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

     4      Code reuse:                        Code reuse:

            Poorly supported.      Can     use Can reuse definitions using named
            parameter entities.                types.

     5      Datatype Support :                  Datatype Support :

            No real datatype support. DTD Provides flexible set of datatypes.
            has only #PCDATA as the data
            type for the elements.(it is used 1. primitive / fundamental data types:
            for string datatype)              string,decimal,float,boolean
                                              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.

     6      Datatype Validation:               Datatype Validation:

            In DTD, no such restrictions       XSD allows us to specify restriction
on data .

                                                 Example: <price></price> tag. we can
                                                 write only digits here.

      7      Uses:                               Uses:

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

      8      Strongly / Weakly typed:            Strongly / Weakly typed:

             DTD is weaky typed.                 XML Schema is strongly typed.

             DTD       lacks   strong  typing    An XML Schema can define the data
             capabilities, and has no way of     type of certain elements, and even
             validating the content to data      constrain it to within specific lengths
             types.                              or values. This ability ensures that the
                                                 data stored in the XML document is
                                                 accurate.

      9      Provisions of Inline Definitions:   Provisions of Inline Definitions:

             DTD allows inline definitions.      XML Schema does not allow 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.


And, further updates on difference between questions and answers, please visit my blog @
http://onlydifferencefaqs.blogspot.in/

Difference between dtd and xsd

  • 1.
    Difference between DTDand XSD S.No DTD XSD 1 Abbreviation: Abbreviation: DTD stands for Document Type XSD stands for Xml Schema Definition Definition 2 Markup validation: Markup validation: Can specify only the root element Any global element can be root. No in the instance document. No ambiguous content support. ambiguous content support. 3 Namespace support : Namespace support : DTD does not support namespace XSD uses its own set of namespaces instead it has its own set of and elements for defining the schema. keywords for defining a schema example: !DOCTYPE for root tag !ELEMENT for an element !ATTLIST for an attribute !ENTITY for defining variables. 4 Code reuse: Code reuse: Poorly supported. Can use Can reuse definitions using named parameter entities. types. 5 Datatype Support : Datatype Support : No real datatype support. DTD Provides flexible set of datatypes. has only #PCDATA as the data type for the elements.(it is used 1. primitive / fundamental data types: for string datatype) string,decimal,float,boolean 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. 6 Datatype Validation: Datatype Validation: In DTD, no such restrictions XSD allows us to specify restriction
  • 2.
    on data . Example: <price></price> tag. we can write only digits here. 7 Uses: Uses: DTD is more suitable for small XSD is used in large XML Data ex: XML Data ADO.NET DataSets, Web Services. ex:bookname,companyname etc. 8 Strongly / Weakly typed: Strongly / Weakly typed: DTD is weaky typed. XML Schema is strongly typed. DTD lacks strong typing An XML Schema can define the data capabilities, and has no way of type of certain elements, and even validating the content to data constrain it to within specific lengths types. or values. This ability ensures that the data stored in the XML document is accurate. 9 Provisions of Inline Definitions: Provisions of Inline Definitions: DTD allows inline definitions. XML Schema does not allow 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. And, further updates on difference between questions and answers, please visit my blog @ http://onlydifferencefaqs.blogspot.in/