Difference Between DTD and XSD | DTD vs XSD


Key Difference – DTD vs XSD
 

DTD and XSD are related to XML, which is used for data transfer among its several functions. Most applications require data transfer. When the client machine requires getting data from the server, there should be an effective method to fetch data. XML can be used to achieve this task. It stands for Extensible Markup Language. The main advantage of using XML is to transfer data. Other than that, it can also be used to configure frameworks and for designing the layout for android applications. The tags used in XML are not predefined. The programmer can write the tags according to the application. An XML document contains the structure and the content. In XML, the DTD stands for Document Type Definition and XSD stands for XML Schema Definition. DTD is a set of markup declarations that define a document type for an SGML – family markup language. XSD specifies how to describe the elements in an Extensible Markup Language document formally. The key difference between DTD and XSD is that DTD can be used to define the structure while XSD can be used to define the structure and content.  This article discusses the difference between DTD and XSD.

CONTENTS

1. Overview and Key Difference
2. What is DTD
3. What is XSD
4. Similarities Between DTD and XSD
5. Side by Side Comparison – DTD vs XSD in Tabular Form
6. Summary

What is DTD?

DTD stands for Document Type Definition. It is used to describe XML language precisely. The main objective of DTD is to define the structure of an XML file. It contains a list of legal elements. It is also used to perform validation. There are two types of DTD. They are internal or external. If the DTD elements are declared within the XML file, it is known as internal DTD. If the DTD elements are declared in some other file, it is known as external DTD.

Difference Between DTD and XSD | DTD vs XSD

Figure 01: Internal DTD

According to the above, the elements are declared within the XML file. So, it is an internal DTD. The <! DOCTYPE Student defines that the root element of the document is Student. The <! Element Student (ID, Name, Email) > defines that the Student element consists of three elements that are ID, Name and Email. Each ID, Name and Email are defined separately. They all are parse-able data types. DTD exist from line number 2 to 7. The rest is XML.

Difference Between DTD and XSD | DTD vs XSD

Figure 02: Adding the external DTD file

When the DTD file is saved as student.dtd, it should be added to the XML file. It is done as follows;

<! DOCTYPE Student SYSTEM “student.dtd”>

What is XSD?

XSD stands for XML Schema Definition. It is used to define the structure and the content of XML files. It is a method of expressing constraint of the XML file. XSD is similar to DTD, but it is providing more control on XML structure. There are two types of XSD files. They are simple Type and complex Type. The simpleType allows having text-based elements. It contains fewer attributes, child elements and cannot be left empty. The complexType allows holding multiple attributes and elements. It contains additional sub-elements and can be left empty.

Difference Between DTD and XSD | DTD vs XSD

Figure 03: new1.xsd file

According to the above XSD file, <xs:element name=”Student”> defines that the element name is Student. The <xs:complexType> defines that the element Student is complex type. The <xs:sequence> defines that the complex type is a sequence of elements. The <xs:element name=”ID” type=”xs:string/> defines that the element ID is of string or text type. The name and Email are also of type string or text.

Difference Between DTD and XSD | DTD vs XSD

Figure 04: Student.xml file

Above is the XML file, the location of the new1.xsd file should be included inside xsi:schemaLocation.

What is the Similarity Between DTD and XSD?

  • Both DTD and XSD can be used to define the structure of an XML document.

What is the Difference Between DTD and XSD?

DTD vs XSD

DTD is a set of markup declarations that define a document type for an SGML – family markup language. XSD specifies how to describe the elements in an Extensible Markup Language document formally.
 Stands For
DTD stands for Document Type Definition. XSD stands for XML Schema Definition.
Control on XML Structure
DTD provides less control over the XML structure. XSD provides more control over the XML structure.
 Support for Data Types
DTD does not support data types. XSD supports data types.
Simplicity
DTD is harder than XSD. XSD is simple than DTD.

Summary – DTD vs XSD

XML is a technology for data transferring. DTD and XSD are related to XML. An XML file contains the structure and the content. DTD is a set of markup declarations that define a document type for an SGML – family markup language. XSD specifies how to describe the elements in an Extensible Markup Language document formally. The difference between DTD and XSD is that DTD can be used to define the structure while XSD can be used to define the structure and content.

Reference:

1.“XML Schema (W3C).” Wikipedia, Wikimedia Foundation, 17 Mar. 2018. Available here  
2.“XML DTD – Javatpoint.”, Java T Point. Available here
3.“XML Schema – Javatpoint.”, Java T Point. Available here
4.“Document Type Definition.” Wikipedia, Wikimedia Foundation, 14 Mar. 2018. Available here

Key Difference – Prepositions vs Conjunctions   The function of prepositions and conjunctions can often be very confusing to the non-native speakers of English although there is a key difference between these two types. A preposition refers to a word that is used with a noun or pronoun to show place, position, time or method. A preposition is usually placed in front of a noun. On the other hand, a conjunction refers to a word that creates a connection between words, clauses or phrases. This is the key difference between a preposition and a conjunction. Through this article let us examine the difference with examples. What are Prepositions? A preposition refers to a word that is used with a noun or pronoun to show place, position, time or method. The main function of a preposition is to highlight the relationship that a particular word has to some other word. A preposition is....... READ

Meet vs Met   Meet is a verb in English language that is used frequently to describe an event where someone comes across another person by chance or through prior appointment. Meet is also a noun where it describes the event such as sports meet or a law and order meet of authorities. Met is the past tense of the word that is used to describe an act of meeting in the past. However, there are instances where meet is used even if the sentence is in the past tense confusing those who are trying to master the grammar of English language. Let us take a closer look at meet and met to find out the difference and the correct usage. Met is the past tense of meet. You use meet when you are talking of present or future events. Take a look at the following examples. • I have.......READ

Be the first to comment

Leave a Reply

Your email address will not be published.

*