Download presentation
Presentation is loading. Please wait.
Published byMadeleine Wells Modified over 8 years ago
1
ELEMENT DECLARATIONS 1 CH 8
2
Objective 2 Analyzing the document ANY #PCDATA Child elements Mixed content Empty elements Comments in DTDs
3
Analyzing the Document 3 First step in creating DTD for particular document is to understand the structure of the information that you will encode Adding a DTD to this document enables you to enforce constraints When designing a new XML application, Writing some actual instance documents first, Then designing the DTD If an element has not been declared, it cannot be used http://www.cafeconleche.org/books/ bible3/source/04/4-2.xml (link to XML)
4
Document Type Definitions cont… 4 The Elements in the Television Schedule ElementRequired Children Optional Children SCHEDULEDATE, STATION(s) DATEText STATIONCHANNELNETWORK, CALL_LETTERS, SHOW(s) SHOWNAME, START_TIME(s), LENGTH EPISODE_NUMBER, START_TIME, LENGTH, AIR_DATE, ORIGINAL_ AIR_DATE, CLOSED_CAPTIONED, REPEAT, DESCRIPTION, TITLE, RATING, YEAR_MADE, STARS, DIRECTOR, WRITER, PRODUCER, CAST CASTACTOR(s) ACTORGIVEN_NAME, MIDDLE_NAME, MIDDLE_INITIAL, SURNAME WRITERGIVEN_NAME, MIDDLE_NAME, MIDDLE_INITIAL, SURNAME
5
Element Declarations 5 ElementRequired Children Optional Children PRODUCER DIRECTOR NAMEText TYPEText LETTERSText NETWORKText CHANNELText EPISODE_NUMB ER Text START_TIMEText LENGTHText AIR_DATEText
6
ANY 6 The keyword ANY is a content specification indicating that there are no restrictions on the content of an element With the Keyword ANY, This says that all possible elements as well as plain text can be children of the SCHEDULE element Because ANY is so unrestrictive, it lets you very quickly create a DTD that will validate a document.
7
ANY cont… 7
8
ANY cont… 8 The DTD in the previous slide does not say very much It place no restrictions on where they may appear and what they may contain
9
ANY Cont… 9 July 3, 2003 CBS WCBS 2 Hollywood Squares 19:00-0500 Figure 1: A Document That’s Valid According to the DTD
10
ANY Cont… 10 Frank Oz Yoda May 25, 1944 Figure 1: A Document That’s invalid According to the DTD
11
#PCDATA 11 When we want to specify that an element will only contain text, and no child elements, we use the keyword #PCDATA Because this keyword specifies that the element must contain parsable character data – that is, any text except the characters less-than ( ), ampersand (&), quote(') and double quote (")
12
#PCDATA 12 July 3, 2003 This declaration indicate text only. No child element is allowed
13
#PCDATA cont… 13 July 3 2003 However, this DATE element is invalid because it contains child elements
14
Child Elements 14 The first child element is date To declare that a SCHEDULE must have a date, we simply add pair of parentheses What this simply mean is that each SCHEDULE element should contain exactly one DATE child element
15
Child Elements cont.. 15 This kind of declaration is called a sequence. The above mean each SCHEDULE element should contain exactly one DATE child element, followed by exactly three STATION elements.
16
Child Elements cont.. 16 Each element should be declared in its own declaration exactly once
17
Child Elements cont.. 17 + One or More Children Use plus sign (+) after element name in the child list The above example mean STATION element have one or more STATION elements
18
Child Elements cont.. 18 ? Zero or One Child We can indicate that a child is optional in a sequence, that is, it can appear or not by suffixing its name with a ? <!ELEMENT ACTOR (GIVEN_NAME?, MIDDLE_NAME?, MIDDLE_INITIAL?, SURNAME?)> <!ELEMENT WRITER (GIVEN_NAME?, MIDDLE_NAME?, MIDDLE_INITIAL?, SURNAME?)> <!ELEMENT PRODUCER (GIVEN_NAME?, MIDDLE_NAME?, MIDDLE_INITIAL?, SURNAME?)>
19
Child Elements cont.. 19 This above indicate that the STATION can Either have a NETWORK,CALL_LETTER, or One or more SHOW, and ONE CHANNEL
20
Child Elements cont.. 20 * Zero or More Children This mean that that a child can appears zero or more times Can be use for middle names or middle initials <!ELEMENT ACTOR (GIVEN_NAME?, MIDDLE_NAME*, MIDDLE_INITIAL*, SURNAME?)> <!ELEMENT WRITER (GIVEN_NAME?, MIDDLE_NAME?*, MIDDLE_INITIAL*, SURNAME?)> <!ELEMENT PRODUCER (GIVEN_NAME?, MIDDLE_NAME*, MIDDLE_INITIAL*, SURNAME?)> <!ELEMENT DIRECTOR (GIVEN_NAME?, MIDDLE_NAME*, MIDDLE_INITIAL*, SURNAME?)>
21
Child Elements cont.. 21 potential child elements of SHOW can appear once, several times, or not at all, including PRODUCER, DIRECTOR, and WRITER
22
Child Elements cont.. 22 Choices We can use vertical bar (|) to indicate choice rather than with a comma(,) in the parent element declaration The PAYMENT element must have a single child element of type CASH or CREDIT_CARD This sort of content specification is called a choice
23
Child Elements cont.. 23 Parentheses Each set of parentheses combines several elements so that the combination is treated as a single unit when validating This parenthesized unit can then be nested inside other parentheses in place of a single element You can then affix a plus sign, an asterisk, or a question mark to it
24
Child Elements cont.. 24 Parentheses cont … Both choices and sequences appear in parentheses These parentheses can also have +, *, or ? quantifiers suffixed to them this declaration says that an ACTOR element can have one or more of GIVEN_NAME, MIDDLE_NAME, MIDDLE_INITIAL, or SURNAME child elements
25
Mixed Content 25 mixed content You can declare tags that contain both child elements and character data. This is called mixed content The above declaration allow each CAST to include text as well as Actor child elements
26
Empty Elements 26 Element with no content <!DOCTYPE DOCUMENT [ <!ELEMENT SIGNATURE (HR, COPYRIGHT, BR, EMAIL, BR, LAST_MODIFIED)> ]> <!DOCTYPE DOCUMENT [ <!ELEMENT SIGNATURE (HR, COPYRIGHT, BR, EMAIL, BR, LAST_MODIFIED)> ]> Empty-element Tags 2003 Elliotte Rusty Harold elharo@metalab.unc.edu Wednesday, December 3, 2003 Empty-element Tags 2003 Elliotte Rusty Harold elharo@metalab.unc.edu Wednesday, December 3, 2003
27
Comments in DTDs 27 DTDs can contain comments, just like the rest of an XML document These comments cannot appear inside a declaration, but they can appear outside one Comments are often used to organize the DTD in different parts Comments, is only for the benefit of people reading the source code. XML processors will ignore it
28
Comments in DTDs cont… 28 <!-- A date in the form Month Day, Year The year is always written with four digits. -- > DTDs often use comments to indicate Who wrote the DTD Copyright for the DTD Usage conditions Usage instructions Customary PUBLIC and SYSTEM identifiers
29
references 29 http://stackoverflow.com/questions/918450/difference-between- pcdata-and-cdata-in-dtd http://stackoverflow.com/questions/918450/difference-between- pcdata-and-cdata-in-dtd
Similar presentations
© 2024 SlidePlayer.com Inc.
All rights reserved.