+ All Categories
Home > Documents > 1 XML Schema Information Retrieval Systems Maria Indrawan 2003.

1 XML Schema Information Retrieval Systems Maria Indrawan 2003.

Date post: 22-Dec-2015
Category:
View: 214 times
Download: 0 times
Share this document with a friend
31
1 XML Schema Information Retrieval Systems Maria Indrawan 2003
Transcript
Page 1: 1 XML Schema Information Retrieval Systems Maria Indrawan 2003.

1

XML Schema

Information Retrieval Systems

Maria Indrawan 2003

Page 2: 1 XML Schema Information Retrieval Systems Maria Indrawan 2003.

2

Complex Type with Attribute

• The declaration of attributes need to be placed after the declaration of child elements.

Page 3: 1 XML Schema Information Retrieval Systems Maria Indrawan 2003.

3

ComplexType with Attribute

<?xml version="1.0"?><xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"><xs:element name="person">

<xs:complexType><xs:sequence>

<xs:element name="firstname" type="xs:string"/>

<xs:element name="lastname" type="xs:string"/>

</xs:sequence><xs:attribute name="ID" type="xs:ID"/>

</xs:complexType></xs:element></xs:schema>

Page 4: 1 XML Schema Information Retrieval Systems Maria Indrawan 2003.

4

Anonymous Type• A type that is defined without a name

associated with it. <xs:complexType>

<xs:simpleContent><xs:extension base="xs:string">

<xs:attribute name="language" type="xs:string" use="required"/>

</xs:extension></xs:simpleContent>

</xs:complexType>

Page 5: 1 XML Schema Information Retrieval Systems Maria Indrawan 2003.

5

Named Type<?xml version="1.0" encoding="UTF-8"?><xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">

<xs:complexType name="person"><xs:sequence><xs:element name="firstname" type="xs:string"/><xs:element name="lastname" type="xs:string"/></xs:sequence></xs:complexType><xs:element name="book"><xs:complexType><xs:sequence><xs:element name="author" type="person"/><xs:element name="editor" type="person"/></xs:sequence></xs:complexType></xs:element>

</xs:schema>

Page 6: 1 XML Schema Information Retrieval Systems Maria Indrawan 2003.

6

Named Type

<?xml version="1.0" encoding="UTF-8"?><book xmlns:xsi="http://www.w3.org/2001/XMLSchema-

instance" xsi:noNamespaceSchemaLocation="namedType.xsd"><author><firstname>John</firstname><lastname>Howard</lastname></author><editor><firstname>George</firstname><lastname>Bush</lastname></editor>

</book>

Page 7: 1 XML Schema Information Retrieval Systems Maria Indrawan 2003.

7

Derived Data Type

• Derived data types can be created using an extension or restriction methods.

• Extension is similar to the concept of generalisation in OO modelling.

• Restriction is similar to the concept of inheritance in OO modelling.

Page 8: 1 XML Schema Information Retrieval Systems Maria Indrawan 2003.

8

Simple Type Derivation

• Derivation by Restriction.– use the xs:restriction

• Derivation by List

• Derivation by Union

Page 9: 1 XML Schema Information Retrieval Systems Maria Indrawan 2003.

9

Restriction

• Restriction can be used to:– specify a range.– specify the length of a string.– specify pattern of a string.– etc

Page 10: 1 XML Schema Information Retrieval Systems Maria Indrawan 2003.

10

Restriction – Range

<?xml version="1.0"?>

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">

<xs:element name="myAge">

<xs:simpleType>

<xs:restriction base="xs:decimal">

<xs:totalDigits value="2"/>

</xs:restriction>

</xs:simpleType>

</xs:schema>

Page 11: 1 XML Schema Information Retrieval Systems Maria Indrawan 2003.

11

Restriction – Range

• Restriction– Example : height integer 150 to 250 cm

<xs:simpleType name=“height”>

<xs:restriction base=“xs:integer”>

<xs:minInclusive value=“150”/>

<xs:maxExclusive value=“251”/>

</xs:restriction>

</xs:simpleType>

<xs:element name=“studentHeight” type=“height”>

Page 12: 1 XML Schema Information Retrieval Systems Maria Indrawan 2003.

