Presentation is loading. Please wait.

Presentation is loading. Please wait.

SNU OOPSLA Lab. Logical structure © copyright 2001 SNU OOPSLA Lab.

Similar presentations


Presentation on theme: "SNU OOPSLA Lab. Logical structure © copyright 2001 SNU OOPSLA Lab."— Presentation transcript:

1 SNU OOPSLA Lab. Logical structure © copyright 2001 SNU OOPSLA Lab.

2 SNU OOPSLA Lab. Contents Concepts DTD Structure Element Declaration Attribute Declarations Parameter Entities Conditional Sections Notation Declarations DTD Processing Issues

3 SNU OOPSLA Lab. Concepts of DTD(1) DTD(Document Type Definition) –An optional but powerful feature of XML –Comprises a set of declarations that define a document structure tree –Some XML processors read the DTD and use it to build the document model in memory –Establishes formal document structure rules It define the elements and dictates where they may be applied in relation to each other

4 SNU OOPSLA Lab. Concepts of DTD(2) Declare Vs. Define –Declare  “This document is a concert poster” –Define  “A concert poster must have the following features” DTD define –Element type + Attribute + Entities Valid Vs. Invalid –Valid  conforms to DTD –Invalid  fail to conform to DTD Well formed XML Document Valid XML Document

5 SNU OOPSLA Lab. Valid & Invalid Documents Valid: various random text but no markup Invalid: anything else including various random text –or various random text

6 SNU OOPSLA Lab. DTD structure DTD is composed of a number of declarations –ELEMENT (tag definition) –ATTLIST (attribute definitions) –ENTITY (entity definition) –NOTATION(data type notation definition) DTD can be stored in an external subset or an internal subset

7 SNU OOPSLA Lab. Internal and External Subset(1) Internal subset –Form : <!DOCTYOE … [ … ]> –Pros Easy to write XML –Cons Editing two files without moving Other document can’t reuse without copying internal subset

8 SNU OOPSLA Lab. Internal and External Subset(2) External subset –better to use external DTDs –Reason why? Many benefits –document management –updating –editing Few reasons –If you use an external DTD, you can use public DTDs(capability) –External DTDs provide for better document management –External DTDs make it easier to validate you document

9 SNU OOPSLA Lab. Element Declarations Used to define a new element, specify its allowed content and gives the name and content model of the element Each tag must be declared in a declar ation. The content model uses a simple regular expression-l ike grammar to precisely specify what is and isn't allo wed in an element ELEMENT Type declaration ‘ ’

10 SNU OOPSLA Lab. Content Specifications ANY #PCDATA Sequences Choices Mixed Content Modifiers Empty

11 SNU OOPSLA Lab. ANY A SEASON can contain any child element an d/or raw text (parsed character data) Rarely used in practice, due to the lack of con straint on structure it encourages.

12 SNU OOPSLA Lab. #PCDATA Parsed Character Data; i.e. raw text, no mark up Represent normal data and preceded by the hash-symbol, ‘#’, to avoid confusion with an i dentical element name, when used within a m odel group ( for example, ‘(#PCDATA | PCDATA)’)

13 SNU OOPSLA Lab. Use of #PCDATA in XML Valid: Invalid: 1999 99 1999.E. The year of our Lord one thousand, nine hundred, and ninety-nine January February March April May June July August September October November December

14 SNU OOPSLA Lab. Child Elements To declare that a LEAGUE element must have a LEAGUE_NAME child:

15 SNU OOPSLA Lab. Sequences(1) Separate multiple required child elements wit h commas; e.g. One or More Children +

16 SNU OOPSLA Lab. Sequences(1) Zero or More Children * Choices

17 SNU OOPSLA Lab. Grouping With Parentheses Parentheses combine several elements into a sin gle element. Parenthesized element can be nested inside othe r parentheses in place of a single element. The parenthesized element can be suffixed with a plus sign, a comma, or a question mark.

18 SNU OOPSLA Lab. Mixed Content Both #PCDATA and child elements in a choic e #PCDATA must come first #PCDATA cannot be used in a sequence Empty elements

19 SNU OOPSLA Lab. Attribute Declarations Consider this element: It is declared like this: Hola!

20 SNU OOPSLA Lab. Multiple Attribute Declarations Consider this element With two attribute declarations: With one attribute declaration Indentation is a convetion, not a requirement <!ATTLIST RECTANGLE LENGTH CDATA "0px" WIDTH CDATA "0px">

21 SNU OOPSLA Lab. Attribute Types CDATA ID IDREF IDREFS ENTITY ENTITIES NOTATION NMTOKEN NMTOKENS Enumerated

22 SNU OOPSLA Lab. CDATA Most general attribute type Value can be any string of text not containing a less-than sign (<) or quotation marks (")

23 SNU OOPSLA Lab. ID Value must be an XML name –May include letters, digits, underscores, hyphens, and periods –May not include whitespace –May contain colons only if used for namespaces Value must be unique within ID type attributes in the document Generally the default value is #REQUIRED

24 SNU OOPSLA Lab. IDREF Value matches the ID of an element in the sam e document Used for links and the like IDREFS A list of ID values in the same document Separated by white space

25 SNU OOPSLA Lab. ENTITY Value is the name of an unparsed general ent ity declared in the DTD ENTITIES Value is a list of unparsed general entities declared in the DTD Separated by white space

26 SNU OOPSLA Lab. NOTATION Value is the name of a notation declared in th e DTD TEXVIEW.EXE LOGO.TEX 1 2 3 4

27 SNU OOPSLA Lab. NMTOKEN Value is any legal XML name NMTOKENS Value is a list of XML names Separated by white space

28 SNU OOPSLA Lab. Enumerated Not a keyword Refers to a list of possible values from which one must be chosen Default value is generally provided explicitly

29 SNU OOPSLA Lab. Attribute Default Values A literal string value One of these three keywords –#REQUIRED –#IMPLIED –#FIXED

30 SNU OOPSLA Lab. #REQUIRED No default value is provided in the DTD Document authors must provide attribute value for each element

31 SNU OOPSLA Lab. #IMPLIED No default value in the DTD Author may(but does not have to) provide a v alue with each element

32 SNU OOPSLA Lab. #FIXED Value is the same for all elements Default value must be provided in DTD Document author may not change default value

33 SNU OOPSLA Lab. Example of Internal DTDs <!DOCTYPE GREETING [ ]> Hello XML!

34 SNU OOPSLA Lab. Internal DTD Subsets Internal declarations override external decla rations <!DOCTYPE GREETING SYSTEM "greeting.dtd" [ ]> Hello XML!


Download ppt "SNU OOPSLA Lab. Logical structure © copyright 2001 SNU OOPSLA Lab."

Similar presentations


Ads by Google