Upload
loreen-riley
View
214
Download
0
Embed Size (px)
Citation preview
CIS 375—Web App Dev II
DTD
2
Introduction to DTD DTD stands for ______________________. The purpose of a DTD is to define the legal
building blocks of an _____ document. A DTD can be declared inline in your XML
document, or as an _________ reference.
3
DTD Declared Inline w/ XML<?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>
4
External DOCTYPE Declaration
XML file<?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>
note.dtd<!ELEMENT note (to,from,heading,body)><!ELEMENT to (#PCDATA)> <!ELEMENT from (#PCDATA)> <!ELEMENT heading (#PCDATA)> <!ELEMENT body (#PCDATA)>
5
Why Use a DTD? Each of your XML files can carry a description
of its own ________ with it. Independent groups of people can agree to
use a common DTD for interchanging data. Your application can use a standard DTD to
______ the data you receive from the outside world.
To verify your own data.
6
Building Blocks of XML/HTML
Elements like “body” in HTML, XML has its own elements
(“note”) Tags
the “body” element has tags <body> and </body> Attributes
info about elements (<img src="computer.gif" />)
Entities variables used to define text (e.g., )
PCDATA—parsed (___________) character data CDATA—character data, not parsed
7
Specifying Elements I Empty element:
<!ELEMENT br EMPTY> Element w/ character data only:
<!ELEMENT from (#PCDATA)> Element w/ any content:
<!ELEMENT note ANY> Element with children:
<!ELEMENT note (to,from,heading,body)>
8
Specifying Elements II Minimum one occurrence of the same element:
<!ELEMENT note (message+)> Zero or more occurrences of the same element:
<!ELEMENT note (message*)> Zero or _____ occurrence of the same element:
<!ELEMENT note (message?)> Declaring either/or content:
<!ELEMENT note (to,from,header,(message|body))>
Declaring mixed content: <!ELEMENT note (#PCDATA|to|from|header|message)*>
9
DTD Attributes Declaring an attribute of an XML element:
<!ATTLIST payment type CDATA "check"> In the XML file:
<payment type="check" /> A value is just required:
<!ATTLIST payment type CDATA #REQUIRED> Only the value “check” is allowed:
<!ATTLIST payment type CDATA #FIXED "check">
Different values are allowed: <!ATTLIST payment type (check|cash) "cash">
10
DTD Entities Entities are variables used to define shortcuts
to common text. <!ENTITY writer "Donald Duck."> <!ENTITY copyright "Copyright W3Schools.">
In the XML file: <author>&writer;©right;</author>
__________ entity declaration: <!ENTITY writer SYSTEM "http://www.w3schools.com/entities/entities.xml">
In the XML file: <author>&writer;</author>
11
Example<!DOCTYPE NEWSPAPER [ <!ELEMENT NEWSPAPER (ARTICLE+)> <!ELEMENT ARTICLE (HEADLINE,BYLINE,LEAD,BODY,NOTES)><!ELEMENT HEADLINE (#PCDATA)> <!ELEMENT BYLINE (#PCDATA)> <!ELEMENT LEAD (#PCDATA)> <!ELEMENT BODY (#PCDATA)> <!ELEMENT NOTES (#PCDATA)>
<!ATTLIST ARTICLE AUTHOR CDATA #REQUIRED> <!ATTLIST ARTICLE EDITOR CDATA #IMPLIED> <!ATTLIST ARTICLE DATE CDATA #IMPLIED> <!ATTLIST ARTICLE EDITION CDATA #IMPLIED>
<!ENTITY NEWSPAPER "Vervet Logic Times"> <!ENTITY PUBLISHER "Vervet Logic Press"> <!ENTITY COPYRIGHT "Copyright 1998 Vervet Logic
Press">]>