Presentation is loading. Please wait.

Presentation is loading. Please wait.

Week 4 Document Type Definition (DTD)

Similar presentations


Presentation on theme: "Week 4 Document Type Definition (DTD)"— Presentation transcript:

1 Week 4 Document Type Definition (DTD)
Introduction DTD Break Down – a building block Elements Attributes Entities Conditional Sections Whitespace Validation A Real World Case Study

2 Introduction – How to Define Elements?
Objective: Define the elements to be used to represent data Use a Document Type Definition, or DTD. A DTD defines the elements, their order, how they can be nested, and other basic details of XML document structure. Part of the original XML specification, very similar to SGML DTDs. Use an XML Schema A schema defines all document structures that you can put in a DTD Define data types and more complicated rules than a DTD can. The W3C developed the XML Schema specification a couple of years after the original XML spec

3 Introduction Document Type Definitions (DTDs) EBNF
Define the legal building blocks of an XML document Define structure of XML document i.e., what legal elements, attributes, etc. are permitted in document XML document not required to have DTD Usually recommended for document conformity Use Extended Backus-Naur Form (EBNF) grammar EBNF

4 Introduction (cont.) Why use a DTD?
Data Definition: Define the different pieces of data planning to model, along with their relationship Specific Format: With DTD, each of your XML files can carry a description of its own format with it. Commonality: With a DTD, independent groups of people can agree to use a common DTD for interchanging data. Verification (Receiving): Your application can use a standard DTD to verify that the data you receive from the outside world is valid. Verification (Own): You can also use a DTD to verify your own data.

5 Document Type Declaration
Introduce DTDs into XML documents Placed in XML document’s prolog <!DOCTYPE ……………… > Can point to Internal subsets Declarations inside document Visible only within document in which it resides External subsets Declarations outside document Exist in different file typically ending with .dtd extension

