0
3.6kviews
What is the purpose of XML and DTD? Design DTD for address book XML document.
1 Answer
0
139views

XML Document Type Declaration

  • The XML Document Type Declaration, commonly known as DTD, is a way to describe XML language precisely. DTDs check vocabulary and validity of the structure of XML documents against grammatical rules of appropriate XML language.
  • Its main purpose is to define the structure of an XML document. It defines the legal building blocks of an XML document. For this it contains a list of legal elements and attributes.
  • With a DTD, independent groups of people can agree on a standard DTD for interchanging data. An application can use a DTD to verify that XML data is valid.
  • A valid XML document must include the reference to DTD which validates it. When a DTD is absent the validating parser can’t verify the data format but can attempt to interpret the data.
  • An XML DTD can be either specified inside the document, or it can be kept in a separate document and then liked separately.

DTD for Address Book XML Document

Internal DTD for Address Book XML Document

< ?xml version=’1.0′ encoding=’utf-8′? > 
< !– DTD for a AddressBook.xml — > 
< !DOCTYPE AddressBook [ 
< !ELEMENT AddressBook (Address+) > 
< !ELEMENT Address (Name, Street, City) > 
< !ELEMENT Name (#PCDATA) > 
< !ELEMENT Street (#PCDATA) > 
< !ELEMENT City (#PCDATA) > 
] > 
< AddressBook > 
< Address > 
< Name >Jeniffer< /Name > 
< Street >Wall Street < /Street > 
< City >New York< /City > 
< /Address > 
< /AddressBook >

External DTD for Address Book XML Document - The DTD for AddressBook.xml is contained in a file AddressBook.dtd. AddressBook.xml contains only XML Data with a reference to the DTD file.

< ?xml version="1.0" encoding="UTF-8"? > 
< !DOCTYPE AddressBook SYSTEM "file:/// c:/XML/AddressBook.dtd dtd" > " > 
< AddressBook > 
< Address > 
< Name >Jeniffer< /Name > 
< Street >Wall Street< /Street > 
< City >New York< /City > 
< /Address > 
< /AddressBook >
Please log in to add an answer.