12

Restriction – Enumerated Values

<?xml version="1.0"?><xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">

<xs:element name="size"><xs:simpleType>

<xs:restriction base="xs:string"><xs:enumeration value="S"/><xs:enumeration value="M"/><xs:enumeration value="L"/><xs:enumeration value="XL"/>

</xs:restriction></xs:simpleType>

</xs:element></xs:schema>

Page 13: 1 XML Schema Information Retrieval Systems Maria Indrawan 2003.

13

Enumerated Values

<?xml version="1.0"?>

<size xsi:noNamespaceSchemaLocation="enum.xsd"

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">XL</size>

Page 14: 1 XML Schema Information Retrieval Systems Maria Indrawan 2003.

14

Restriction - Pattern

• Victorian Number Plate.– 3 digits character followed by 3 digits number.

<xs:element name="numberPlate">

<xs:simpleType>

<xs:restriction base="xs:string">

<xs:length value="6"/>

<xs:pattern value="[A-Z]{3}[0-9]{3}"/>

</xs:restriction>

</xs:simpleType>

</xs:element>

Page 15: 1 XML Schema Information Retrieval Systems Maria Indrawan 2003.

15

Regular Expression

• A pattern definition language used to perform pattern matching.

• Characters used in regular expression:– Bound

• {n} specifies the exact number of times for the preceeding item to match.

• {n,} specifices the minimum number of times for the preceeding item to match.

• {n,m} specifies the minimum(n) and the maximum(m) nuber of times for the preceeding item to match.

– ?, +, *

Page 16: 1 XML Schema Information Retrieval Systems Maria Indrawan 2003.

16

Regular Expression

– Bracket• [] => Matches one of any character enclosed, eg. [abcd]• [lowerBound-upperBound] => Matches any character within the

range of lowerBound and upperBound, eg [1-9].• [^] => Matches any character EXCEPT those enclosed, eg [cat]

Examples:– “0{0,2}1?5?

• 0{0,2} => up to two 0s are permitted.• 1?=> 0 or 1 occurrence of the number “1”• 5?=> 0 or 1 occurrence of the number “5”• Correct values: 0015, 1, 5• Incorrect values: 25, 0001

Page 17: 1 XML Schema Information Retrieval Systems Maria Indrawan 2003.

17

Derivation by List

• Derivation by list is the mechanism by which a list data type can be derived from an atomic data type.

• All the items in the list need to have the same data type.

• Example: <integerList> 5 6 7 8 9 10 11</integerList>

Page 18: 1 XML Schema Information Retrieval Systems Maria Indrawan 2003.

18

Derivation by List

<xs:element name="size">

<xs:simpleType>

<xs:list itemType="xs:integer"/>

</xs:simpleType>

</xs:element>

Page 19: 1 XML Schema Information Retrieval Systems Maria Indrawan 2003.

19

Derivation by Union

• Derivation by union allows the definition of a new data type by merging of several predefined or user derived data types.

Page 20: 1 XML Schema Information Retrieval Systems Maria Indrawan 2003.

20

Derivation by Union

<?xml version="1.0"?>

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">

<xs:simpleType name="sizeLetter">

<xs:restriction base="xs:string">

<xs:enumeration value="S"/>

<xs:enumeration value="M"/>

<xs:enumeration value="L"/>

<xs:enumeration value="XL"/>

</xs:restriction>

</xs:simpleType>

Page 21: 1 XML Schema Information Retrieval Systems Maria Indrawan 2003.

21

Derivation by Union (con’t)

<xs:simpleType name="sizeNumber">

<xs:restriction base="xs:integer">

<xs:enumeration value="26"/>

<xs:enumeration value="30"/>

<xs:enumeration value="34"/>

<xs:enumeration value="38"/>

</xs:restriction>

</xs:simpleType>

Page 22: 1 XML Schema Information Retrieval Systems Maria Indrawan 2003.

22

Derivation by Union (con’t)

<xs:element name="myJeans"><xs:complexType>

<xs:simpleContent><xs:extension base="xs:string">

<xs:attribute name="size"><xs:simpleType>

<xs:union memberTypes="sizeNumber sizeLetter"/>

