CIS 375Web App Dev II DTD Introduction to
CIS 375—Web App Dev II DTD
Introduction to DTD n n n 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. 2
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> 3
External DOCTYPE Declaration n 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> n note. dtd <!ELEMENT <!ELEMENT note (to, from, heading, body)> to (#PCDATA)> from (#PCDATA)> heading (#PCDATA)> body (#PCDATA)> 4
Why Use a DTD? n n 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. 5
Building Blocks of XML/HTML n Elements n n Tags n n n info about elements (<img src="computer. gif" />) Entities n n the “body” element has tags <body> and </body> Attributes n n like “body” in HTML, XML has its own elements (“note”) variables used to define text (e. g. , ) PCDATA—parsed (______) character data CDATA—character data, not parsed 6
Specifying Elements I n Empty element: n n Element w/ character data only: n n <!ELEMENT from (#PCDATA)> Element w/ any content: n n <!ELEMENT br EMPTY> <!ELEMENT note ANY> Element with children: n <!ELEMENT note (to, from, heading, body)> 7
Specifying Elements II n Minimum one occurrence of the same element: n n Zero or more occurrences of the same element: n n <!ELEMENT note (message? )> Declaring either/or content: n n <!ELEMENT note (message*)> Zero or _____ occurrence of the same element: n n <!ELEMENT note (message+)> <!ELEMENT note (to, from, header, (message|body))> Declaring mixed content: n <!ELEMENT note (#PCDATA|to|from|header|message)*> 8
DTD Attributes n Declaring an attribute of an XML element: n n In the XML file: n n <!ATTLIST payment type CDATA #REQUIRED> Only the value “check” is allowed: n n <payment type="check" /> A value is just required: n n <!ATTLIST payment type CDATA "check"> <!ATTLIST payment type CDATA #FIXED "check"> Different values are allowed: n <!ATTLIST payment type (check|cash) "cash"> 9
DTD Entities n Entities are variables used to define shortcuts to common text. n n In the XML file: n n <author>&writer; ©right; </author> _____ entity declaration: n n <!ENTITY writer "Donald Duck. "> <!ENTITY copyright "Copyright W 3 Schools. "> <!ENTITY writer SYSTEM "http: //www. w 3 schools. com/entities. xml"> In the XML file: n <author>&writer; </author> 10
Example <!DOCTYPE <!ELEMENT <!ELEMENT NEWSPAPER [ NEWSPAPER (ARTICLE+)> ARTICLE (HEADLINE, BYLINE, LEAD, BODY, NOTES)> HEADLINE (#PCDATA)> BYLINE (#PCDATA)> LEAD (#PCDATA)> BODY (#PCDATA)> NOTES (#PCDATA)> <!ATTLIST ARTICLE AUTHOR CDATA #REQUIRED> EDITOR CDATA #IMPLIED> DATE CDATA #IMPLIED> EDITION CDATA #IMPLIED> <!ENTITY NEWSPAPER "Vervet Logic Times"> <!ENTITY PUBLISHER "Vervet Logic Press"> <!ENTITY COPYRIGHT "Copyright 1998 Vervet Logic Press">]> 11
- Slides: 11