6 Document Type Declaration (cont.)
A DTD can be declared inline in your XML document, or as an external reference Internal DOCTYPE declaration: should be wrapped in a DOCTYPE definition (anything in [ ] ) External DOCTYPE declaration should be wrapped in a DOCTYPE definition <!DOCTYPE root-element [element-declarations]> Exam: <!DOCTYPE Mail [<!ELEMENT Mail (#PCDATA) >]> <!DOCTYPE root-element SYSTEM "filename.dtd"> or <!DOCTYPE root-element PUBLIC “

7 DOCTYPE starts document type declaration
1 <?xml version = "1.0"?> 2 3 <!-- Fig. 6.1: intro.xml > 4 <!-- Using an external subset --> 5 6 <!DOCTYPE myMessage SYSTEM "intro.dtd"> 7 8 <myMessage> 9 <message>Welcome to XML!</message> 10 </myMessage> Fig. 6.1 XML document declaring its associated DTD. DOCTYPE starts document type declaration Document type declaration is named myMessage Keyword SYSTEM specifies external subset intro.dtd is DTD Document type declaration is named myMessage Keyword SYSTEM specifies external subset intro.dtd is DTD

8 Declare element myMessage
1 <!-- Fig. 6.2: intro.dtd --> 2 <!-- External declarations --> 3 4 <!ELEMENT myMessage ( message )> 5 <!ELEMENT message ( #PCDATA )> Declare element myMessage Fig. 6.2 Validation with using an external DTD. Declare element myMessage Element myMessage contains child element message Declare element message Element message contains parsable character data Element myMessage contains child element message Declare element message Element message contains parsable character data

9 DTD Break Down – A Building Block
The main building blocks of both XML and HTML documents are tags like <body>....</body> The building blocks of XML documents made up by the following simple building blocks: Elements Tags Attributes Entities PCDATA CDATA

10 DTD Break Down – A Building Block (cont.)
Elements The main building blocks of both XML and HTML documents. Examples of HTML elements are "body" and "table". Examples of XML elements could be "note" and "message". Elements can contain text, other elements, or be empty. Examples of empty HTML elements are "hr", "br" and "img" Tags Tags are used to markup elements. A starting tag like <element_name> marks up the beginning of an element, and an ending tag like </element_name>  marks up the end of an element.

11 DTD Break Down – A Building Block (cont.)
Tags Attributes Provide extra information about elements Attributes are always placed inside the starting tag of an element. Attributes always come in name/value pairs. The name of the attribute is "src". The value of the attribute is "computer.gif". The element itself is empty, it is closed by a " /" body element marked up with body tags: <body>body text in between</body> message element marked up with message tags: <message>some message in between</message> <img src="computer.gif" />

12 DTD Break Down – A Building Block (cont.)
Entities Entities are variables used to define common text. Entity references are references to entities. Most of you will know the HTML entity reference: " ". This "no-breaking-space" entity is used in HTML to insert an extra space in a document. Entities are expanded when a document is parsed by an XML parser. Entity Ref. Char. < > & & " " &apos; '

13 DTD Break Down – A Building Block (cont.)
PCDATA PCDATA means parsable character data (markup text: <, >, &, …etc. will be treated as markup text). Think of character data as the text found between the start tag and the end tag of an XML element. PCDATA is text that will be parsed by a parser. Tags inside the text will be treated as markup and entities will be expanded CDATA CDATA also means character data. CDATA is text that will NOT be parsed by a parser. Tags inside the text will NOT be treated as markup and entities will not be expanded

14 DTD – Element Element type declarations
Declare elements that will be used in XML documents Declaring an Element <!ELEMENT element-name category> or <!ELEMENT element-name (element-content)>

15 DTD – Element (cont.) Elements with children (sequences)
Defined with the name of the children elements inside parentheses <!ELEMENT element-name (child-element-name)> or <!ELEMENT element-name (child-element-name,child-element-name,.....)> example: <!ELEMENT note (to,from,heading,body)> Children must appear in the same sequence in the document. The children must also be declared Children can also have children. <!ELEMENT note (to,from,heading,body)> <!ELEMENT to (#PCDATA)> <!ELEMENT from (#PCDATA)> <!ELEMENT heading (#PCDATA)> <!ELEMENT body (#PCDATA)>

16 Sequences, Pipe Characters and Occurrence Indicators
Specify order in which elements occur Comma (,) used as delimiter <!ELEMENT classroom (teacher, student )> Pipe characters (|) Specify choices <!ELEMENT dessert (iceCream | pastry )>

17 Sequences, Pipe Characters and Occurrence Indicators (cont.)
If no sign at all, indicates exactly one occurrence Plus sign (+) indicates one or more occurrences <!ELEMENT album ( song+ )> Asterisk (*) indicates optional element <!ELEMENT library ( book* )> Question mark (?) indicates element can occur only once <!ELEMENT seat ( person? )>

18 Fig. 6.4 Occurrence indicators.

19 Sequences, Pipe Characters and Occurrence Indicators (cont.)
<!ELEMENT element-name (child-name)> example: <!ELEMENT note (message)> <!ELEMENT element-name (child-name+)> example: <!ELEMENT note (message+)> <!ELEMENT element-name (child-name*)> example: <!ELEMENT note (message*)> <!ELEMENT element-name (child-name?)> example: <!ELEMENT note (message?)>

20 Occurrence Indicators (cont.)
<!ELEMENT x ( a, (b | c | d ), e)*> <x> <a /> <b /> <e /> </x> <x> <a /> <d /> <e /> </x> <x> <a /> <c /> <e /> </x> <x> <a /> <b /> <e /> <c /> <d /> </x> <x> </x>

21 EMPTY, Mixed Content and ANY
Content specification types EMPTY Elements do not contain character data Elements do not contain child elements Empty elements: are declared with the category keyword EMPTY <!ELEMENT element-name EMPTY> example: <!ELEMENT oven EMPTY> XML example: <oven />

22 EMPTY, Mixed Content and ANY
Content specification types Mixed content Combination of elements and PCDATA <!ELEMENT myMessage ( #PCDATA | message )*> Markup for myMessage <myMessage>Here is some text, some <message>other text</message>and <message>even more text</message> </myMessage> example: <!ELEMENT note (#PCDATA|to|from|header|message)*>

23 EMPTY, Mixed Content and ANY (cont.)
example: <!ELEMENT note (#PCDATA|to|from|header|message)*> Markup for note <note>Here is some text, some <message>other text</message>and <message>even more text</message> </note> <note>Here is some text, some <to>other text</to>and <from>even more text</from> </note>

24 Specify DTD as internal subset
1 <?xml version = "1.0" standalone = "yes"?> 2 Specify DTD as internal subset Fig. 6.5 Example of a mixed-content element. Specify DTD as internal subset Declare format as mixed content element Elements bold and italic have PCDATA only for content specification Element format adheres to structure in DTD 3 <!-- Fig. 6.5 : mixed.xml > 4 <!-- Mixed content type elements --> Declare format as mixed content element 5 6 <!DOCTYPE format [ 7 <!ELEMENT format ( #PCDATA | bold | italic )*> 8 <!ELEMENT bold ( #PCDATA )> Elements bold and italic have PCDATA only for content specification 9 <!ELEMENT italic ( #PCDATA )> 10 ]> 11 12 <format> Element format adheres to structure in DTD 13 This is a simple formatted sentence. 14 <bold>I have tried bold.</bold> 15 <italic>I have tried italic.</italic> 16 Now what? 17 </format>

25 Fig. 6.5 Example of a mixed-content element.

26 Fig. 6.6 Illegal mixed-content element syntax.

27 EMPTY, Mixed Content and ANY (cont.)
Elements with character data Declared with #PCDATA inside parentheses <!ELEMENT myElement ( #PCDATA )> myElement is generic identifier Parentheses specify element’s content (content specification) Keyword PCDATA Element must contain parsable character data All text treated as markup Elements with any contents Elements declared with the category keyword ANY, can contain any combination of parsable data <!ELEMENT element-name ANY> example: <!ELEMENT note ANY>

28 EMPTY, Mixed Content and ANY (cont.)
Can contain any content PCDATA, elements or combination Can also be empty elements Commonly used in early DTD-development stages Replace with specific content as DTD evolves

29 Fig. 6.2 Validation with using an external DTD.

30 Fig. 6.2 Validation with using an external DTD (cont.)

31 Fig. 6.3 Non-valid XML document.
1 <?xml version = "1.0"?> 2 3 <!-- Fig. 6.3 : intro-invalid.xml > 4 <!-- Simple introduction to XML markup --> 5 6 <!DOCTYPE myMessage SYSTEM "intro.dtd"> 7 8 <!-- Root element missing child element message --> 9 <myMessage> 10 </myMessage> Fig. 6.3 Non-valid XML document. Element myMessage’s structure does not adhere to that specified in intro.dtd Element myMessage’s structure does not adhere to that specified in intro.dtd

32 DTD - Attributes Declaration Specifies element’s attribute list
Uses ATTLIST attribute list declaration <!ATTLIST element-name attribute-name attribute-type default- value> example: DTD example:<!ATTLIST payment type CDATA "check"> XML example:<payment type="check" />

33 Specify DTD as internal subset
1 <?xml version = "1.0"?> 2 3 <!-- Fig. 6.7: intro2.xml --> 4 <!-- Declaring attributes --> 5 6 <!DOCTYPE myMessage [ 7 <!ELEMENT myMessage ( message )> 8 <!ELEMENT message ( #PCDATA )> 9 <!ATTLIST message id CDATA #REQUIRED> 10 ]> 11 12 <myMessage> 13 14 <message id = "445"> Welcome to XML! 16 </message> 17 18 </myMessage> Specify DTD as internal subset Fig. 6.7 Declaring attributes. Specify DTD as internal subset Declare element myMessage with child element message Declare that attribute id contain required CDATA Declare element myMessage with child element message Declare that attribute id contain required CDATA

34 Fig. 6.7 Declaring attributes.

35 DTD - Attributes <!ATTLIST element-name attribute-name attribute-type default-value> The attribute-type can have the following values Value Explanation CDATA The value is character data (en1|en2|..) The value must be one from an enumerated list ID The value is a unique id IDREF The value is the id of another element IDREFS The value is a list of other ids NMTOKEN The value is a valid XML name NMTOKENS The value is a list of valid XML names ENTITY The value is an entity ENTITIES The value is a list of entities NOTATION The value is a name of a notation xml: The value is a predefined xml value

36 DTD – Attributes (cont.)
<!ATTLIST element-name attribute-name attribute-type default-value> The default-value can have the following values Value Explanation value The default value of the attribute #REQUIRED The attribute value must be included in the element #IMPLIED The attribute does not have to be included #FIXED value The attribute value is fixed

37 Attribute Types Strings (CDATA) Tokenized attributes
No constraints on attribute values Except for disallowing <, >, &, ’and ” characters Tokenized attributes Constraints on permissible characters for attribute values Enumerated attributes Most restrictive Take only one value listed in attribute declaration

38 Tokenized Attribute Type (ID, IDREF, ENTITY, NMTOKEN)
Tokenized attribute types Restrict attribute values ID Uniquely identifies an element IDREF Points to elements with ID attribute

39 Each shipping element has a unique identifier (shipID)
1 <?xml version = "1.0"?> 2 3 <!-- Fig. 6.8: IDExample.xml > 4 <!-- Example for ID and IDREF values of attributes --> 5 6 <!DOCTYPE bookstore [ 7 <!ELEMENT bookstore ( shipping+, book+ )> 8 <!ELEMENT shipping ( duration )> 9 <!ATTLIST shipping shipID ID #REQUIRED> 10 <!ELEMENT book ( #PCDATA )> 11 <!ATTLIST book shippedBy IDREF #IMPLIED> 12 <!ELEMENT duration ( #PCDATA )> 13 ]> 14 15 <bookstore> 16 <shipping shipID = "s1"> <duration>2 to 4 days</duration> 18 </shipping> 19 Fig. 6.8 XML document with ID and IDREF attribute types. Each shipping element has a unique identifier (shipID) Attribute shippedBy points to shipping element by matching shipID attribute Each shipping element has a unique identifier (shipID) Attribute shippedBy points to shipping element by matching shipID attribute

40 Declare book elements with attribute shippedBy
20 <shipping shipID = "s2"> <duration>1 day</duration> 22 </shipping> 23 24 <book shippedBy = "s2"> Java How to Program 3rd edition. 26 </book> 27 28 <book shippedBy = "s2"> C How to Program 3rd edition. 30 </book> 31 32 <book shippedBy = "s1"> C++ How to Program 3rd edition. 34 </book> 35 </bookstore> Fig. 6.8 XML document with ID and IDREF attribute types . (Part 2) Declare book elements with attribute shippedBy Declare book elements with attribute shippedBy

41 Fig. 6.7 XML document with ID and IDREF attribute types.

42 Assign shippedBy (line 28) value “s3”
Fig Error displayed by XML Validator when an invalid ID is referenced. Outline Assign shippedBy (line 28) value “s3” Assign shippedBy (line 28) value “s3”

43 Tokenized Attribute Type (ID, IDREF, ENTITY, NMTOKEN) (cont.)
ENTITY tokenized attribute type Indicate that attribute has entity for its value Entity declaration <!ENTITY digits “ ”> Entity may be used as follows: <useAnEntity>&digits;</useAnEntity> Entity reference &digits; replaced by its value <useAnEntity> </useAnEntity>

44 NDATA indicates that external-entity content is not XML
Declare entity city that refers to external document elements tour.html 1 <?xml version = "1.0"?> 2 Declare entity city that refers to external document elements tour.html 3 <!-- Fig. 6.10: entityExample.xml > Fig XML document that contains an ENTITY attribute type. Declare entity city that refers to external document elements tour.html NDATA indicates that external-entity content is not XML Attribute tour for element company requires ENTITY attribute type 4 <!-- ENTITY and ENTITY attribute types --> 5 6 <!DOCTYPE database [ 7 <!NOTATION html SYSTEM "iexplorer"> 8 <!ENTITY city SYSTEM "tour.html" NDATA html> NDATA indicates that external-entity content is not XML 9 <!ELEMENT database ( company+ )> 10 <!ELEMENT company ( name )> 11 <!ATTLIST company tour ENTITY #REQUIRED> 12 <!ELEMENT name ( #PCDATA )> Attribute tour for element company requires ENTITY attribute type 13 ]> 14 15 <database> 16 <company tour = "city"> <name>Deitel & Associates, Inc.</name> 18 </company> 19 </database>

45 Fig. 6.10 XML document that contains an ENTITY attribute type.

46 Fig. 6.11 Error generated by XML Validator when a DTD contains a reference to an undefined entity.
Outline Replace line 16 Replace line 16 <company tour = "city"> with <company tour = "country">

47 Tokenized Attribute Type (ID, IDREF, ENTITY, NMTOKEN) (cont.)
NMTOKEN tokenized attribute type “Name token” Value consists of letters, digits, periods, underscores, hyphens and colon characters Spaces are not allowed!

48 Enumerated Attribute Types
Declare list of possible values for attribute <!ATTLIST person gender ( M | F ) “F”> Attribute gender can have either value M or F F is default value Syntax: <!ATTLIST element-name attribute-name (en1|en2|..) default-value> DTD example: <!ATTLIST payment type (check | cash) "cash"> XML example: <payment type="check" />or<payment type="cash" />

49 DTD – Attribute Values Attribute defaults
Specify attribute’s default value #IMPLIED Use (application’s) default value if attribute value not specified #REQUIRED Attribute must appear in element Document is not valid if attribute is missing #FIXED Attribute value is constant Attribute value cannot differ in XML document

50 DTD – Attribute Values (cont.)
Specifying a Default attribute value The "square" element is defined to be an empty element with a "width" attribute of  type CDATA. If no width is specified, it has a default value of 0 DTD: <!ELEMENT square EMPTY> <!ATTLIST square width CDATA "0"> Valid XML: <square width="100" />

51 DTD – Attribute Values (cont.)
#IMPLIED: Syntax <!ATTLIST element-name attribute-name attribute-type #IMPLIED> Example: don't want to force the author to include an attribute, don't have an option for a default value DTD: <!ATTLIST contact fax CDATA #IMPLIED> Valid XML: <contact fax=" " />Valid XML:<contact />

52 DTD – Attribute Values (cont.)
#REQUIRED: Syntax <!ATTLIST element-name attribute name attribute-type #REQUIRED> Example: don't have an option for a default value, but still want to force the attribute to be present DTD: <!ATTLIST person number CDATA #REQUIRED> Valid XML: <person number="5677" /> Invalid XML: don't have an option for a default value, but still want to force the attribute to be present<person />

53 DTD – Attribute Values (cont.)
#FIXED : Syntax <!ATTLIST element-name attribute-name attribute-type #FIXED "value"> Example Want an attribute to have a fixed value without allowing the author to change it. Includes another value, the XML parser will return an error DTD: <!ATTLIST sender company CDATA #FIXED "Microsoft"> Valid XML: <sender company="Microsoft" /> Invalid XML: <sender company="W3Schools" />

54 DTD - Entities Entities are variables used to define shortcuts to common text. Entity references are references to entities. Entities can be declared internal, or external Internal Entity Declaration Syntax: <!ENTITY entity-name "entity-value"> DTD Example: <!ENTITY writer "Donald Duck."> <!ENTITY copyright "Copyright W3Schools."> XML example: <author>&writer;&copyright;</author>

55 DTD – Entities (cont.) External Entity Declaration Syntax:
<!ENTITY entity-name SYSTEM "URI/URL"> DTD Example: <!ENTITY writer SYSTEM " <!ENTITY copyright SYSTEM " XML example: <author>&writer;&copyright;</author> DTD XML

56 Conditional Sections – True or False?
Include declarations Keyword INCLUDE Exclude declarations Keyword IGNORE Often used with entities Parameter entities Preceded by percent character (%) Creates entities specific to DTD Can be used only inside DTD in which they are declared

57 Include this element message declaration
Entities accept and reject represent strings INCLUDE and IGNORE, respectively 1 <!-- Fig. 6.12: conditional.dtd > Entities accept and reject represent strings INCLUDE and IGNORE, respectively 2 <!-- DTD for conditional section example --> 3 Fig Conditional sections in a DTD. Entities accept and reject represent strings INCLUDE and IGNORE, respectively Include this element message declaration Exclude this element message declaration 4 <!ENTITY % reject "IGNORE"> 5 <!ENTITY % accept "INCLUDE"> Include this element message declaration 6 7 <![ %accept; [ 8 <!ELEMENT message ( approved, signature )> 9 ]]> Exclude this element message declaration 10 11 <![ %reject; [ 12 <!ELEMENT message ( approved, reason, signature )> 13 ]]> 14 15 <!ELEMENT approved EMPTY> 16 <!ATTLIST approved flag ( true | false ) "false"> 17 18 <!ELEMENT reason ( #PCDATA )> 19 <!ELEMENT signature ( #PCDATA )>

58 Fig. 6.13 XML document that conforms to conditional.dtd.
1 <?xml version = "1.0" standalone = "no"?> 2 3 <!-- Fig. 6.13: conditional.xml --> 4 <!-- Using conditional sections --> 5 6 <!DOCTYPE message SYSTEM "conditional.dtd"> 7 8 <message> 9 <approved flag = "true"/> 10 <signature>Chairman</signature> 11 </message> Fig XML document that conforms to conditional.dtd.

59 Fig. 6.13 XML document that conforms to conditional.dtd.

60 Whitespace Characters
Either preserved or normalized Depending on context in which it is used

61 Attribute hasCDATA requires CDATA, which preserves whitespace
1 <?xml version = "1.0"?> 2 3 <!-- Fig : whitespace.xml > 4 <!-- Demonstrating whitespace parsing --> 5 6 <!DOCTYPE whitespace [ 7 <!ELEMENT whitespace ( hasCDATA, hasID, hasNMTOKEN, hasEnumeration, hasMixed )> 9 10 <!ELEMENT hasCDATA EMPTY> 11 <!ATTLIST hasCDATA cdata CDATA #REQUIRED> 12 13 <!ELEMENT hasID EMPTY> 14 <!ATTLIST hasID id ID #REQUIRED> 15 16 <!ELEMENT hasNMTOKEN EMPTY> 17 <!ATTLIST hasNMTOKEN nmtoken NMTOKEN #REQUIRED> 18 19 <!ELEMENT hasEnumeration EMPTY> 20 <!ATTLIST hasEnumeration enumeration ( true | false ) #REQUIRED> 22 23 <!ELEMENT hasMixed ( #PCDATA | hasCDATA )*> 24 ]> 25 Fig Processing whitespace in an XML document. Attribute hasCDATA requires CDATA, which preserves whitespace Other attributes normalize (do not preserve) whitespace Attribute hasCDATA requires CDATA, which preserves whitespace Other attributes normalize (do not preserve) whitespace

62 Whitespace normalized
Whitespace preserved 26 <whitespace> 27 28 <hasCDATA cdata = " simple cdata "/> 29 30 <hasID id = " i20"/> 31 32 <hasNMTOKEN nmtoken = " hello"/> 33 34 <hasEnumeration enumeration = " true"/> 35 36 <hasMixed> This is text. <hasCDATA cdata = " simple cdata"/> This is some additional text. 40 </hasMixed> 41 42 </whitespace> Fig Processing whitespace in an XML document. (Part 2) Whitespace preserved Whitespace normalized Whitespace normalized

63 Output from Fig. 6.14 Whitespace preserved Whitespace normalized
>java Tree yes whitespace.xml URL: file:C:/Examplesps/Files/deleted/ch09/Tree/whitespace.xml [ document root ] +-[ element : whitespace ] +-[ ignorable ] +-[ ignorable ] +-[ ignorable ] +-[ element : hasCDATA ] [ attribute : cdata ] " simple cdata “ +-[ ignorable ] +-[ ignorable ] +-[ ignorable ] +-[ element : hasID ] [ attribute : id ] "i20“ +-[ ignorable ] +-[ ignorable ] +-[ ignorable ] +-[ element : hasNMTOKEN ] [ attribute : nmtoken ] "hello“ +-[ ignorable ] +-[ ignorable ] +-[ ignorable ] +-[ element : hasEnumeration ] [ attribute : enumeration ] "true“ +-[ ignorable ] +-[ ignorable ] +-[ ignorable ] +-[ element : hasMixed ] [ text ] “ “ [ text ] " This is text.“ [ text ] “ Output from Fig. 6.14 Whitespace preserved Whitespace normalized Whitespace preserved Whitespace normalized

64 “ [ text ] " “ [ element : hasCDATA ] [ attribute : cdata ] " simple cdata“ [ text ] “ “ [ text ] " This is some additional text.“ [ text ] “ “ [ text ] " “ +-[ ignorable ] +-[ ignorable ] [ document end ] Output from Fig. 6.14

65 Parsers, Well-formed and Valid XML Documents
Validating Able to read DTD Determine whether XML document conforms to DTD Valid document conforms to DTD Document is then well formed, by definition Documents can be well formed, but not valid Nonvalidating Cannot check document against DTD for conformity

66 Fig. 6.3 Non-valid XML document.

67 A Practical Exercise – Car Ads Data Modeling
A car ads columan is presented as follow, Try your best to model the data set by creating an XML doc associated with a DTD Year: Maker: Lexus Model: LS400 Color: Light blue and white Description: Five-passenger luxury sedan Price: $56,875 Seller phone: " “ Seller: Lexus.com Location: Rapid City, South Dakota DTD XML

68 Real World Case Studies DTD - Examples from the Net
TV Schedule <!DOCTYPE TVSCHEDULE [ <!ELEMENT TVSCHEDULE (CHANNEL+)> <!ELEMENT CHANNEL (BANNER,DAY+)> <!ELEMENT BANNER (#PCDATA)> <!ELEMENT DAY (DATE,(HOLIDAY|PROGRAMSLOT+)+)> <!ELEMENT HOLIDAY (#PCDATA)> <!ELEMENT DATE (#PCDATA)> <!ELEMENT PROGRAMSLOT (TIME,TITLE,DESCRIPTION?)> <!ELEMENT TIME (#PCDATA)> <!ELEMENT TITLE (#PCDATA)>  <!ELEMENT DESCRIPTION (#PCDATA)> <!ATTLIST TVSCHEDULE NAME CDATA #REQUIRED> <!ATTLIST CHANNEL CHAN CDATA #REQUIRED> <!ATTLIST PROGRAMSLOT VTR CDATA #IMPLIED> <!ATTLIST TITLE RATING CDATA #IMPLIED> <!ATTLIST TITLE LANGUAGE CDATA #IMPLIED> ]>

69 Real World Case Studies DTD - Examples from the Net
Newspaper Article DTD <!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"> ]>

70 Real World Case Studies DTD - Examples from the Net
Product Catalog DTD <!DOCTYPE CATALOG [ <!ENTITY AUTHOR "John Doe"> <!ENTITY COMPANY "JD Power Tools, Inc."> <!ENTITY <!ELEMENT CATALOG (PRODUCT+)> <!ELEMENT PRODUCT (SPECIFICATIONS+,OPTIONS?,PRICE+,NOTES?)> <!ATTLIST PRODUCT NAME CDATA #IMPLIED CATEGORY (HandTool|Table|Shop-Professional) "HandTool" PARTNUM CDATA #IMPLIED PLANT (Pittsburgh|Milwaukee|Chicago) "Chicago" INVENTORY (InStock|Backordered|Discontinued) "InStock"> <!ELEMENT SPECIFICATIONS (#PCDATA)>

71 Real World Case Studies DTD - Examples from the Net
Product Catalog DTD (cont.) <!ATTLIST SPECIFICATIONS WEIGHT CDATA #IMPLIED POWER CDATA #IMPLIED> <!ELEMENT OPTIONS (#PCDATA)> <!ATTLIST OPTIONS FINISH (Metal|Polished|Matte) "Matte" ADAPTER (Included|Optional|NotApplicable) "Included" CASE (HardShell|Soft|NotApplicable) "HardShell"> <!ELEMENT PRICE (#PCDATA)> <!ATTLIST PRICE MSRP CDATA #IMPLIED WHOLESALE CDATA #IMPLIED STREET CDATA #IMPLIED SHIPPING CDATA #IMPLIED> <!ELEMENT NOTES (#PCDATA)> ]>

72 Due Day: Next Friday before the class!
HomeWork # 2 Using the 3 real-world-case DTDs to model your data sets (i.e., your own daily TV schedule, an interesting news article, and a product) and also present them on the web pages. Select your own method to present the data modeled in the XML doc Hint: To do that, you’ll need to create several XML and HTML files to model and present the data sets. Due Day: Next Friday before the class!

73 What is BNF? Backus-Naur notation (more commonly known as BNF or Backus-Naur Form) A formal mathematical way to describe a language, Developed by John Backus (and possibly Peter Naur as well) Describe the syntax of the Algol 60 programming language. Used to formally define the grammar of a language


Download ppt "Week 4 Document Type Definition (DTD)"

Similar presentations


Ads by Google