Presentation is loading. Please wait.

Presentation is loading. Please wait.

VICTORIA UNIVERSITY OF WELLINGTON Te Whare Wananga o te Upoko o te Ika a Maui SWEN 432 Advanced Database Design and Implementation Document Type Definition.

Similar presentations


Presentation on theme: "VICTORIA UNIVERSITY OF WELLINGTON Te Whare Wananga o te Upoko o te Ika a Maui SWEN 432 Advanced Database Design and Implementation Document Type Definition."— Presentation transcript:

1 VICTORIA UNIVERSITY OF WELLINGTON Te Whare Wananga o te Upoko o te Ika a Maui SWEN 432 Advanced Database Design and Implementation Document Type Definition Lecturer : Dr. Pavle Mogin

2 SWEN 432 Advanced Database Design and Implementation 2015 DTD 1 Plan for the DTD Topic General remarks about the Document Type Definition (DTD) The structure of a DTD Components of a DTD: –Elements, –Attributes, Reading: –Extensible Markup Language (XML) 1.0 W3C Recommendation 04 February 2004 http://www.w3.org/TR/2004/REC-xml-20040204 –Any book on XML

3 SWEN 432 Advanced Database Design and Implementation 2015 DTD 2 Motives If we create an XML document that is well formed and send it to a communicating party, she/he will understand it, since XML is self explaining But the communicating party will never be sure whether the information received is complete, whether there is anything missing or incorrect So, if we want to exchange documents with a common: –Structure, –Meaning, and –Constraints we need a language to define languages – a meta language Using a meta language, we develop a new language and share its definition with all communicating parties

4 SWEN 432 Advanced Database Design and Implementation 2015 DTD 3 Document Type Definition (DTD) Document Type Definition (DTD) is a set of declarations used to define a language (meta language) DTD is an overloaded term –DTD is a meta language –DTD is a particular language (set of rules that language sentences have to obey) A particular DTD is a grammar of a language that indicates: –What elements are allowed, –Constraints on elements allowed, –In what order elements can appear –How the elements can be nested, –What attributes an element may contain, and –Constraints on element and attribute values All not mentioned in a DTD is not allowed in documents that are made according to that DTD

5 SWEN 432 Advanced Database Design and Implementation 2015 DTD 4 A Valid XML Document A DTD can be included in a file that contains the document it describes, or can be linked from an external file An XML document can also exist without any DTD An XML document is said to be valid if: –A DTD is associated with it, and –It is structured according to the rules set by the DTD A document may be not valid according to a DTD, but still well formed

6 SWEN 432 Advanced Database Design and Implementation 2015 DTD 5 Document Type Declaration A document type declaration specifies the DTD a document uses The document type declaration appears in a document’s prolog, after the XML declaration but before the root element It contains either a DTD, or the URL of a DTD A document type declaration contains or refers to a DTD An XML declaration and a document type declaration form the prolog of a document

7 SWEN 432 Advanced Database Design and Implementation 2015 DTD 6 An XML Document with Prolog <!DOCTYPE GREETING[ ]> Hello SWEN 432 people! Components of the prolog are shaded The DTD is:

8 SWEN 432 Advanced Database Design and Implementation 2015 DTD 7 Syntax of a DT Declaration A DT Declaration The name of a document type declaration has to be the name of the root element –GREETING in our example DTD is a text containing rules of a DTD that is enclosed in [ ] Any document valid with regard to our example DTD must have the root element GREEETING, and this element must be declared in the DTD

9 SWEN 432 Advanced Database Design and Implementation 2015 DTD 8 Sharing Common DTDs A DTD can be shared among many documents Then: –The DTD is linked into the document from an external source –The document is not standalone any more The syntax of a DT Declaration with an external DTD is: Example: <!DOCTYPE GREETING SYSTEM “http://ecs.victoria.ac.nz/Courses/ SWEN432/grt.dtd”> SYSTEM is a key word

10 SWEN 432 Advanced Database Design and Implementation 2015 DTD 9 General Content of a DTD A DTD contains declarations of: –Elements, –Comments –Entities, and –Attributes

