yt

Header Ads

Chapter 03 XML - DTD (Document Type Definition )-Technology369kk

  DTD 

(Document Type Definition)

  • DTD stands for Document Type Definition, and it is a markup language used to define the structure and constraints of an XML (eXtensible Markup Language) document. A DTD defines the elements, attributes, and entity references allowed in an XML document and their relationships.
  • A DTD defines the structure and the legal elements and attributes of an XML document. It checks vocabulary and validity of the structure of XML documents against grammatical rules of appropriate XML language. 

Table of Content: 

XML DTD Introduction:

  • XML Document Type Definition/Declaration.
  • Used to Describes with XML language pre closing 
  • Used to define structure of a xml document 
  • Contains list of legal elements 
  • Used to perform dali-datation.

  • DTD SYNTAX:   

<! DOCTYPE element DTD identifiers
  [Declaration 1
   Declaration 2
  ]>



Types of DTD:  

  1. Internal  : Element as declaration within the XML files.

Syntax:::

<! DOCTYPE root-element
  [Element-Declaration]
>

  1. External : Element as declaration outside the XML files. 

Syntax:::

<! DOCTYPE root-element
  Element-SYSTEM ="file-name";
>


Advantages of DTD: 

Here are some advantages of using DTD:-
  • You can define your own format for the XML files.
  • Looking at this document a user/developer can understand the structure of the data.
  • It helps in validation of XML file.
  • It provides us with proper documentation.
  • It enables us to describe an XML document efficiently

Disadvantages of DTD: 

Some of the disadvantages of DTD are:
  • DTD can be complex and difficult to understand, especially for non-technical users. This can make it challenging to create and maintain DTDs, and may require specialized training or expertise.
  • DTD has some limitations in terms of its functionality and expressiveness.
  • It does not support namespaces.
  • It supports only the text string data type.
  • It is not object-oriented. Hence, the concept of inheritance cannot be applied to DTDs.

Example of DTD: 

Q1. Here is an example of a simple DTD for a bookstore:

<!DOCTYPE student [
    <!ELEMENT student (bca+)>
    <!ELEMENT bca(name, roll, year, regfee)>
    <!ELEMENT name (#SHAILES)>
    <!ELEMENT roll (#82025)>
    <!ELEMENT year (#2020)>
    <!ELEMENT regfee (#3500)>
]>


ANOTHER EXAMPLE: 

<!DOCTYPE bookstore [
    <!ELEMENT bookstore (book+)>
    <!ELEMENT book (title, author, year, price)>
    <!ELEMENT title (#PCDATA)>
    <!ELEMENT author (#PCDATA)>
    <!ELEMENT year (#PCDATA)>
    <!ELEMENT price (#PCDATA)>
]>

In this example:

  • The bookstore element is the root element and can contain one or more book elements.
  • The book element contains the elements title, author, year, and price.
  • The title, author, year, and price elements are defined as containing only parsed character data (#PCDATA).
  • This DTD specifies the structure of an XML document representing a bookstore, where each book has a title, author, publication year, and price.

Conclusion :

DTDs can also define attributes for elements, specify the order and occurrence of elements, define entities, and more. However, DTDs have limitations and are considered less expressive and flexible compared to other schema languages like XML Schema or Relax NG.

I hope this is helpful for you.. 




No comments

Theme images by Dizzo. Powered by Blogger.