Presentation is loading. Please wait.

Presentation is loading. Please wait.

Www.monash.edu.au CSE4500 Information Retrieval Systems XML Schema – Part 1.

Similar presentations


Presentation on theme: "Www.monash.edu.au CSE4500 Information Retrieval Systems XML Schema – Part 1."— Presentation transcript:

1 www.monash.edu.au CSE4500 Information Retrieval Systems XML Schema – Part 1

2 www.monash.edu.au 2 Why Schema? Expressed in XML Ability to derive new data type Extensible Self Documenting

3 www.monash.edu.au 3 Example- XML Doc John Howard George W Bush Memoir of Saddam

4 www.monash.edu.au 4 Example- Schema File http://www.w3.org/2001/XMLSchema

5 www.monash.edu.au 5 Attaching document to a schema XML document entry: XML Schema entry:

6 www.monash.edu.au 6 Element Content Models - revisited Content Models: –Any –Empty >no child element nor text node are expected. –Simple (text only) >only text node is expected –Complex (element only) >only child element is expected –Mixed >both child element and text node are expected Attributes, Comments and Processing Instructions are ignored.

7 www.monash.edu.au 7 Data Types Simple Type –contains a simple (text only) without any attribute. Complex Type –May contain any, empty, simple, complex (element only), or mixed content model. –A simple content with an attribute is considered as a complex type. –All complex types are user-derived data types.

8 www.monash.edu.au 8 Data Types Built-in data types –Data types that are defined in the W3C’s specification. –http://www.w3.org/TR/xmlschema-2/#built-in-datatypes >Primitive data types –eg string, date, float, decimal, etc >Derived data types –eg interger, nonNegativeInteger. These are derived from decimal. –Example:

9 www.monash.edu.au 9 Data Types User-derived data types –Data types that are defined by the XML Schema designer. –Example: <xs:element name="title” type="xs:string“/> <xs:element name=“publisher” type="xs:string"/> </xs:element

10 www.monash.edu.au 10 Declaration vs Definition Declaration –It is used to declare an element or an attribute with its associated name and data type. – Definition –It is used to define a user derived data type.

11 www.monash.edu.au 11 Element Declaration Examples: Simple type Complex Type <xs:element name="title” type="xs:string“/>< <xs:element name=“publisher” type="xs:string"/> </xs:element

12 www.monash.edu.au 12 Attribute Declaration The data type of an attribute is always a simple type. Possible values for attribute use >required >prohibited >optional –The default value is optional –Prohibited mainly used to create a derived type without the concerned attribute.

13 www.monash.edu.au 13 Simple Type with Simple Content (1) Harry Potter and The Philosopher Stone element title is a simple type

14 www.monash.edu.au 14 Simple Type with Simple Content (2) Harry Potter and The Philosopher Stone element title IS NOT a simple type (it is a complex type) attribute language is a simple type

15 www.monash.edu.au 15 Complex Type Definition Harry Potter and The Philosopher Stone element book and title is a complex type

16 www.monash.edu.au 16 ComplexType Example <xs:attribute name="language" type="xs:string" use="required"/>

17 www.monash.edu.au 17 Complex Type with Simple Content Harry Potter and The Philosopher Stone

18 www.monash.edu.au 18 Complex Type with Complex Content A complex content model contains one or more child elements. The structure of child elements is determined by the following keywords: –sequence –choice –all

19 www.monash.edu.au 19 Sequence Ordered List Professional XML WROX

20 www.monash.edu.au 20 Choice – XML Schema

21 www.monash.edu.au 21 Choice – XML Document George Walker Bush Howard John

22 www.monash.edu.au 22 All unordered list cardinality of each member of the list is 1(maxOccur=1 and minOccurs=1) cardinality of the list can be either 0 or 1 –0 => minOccurs=0, maxOccurs=1 –1 => minOccurs=1, maxOccurs=1

23 www.monash.edu.au 23 All – XML Schema

24 www.monash.edu.au 24 All – XML Doc George Bush John Howard

25 www.monash.edu.au 25 Complex Type with Empty Content There are two ways that an empty content model for the complex type can be created: –Verbose >As a restriction of an ANY type –Compact >Omitting the keyword for defining the content model. Example: –Break element in an HTML =>

26 www.monash.edu.au 26 Verbose

27 www.monash.edu.au 27 Compact

28 www.monash.edu.au 28 Complex Content with Mixed Content <book xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="mixedContent.xsd"> Harry Potter and The Philosopher's Stone written by J.K Rowling book element has a mixed content model

29 www.monash.edu.au 29 Complex Type with Mixed Content

30 www.monash.edu.au 30 Attaching an Attribute to an Element The content model of an element determines the method used to attach an attribute to the element.

31 www.monash.edu.au 31 Attaching an attribute to an element with a simple content Use an extension of a simple type <xs:attribute name="language” type="xs:string“ use="required"/>

32 www.monash.edu.au 32 Attaching an attribute to an element with a complex content To attach an attribute to the element in this category, we place the declaration of attribute after the declaration of child elements.

33 www.monash.edu.au 33 Attaching an attribute to an element with an empty content The declaration of the attribute is placed within the definition of a complexType. <xs:attribute name="src" type="xs:string" use="required"/>

34 www.monash.edu.au 34 Cardinality The number of the minimum and the maximum instances in a given element can be specified using the attributes minOccurs and maxOccurs. The default values for the maximum and the minimum are ONE. Example: <xs:element name="title" type="xs:string" minOccurs=“0” maxOccurs="unbounded"/>

35 www.monash.edu.au 35 Week 3 Reflection Content ModelAttributeData Type EmptyN/A? Simple (text only)Yes? Simple (text only)No? Complex (element only) N/A? MixedN/A?


Download ppt "Www.monash.edu.au CSE4500 Information Retrieval Systems XML Schema – Part 1."

Similar presentations


Ads by Google