</xs:simpleType></xs:attribute>

</xs:extension></xs:simpleContent>

</xs:complexType></xs:element></xs:schema>

Page 23: 1 XML Schema Information Retrieval Systems Maria Indrawan 2003.

23

Derivation of a Complex Type

• Extension– add child-elements

• cannot be used in a simple content complex type

– add attributes

• Restriction– removing child-elements or attributes

Page 24: 1 XML Schema Information Retrieval Systems Maria Indrawan 2003.

24

Adding a Child-element

<xs:element name="author“>

<xs:complexType>

<xs:complexContent>

<xs:extension base="person">

<xs:sequence>

<xs:element name="nationality“ type="xs:string"/>

</xs:sequence>

</xs:extension>

</xs:complexContent>

</xs:complexType>

</xs:element>

Page 25: 1 XML Schema Information Retrieval Systems Maria Indrawan 2003.

25

Adding an Attribute (1)

<!–- Adding an attribute to a simple type to make a complex type

<xs:element name="title"><xs:complexType>

<xs:simpleContent><xs:extension base="xs:string">

<xs:attribute name="language" type="xs:string"

use="required"/></xs:extension>

</xs:simpleContent></xs:complexType>

</xs:element>

Page 26: 1 XML Schema Information Retrieval Systems Maria Indrawan 2003.

26

Adding an Attribute (2)

<!–- adding an attribute to a complex type

<xs:element name="author">

<xs:complexType>

<xs:complexContent>

<xs:extension base="person">

<xs:attribute name="sex"/>

</xs:extension>

</xs:complexContent>

</xs:complexType>

</xs:element>

Page 27: 1 XML Schema Information Retrieval Systems Maria Indrawan 2003.

27

Removing a Child-Element

<?xml version="1.0"?>

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">

<xs:complexType name="person">

<xs:sequence>

<xs:element name="firstname" type="xs:string"/>

<xs:element name="lastname" type="xs:string"/>

</xs:sequence>

</xs:complexType>

Page 28: 1 XML Schema Information Retrieval Systems Maria Indrawan 2003.

28

<xs:element name="book"><xs:complexType>

<xs:sequence><xs:element name="author">

<xs:complexType><xs:complexContent>

<xs:restriction base="person"><xs:sequence>

<xs:element name="lastname" type="xs:string"/></xs:sequence>

</xs:restriction></xs:complexContent>

</xs:complexType></xs:element>

<xs:element name="editor" type="person"/></xs:sequence>

</xs:complexType></xs:element></xs:schema>

Page 29: 1 XML Schema Information Retrieval Systems Maria Indrawan 2003.

29

Removing Attribute<xs:element name="book">

<xs:complexType><xs:sequence><xs:element name="author"><xs:complexType><xs:complexContent><xs:restriction base="person"><xs:sequence><xs:element name="firstname" type="xs:string"/><xs:element name="lastname" type="xs:string"/></xs:sequence><xs:attribute name="nationality" type="xs:string" use="prohibited"/></xs:restriction></xs:complexContent></xs:complexType></xs:element><xs:element name="editor" type="person"/></xs:sequence></xs:complexType></xs:element>

</xs:schema>

Page 30: 1 XML Schema Information Retrieval Systems Maria Indrawan 2003.

30

Global Declaration

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"><xs:element name="author" type="xs:string"/><xs:element name="editor" type="xs:string"/><xs:element name="title" type="xs:string"/><xs:element name="book">

<xs:complexType><xs:sequence>

<xs:element ref="author"/><xs:element ref="editor"/><xs:element ref="title"/>

</xs:sequence></xs:complexType>

</xs:element></xs:schema>

Page 31: 1 XML Schema Information Retrieval Systems Maria Indrawan 2003.

31

y

y

Summary

element model group

xs:sequence xs:choicexs:all

Named Type exist?

type=complexType

y type=“nameType” modify the namedType?

primitive dataType?

simpleType “type= xs:..”

y

n

modify? restriction

y

add element/attr ?

restriction

extension

nchild element?

n

n

y textNode? ymixed

Contentn

y

y

textNode?

simpleContent

attribute(s)?

emptyContentn


Recommended