![]() |
DTD stands for Document Type Definition. It is a set of rules which is used to define the structure and elements of an XML document. A DTD:
DTDs are used to validate and describe the structure of XML documents. In a way, they are a set of rules that confirm that the XML document follows a specified structure. Syntax:1. Element Declaration:<!ELEMENT> declaration is used to define an element in a DTD. <!ELEMENT element_name content_specification>
where: element_name is the name of the XML and content_specification defines what can appear within the element> It can be EMPTY, ANY, or can contain any content. 2. Entity Declaration:Entities are used to define reusable strings or special characters. <!ENTITY> declaration is used to define entities in a DTD. Entities can be of two types: a. Internal entities: <!ENTITY entity_name "entity_value">
b. External entities: <!ENTITY entity_name SYSTEM "file_location">
3. Attribute Declaration:<!ATTLIST> declaration is used to define attributes for an element. <!ATTLIST element_name
attribute_name attribute_type default_value>
4. Comments:IN DTDs, comments are added in the same way just like XML documents. ‘<!—-‘ and ‘—->’ are used to add comments. <!-- This is a DTD comment -->
5. Parameter Entity Reference:Parameter entities are used to define reusable parts of the DTD. They are denoted by %. <![ENTITY % entity_name "entity_value">
6. Notation Declaration:It provides a way to specify the format or encoding of external data that an XML document might reference, such as multimedia files, binary data, or other data types that are not directly represented in XML. <!NOTATION notation_name SYSTEM "system_identifier">
Now, let’s take an example of a DTD document which defines details of the book- its title, publisher, author, publishing year and ISBN. XML
The above code comprises details of the book. We have to link the above dtd document to an .xml file to run an executable code as shown below: XML
Advantages of DTDs:
Disadvantages of DTDs:
Document Type Definitions (DTDs) are a fundamental component of XML, providing a means to define and validate the structure of XML documents. |
Reffered: https://www.geeksforgeeks.org
Data Formats |
Related |
---|
![]() |
![]() |
![]() |
![]() |
![]() |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 13 |