11 SWEN 432 Advanced Database Design and Implementation 2015 DTD 10 Basic Element Types Elements have two basic types in XML: –Simple (also terminal) elements that contain only text, which is also known as parsed character data ( #PCDATA ) and –Compound or complex (also non terminal) elements that contain as their content any of the following: Other elements, Attributes, Other elements and free text, Attributes and free text, Other elements, attributes, and free text

12 SWEN 432 Advanced Database Design and Implementation 2015 DTD 11 Element Declaration Each tag used in a valid XML document must be declared with an element declaration in a DTD (Content Model )> An element declaration specifies: –A name, –Allowed components of the element’s content, and –Structural constraints of the components (cardinality and participation constraint) A declaration of components and their structural constraints is also called content specification, or content model, or type

13 SWEN 432 Advanced Database Design and Implementation 2015 DTD 12 Element Content Types Five possible content types: 1.An element (child element), 2.#PCDATA (parsed character data), 3.The special symbol ANY (any content permitted), 4.The special symbol EMPTY (element with no content), and 5.A regular expression constructed from above choices Regular expressions: –exp1, exp2, exp3 : A sequence of regular expressions, –exp* : An expression with zero or more occurrences (Kleene closure), –exp? : An expression with at most one occurrence, –exp+ : An expression with at least one occurrence, –exp1 | exp2 : The element will contain either expression 1 or expression 2 (exclusive or operator, choice)

14 SWEN 432 Advanced Database Design and Implementation 2015 DTD 13 A Simple XML Document COMP 442 Pavle Ahmed 10 Bad Student

15 SWEN 432 Advanced Database Design and Implementation 2015 DTD 14 A DTD for The Simple XML Document The preceding XML document is valid with regard to: <!ELEMENT CLASS (TITLE, LECTURER+, AUDITOR?, STUDENT*)> Discuss: –Content models –Child sequences Note, the order of element declarations is immaterial

16 SWEN 432 Advanced Database Design and Implementation 2015 DTD 15 Choices It is sometimes needed to control the appearance of children with exclusive or like constraints To achieve this the “ | “ operator (union) is used The vertical bar “ | “ operator allows only one of the multiple choices to appear in a valid XML document Example: A regular expression containing choices needs to be deterministic

17 SWEN 432 Advanced Database Design and Implementation 2015 DTD 16 Non Deterministic Reg_Exp XML processors do not accept non deterministic regular expression –A non deterministic regular expression needs to be transformed into a deterministic one, –SWEN224 (Formal Methods) stuff Loosely speaking, a regular expression is non deterministic if the operands of a union expression start with the same element names Example: –Non deterministic: a | (a, b) –Transformation: a | (a, b) ≡ (a, ε) | (a, b) ≡ a, (ε | b) ≡ a, b? ε is the empty string

18 SWEN 432 Advanced Database Design and Implementation 2015 DTD 17 Children with Parentheses Grouping children elements within parentheses allows achieving some special constraints All elements in a pair of parenthesis behave as a single element (with the regard to suffix) You to explain: –Example 1: –Example 2: <!ELEMENT DOCUMENT (TITLE, (PARAGRAPH | IMAGE)*, SIGNATURE?)

19 SWEN 432 Advanced Database Design and Implementation 2015 DTD 18 Mixed Content Content of an XML element can be mixed with child elements and parsed character data One way to achieve this is to use key word ANY The other way is the following construct This is the only construct of mixed element and # PCDATA a DTD can support The best way is: You to comment advantages and disadvantages!

20 SWEN 432 Advanced Database Design and Implementation 2015 DTD 19 Empty Elements In an XML DTD empty elements are identified by empty element declarations: –EMPTY is the declaration of the element’s type In an XML document, an empty element has only the start tag: –With a compulsory name, –A set of attributes (may be empty), and –A compulsory “/” at the end Example: –DTD: –XML document:

21 SWEN 432 Advanced Database Design and Implementation 2015 DTD 20 What Is and What Can Contain an Attribute An attribute is a (name, value) pair, where the name component is separated from the value component by an “=“ sign The name should be an XML valid name The following XML concepts may contain an attribute: –A document declaration –A processing instruction –A start tag of an element –An empty element

22 SWEN 432 Advanced Database Design and Implementation 2015 DTD 21 Declaring Attributes in a DTD The syntax of an attribute declaration in a DTD: Each attribute declaration belongs to exactly one element If two elements have an attribute with the same name, type, and default, this attribute has to be declared twice (each time with a different owner name)

23 SWEN 432 Advanced Database Design and Implementation 2015 DTD 22 An XML Document with Attributes <!DOCTYPE GREETING[ ]> Hello SWEN 432 people!

24 SWEN 432 Advanced Database Design and Implementation 2015 DTD 23 Attribute Types TypeMeaning CDATA Character data – text that is not markup Enumerated A list of possible values from which exactly one will be chosen ID Unique values not shared by any other ID type attribute in the document IDREF The value of an ID type attribute of an element in the document IDREFS Multiple element IDs separated by whitespace There are also other attribute types, but we do not consider them

25 SWEN 432 Advanced Database Design and Implementation 2015 DTD 24 Default Values An attribute default value can be either: –A specific string value, or –One of the key words: #REQUIRED, #IMPLIED (default), or #FIXED (constant value) #REQUIRED means that an attribute value is mandatory #IMPLIED means that an attribute (and it’s value) is optional #FIXED means that the attribute has a fixed (constant) value –If a #FIXED attribute is not included in a document, an XML processor will do it by including the attribute and its default value

26 SWEN 432 Advanced Database Design and Implementation 2015 DTD 25 Enumerated Attribute Type A list of possible values separated by vertical bars Each value must be a valid XML name The default value must be one of the enumerated values An example:

27 SWEN 432 Advanced Database Design and Implementation 2015 DTD 26 ID Attribute Type An ID type attribute value uniquely identifies an element within a document An element can have at most one attribute of the type ID Attributes of the type ID are usually used in conjunction with attributes of the IDREF type

28 SWEN 432 Advanced Database Design and Implementation 2015 DTD 27 IDREF and IDREFS Attribute Types An attribute value of the type IDREF is the ID value of an element in the same document ID and IDREF attribute types are used to connect elements that can not be connected through the tree structure of the document For example, when a child element has more parent elements An attribute of the IDREFS type serves practically the same purpose as an attribute of the IDREF type, except IDREFS means that the attribute is multivalued

29 SWEN 432 Advanced Database Design and Implementation 2015 DTD 28 Example of Using ID and IDREF <!DOCTYPE FAMILY [ ]> (to be continued)

30 SWEN 432 Advanced Database Design and Implementation 2015 DTD 29 Example of Using ID and IDREF (cont) Susan Jack Annie Kirk

31 SWEN 432 Advanced Database Design and Implementation 2015 DTD 30 Recursions A recursion on an element E is expressed by placing: –An element E* into element’s E content model, or –In the content model of its descendant and using attributes of the ID and IDREF types (if needed) By placing E* into content model of E (directly, or via one of its descendants) we enable the element E to appear a large number of times in a document The attributes of the ID and IDREF types are needed only if there is a N:N relationship between E elements having different roles

32 SWEN 432 Advanced Database Design and Implementation 2015 DTD 31 Summary An XML document structure may be defined using: –Document Type Definition, or –XML Schema definition language By defining a DTD schema a new language is introduced The most important components of a DTD are: –Element declarations, and –Attribute declarations The declaration of an element consist of: –An element name, and –An element content model (type), enclosed in parenthesis The declaration of an attribute consists of: –The owner’s name, and –A triple (att_name, att_type, att_default)


Download ppt "VICTORIA UNIVERSITY OF WELLINGTON Te Whare Wananga o te Upoko o te Ika a Maui SWEN 432 Advanced Database Design and Implementation Document Type Definition."

Similar presentations


Ads by Google