XML (eXtensible Markup Language) is a markup language that is primarily used to transfer data and text between driver hardware, applications, and operating systems, with little or no human intervention. The key advantage of using XML to transfer data is the ability to design the layout for android applications and to configure frameworks.
It is used as a format for both storing and communicating your data between different systems in a platform-independent fashion. Instead of the predefined tags, the programmer in XML can write the tags based on the application. An XML document typically contains both the structure and the content.
In the e-Publishing industry, XML plays a major role in publishing online books and journals on various web portals. Many organizations use XML format to convert data into various formats such as doc, HTML, PDF, ePub, Mobi etc.
DTD (Document Type Definition), on the other hand, is a part of XML that helps to describe the language. It is mainly a set of markup declarations that is used to define a document type for a markup language.
Table of Contents:
Different Aspects of XML & DTD
XML—Features and Terminology
Among the key features of XML include
- Portability: Similar to HTML, you can easily ship XML data across platforms
- Extensibility: Since XML data describes itself, you can conveniently change the schema
- Flexibility: With XML data, you can represent any information including documents, structured, and semi-structured files
Among the key XML terminologies include
- Tag name—e.g., book, title
- Start tags—e.g., <book>, <title>
- End tags – e.g., </book>, </title>
- The element—that is enclosed by a pair of start and end tags—e.g., <book>…</book>
Elements here can be
- Nested—e.g., <book>…<title>…</title>…</book>
- Empty elements—e.g., <is_textbook/>3. Elements with attributes—e.g., <book ISBN=”…” price=”60.00″>
What Are Well-Formed XML Documents?
A well-formed XML document has the following features:
- It follows XML lexical conventions
- It contains a single root element
- It has properly matched tags and nested elements
What Are Valid XML Documents?
A valid XML document conforms to a Document Type Definition or DTD with the following requirements:
- A DTD is helpful to specify grammar for the document
- Constraints on structures, values of elements, and attributes
What is DTD?
As mentioned above, DTD refers to Document Type Definition and is mainly used to describe XML language in a concise manner.
The primary objective of DTD is to define the structure of an XML file. It contains a list of legal elements and is used to perform validation. Put simply, DTD allows you to create rules for the elements within your XML documents. Although the XML document itself has its own rules, the rules defined in a DTD are specific to individual needs.
The two main types of DTD are the following:
- Internal DTD—If the DTD elements are declared within the XML file, it is called an internal DTD
- External DTD—If the DTD elements are declared in some other file, it is called an external DTD
The working of DTD is done through the following steps:
- Begin by creating a DTD file for your respective XML document
- Once done, outline the structure of the document
- You can now create DTD either with internal or with external references
- Make sure to include all the elements, entities, and attributes for the file
DTD is essentially a way to describe XML language precisely. Since DTD defines the structure, legal elements, and attributes of an XML document, it helps to check both vocabulary and validity of the structure of XML documents against various grammatical rules of appropriate XML language.
There are two ways to specify and keep an XML–DTD that is either inside the document or in a separate document.
An XML document is well-formed if it contains the correct syntax. And a valid and well-formed XML document is one that has been validated against DTD.
Steps to Validate XML Using DTD
An XML document that is well created can be easily validated using DTD. A well-formed XML document with correct syntax would need to follow these rules:
- It must begin with the XML declaration.
- The document must have one unique root element enclosing all the other tags.
- All elements must be closed with a proper end tag.
- For special characters, XML entities should be used.
- Values of all attributes must be in quotes.
XML is a technology primarily used for data transfer and DTD is related to XML. Since an XML file contains both the structure and the content, DTD is used to define that structure. It is a set of markup declarations that define a document type for a markup language.
If your XML document is conformed to the DTD format, then it is valid and can be used in various business-to-business applications. The standard DTD is used by a number of applications to verify the valid data received from the external sources before being sent to the other clients. Therefore, it is a main element of the DTD to examine/test/convert the XML file before it is given to the business process.