0% found this document useful (0 votes)
36 views10 pages

Document Type Definition

A Document Type Definition (DTD) defines the structure and elements of an XML document. A DTD specifies elements, attributes, entities and element content that can be used in an XML document. An XML document that adheres to the rules specified in a DTD is considered "valid". DTDs allow different groups to agree on a standard structure for exchanging XML data.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
36 views10 pages

Document Type Definition

A Document Type Definition (DTD) defines the structure and elements of an XML document. A DTD specifies elements, attributes, entities and element content that can be used in an XML document. An XML document that adheres to the rules specified in a DTD is considered "valid". DTDs allow different groups to agree on a standard structure for exchanging XML data.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 10

DTD

Document Type Definition


XML DTD
• An XML document with correct syntax is called
"Well Formed".
• An XML document validated against a DTD is
both "Well Formed" and "Valid".
• The purpose of a DTD is to define the
structure of an XML document.
The Building Blocks of XML Documents
Seen from a DTD point of view, all XML documents are made up by the following
building blocks:

•Elements
•Attributes
•Entities
•PCDATA
•CDATA
Note.xml

<?xml version="1.0" encoding="UTF-8"?>


<!DOCTYPE note SYSTEM "Note.dtd">
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this
weekend!</body>
</note>
Note.dtd

<!ELEMENT note (to,from,heading,body)>


<!ELEMENT to (#PCDATA)>
<!ELEMENT from (#PCDATA)>
<!ELEMENT heading (#PCDATA)>
<!ELEMENT body (#PCDATA)>
The DTD above is interpreted like this:

!DOCTYPE note defines that the root element of the document is note
!ELEMENT note defines that the note element must contain the elements:
"to, from, heading, body"
!ELEMENT to defines the to element to be of type "#PCDATA"
!ELEMENT from defines the from element to be of type "#PCDATA"
!ELEMENT heading defines the heading element to be of type "#PCDATA"
!ELEMENT body defines the body element to be of type "#PCDATA"
#PCDATA means parse-able text data.
<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE note [
<!ELEMENT note (to,from,heading,body)>
<!ELEMENT to (#PCDATA)>
<!ELEMENT from (#PCDATA)>
<!ELEMENT heading (#PCDATA)>
<!ELEMENT body (#PCDATA)>

<!ENTITY nbsp "&#xA0;">


<!ENTITY writer "Writer: Donald Duck.">
<!ENTITY copyright "Copyright: W3Schools.">
]>

<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this
weekend!</body>
<footer>&writer;&nbsp;&copyright;</footer>
When to Use a DTD/Schema?

With a DTD, independent groups of people can agree to use a standard DTD for
interchanging data.
With a DTD, you can verify that the data you receive from the outside world is
valid.
You can also use a DTD to verify your own data.
INTERNAL DTD DECLARATION

<?xml version="1.0"?>
<!DOCTYPE note [
<!ELEMENT note (to,from,heading,body)>
<!ELEMENT to (#PCDATA)>
<!ELEMENT from (#PCDATA)>
<!ELEMENT heading (#PCDATA)>
<!ELEMENT body (#PCDATA)>
]>
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend</body>
</note>
<?xml version="1.0"?>
<!DOCTYPE note SYSTEM "note.dtd">
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this
weekend!</body>
</note>

And here is the file "note.dtd", which contains


the DTD:
<!ELEMENT note (to,from,heading,body)>
<!ELEMENT to (#PCDATA)>
<!ELEMENT from (#PCDATA)>
<!ELEMENT heading (#PCDATA)>
<!ELEMENT body (#PCDATA)>
Declaring Attributes
An attribute declaration has the following syntax:

<!ATTLIST element-name attribute-name attribute-type attribute-value>

DTD example:

<!ATTLIST payment type CDATA "check">

XML example:

<payment type="check" />

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy