top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

What is DTD in XML?

+2 votes
501 views
What is DTD in XML?
posted Jun 29, 2018 by anonymous

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

2 Answers

+1 vote

The purpose of a DTD is to define the legal building blocks of an XML document. It defines the document structure with a list of legal elements. A DTD can be declared inline in your XML document, or as an external reference

This is an XML document with a Document Type Definition:

<?xml version="1.0"?>
<!DOCTYPE note [ <!ELEMENT note (to,from,heading,body)>
<!ELEMENT to (#PCDATA)>
<!ELEMENT from (#PCDATA)>
<!ELEMENT heading (#PCDATA)>
<!ELEMENT body (#PCDATA)>
]>

Tove
Jani
Reminder
Don't forget me this weekend!

This is the same XML document with an external DTD:
<?xml version="1.0"?>
<!DOCTYPE note SYSTEM "note.dtd">

Tove
Jani
Reminder
Don't forget me this weekend!

This is a copy of the file “note.dtd” containing the Document
<?xml version="1.0"?>
<!ELEMENT note (to,from,heading,body)>
<!ELEMENT to (#PCDATA)>
<!ELEMENT from (#PCDATA)>
<!ELEMENT heading (#PCDATA)>
<!ELEMENT body (#PCDATA)>

Why use a DTD?
XML provides an application independent way of sharing data. With a DTD, independent groups of people can agree to use a common DTD for interchanging data. Your application can use a standard DTD to verify that data that you receive from the outside world is valid. You can also use a DTD to verify your own data.

@iFour Techno Lab Pvt. Ltd.

answer Mar 18, 2019 by Rushabh Verma R.
0 votes

A DTD is a Document Type Definition. A DTD defines the structure and the legal elements and attributes of an XML document.

answer Jun 29, 2018 by Amarvansh
...