11
CIS 375—Web App Dev II DTD

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

Embed Size (px)

Citation preview

Page 1: 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

CIS 375—Web App Dev II

DTD

Page 2: 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

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.

Page 3: 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

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>

Page 4: 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

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)>

Page 5: 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

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.

Page 6: 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

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., &nbsp;)

PCDATA—parsed (___________) character data CDATA—character data, not parsed

Page 7: 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

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)>

Page 8: 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

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)*>

Page 9: 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

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">

Page 10: 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

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;&copyright;</author>

__________ entity declaration: <!ENTITY writer SYSTEM "http://www.w3schools.com/entities/entities.xml">

In the XML file: <author>&writer;</author>

Page 11: 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

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">]>