XML Schema vs DTD
XML stands for EXtensible Markup Language. It is defined in the XML 1.0 specification, which is developed by the W3C (World Wide Web Consortium). XML provides a standard way, which is also simple, to encode data and text such that the content could be exchanged across driver hardware, operating systems and applications with little human intervention. XML Schema describes the structure of a XML document. XML schema imposes constraints on the structure and the content of a XML document in addition to the syntactical rules that should be followed in XML. XML schema is a recommendation provided by World Wide Web Consortium (W3C) and it became a recommendation in May, 2001. DTD (Document Type Definition) also defines how the elements of document are ordered and nested, what elements are included in the document and the attributes of the included elements. DTD defines the structure of documents in SGML-family markup languages.
What is XML Schema?
XML schema describes the structure of a XML document. It defines the elements that can appear in a XML document and their attributes such as whether an element is empty or whether it can contain text. It also defines what elements would be child elements and the order of the child elements. Further, XML schema defines data types used in elements and their attributes. XML schemas are widely used in web applications since it is extensible and provides support for data types and name spaces. Biggest strength with XML schema is providing support for data types. It provides easy methods to define the content allowed in a document and methods to ensure the correctness of data. Furthermore, XML schema has provisions to work with data in databases and allows conversion between data types.
What is DTD?
DTD defines the structure of documents in SGML-family markup languages such as SGML, XML, and HTML. It defines how the elements of documents are ordered and nested, what elements are included in the documents and the attributes of the included elements. In a XML document, DTD is declared in a DOCTYPE declaration, which is beneath the XML declaration. The body of the DTD holds the definitions for the elements in the document and their attributes and it can be defined as an inline definition or an external definition. Having an external DTD is very useful when you use XML protocol to communicate between separate systems since it reduces the overhead of resending the DTD each time as with inline definition. The external DTD could be placed in a place like a web server that could be accessed by both the systems.
What is the difference between XML Schema and DTD?
DTD is the predecessor of XML schema. While DTD provides the basic structure/grammar for defining a XML document, in addition to that XML schema provides methods to define constraints on the data contained in the document. Therefore XML schema is considered to be richer and powerful than DTD. Also, XML schema provides an object oriented approach for defining the structure of a XML document. But since XML schema is a new technology, some XML parsers do not support it yet. Furthermore, most of rich and complex definitions of legacy systems are defined with DTD. So rewriting them would not be an easy task.