Date post: | 22-Dec-2015 |
Category: |
Documents |
View: | 214 times |
Download: | 0 times |
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.
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>
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>
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>
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>
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.
8
Simple Type Derivation
• Derivation by Restriction.– use the xs:restriction
• Derivation by List
• Derivation by Union
9
Restriction
• Restriction can be used to:– specify a range.– specify the length of a string.– specify pattern of a string.– etc
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>
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”>
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>
13
Enumerated Values
<?xml version="1.0"?>
<size xsi:noNamespaceSchemaLocation="enum.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">XL</size>
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>
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.
– ?, +, *
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
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>
18
Derivation by List
<xs:element name="size">
<xs:simpleType>
<xs:list itemType="xs:integer"/>
</xs:simpleType>
</xs:element>
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.
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>
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>
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>
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
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>
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>
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>
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>
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>
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>
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>
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