CSE3201 Information Retrieval Systems XML Schema – Part 2
2 XML Schema – Part 1 Data Type. Content Model. Relations between data types and content models.
3 XML Schema – Part 2 Anonymous vs Named Type. Derivation of –Simple Type. –Complex Type. Scoping. Designing and Writing XML Schema.
4 Anonymous vs Named Data Type A user-derived data type can be either an anonymous or named data type. A named type allow us to re-use user defined data-types.
5 Anonymous Type A type that is defined without an associated name. Example: <xs:attribute name="language" type="xs:string" use="required"/>
6 Named Type
7 Named Type John Howard George Bush
8 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.
9 Simple Type Derivation Derivation by Restriction. –use the xs:restriction Derivation by List Derivation by Union Derivation by extension is not possible for a simple type.
10 Restriction Restriction can be used to: –specify a range. –specify the length of a string. –specify pattern of a string. –etc
11 Restriction – Range
12 Restriction – Range Restriction –Example : height integer 150 to 250 cm
13 Restriction – Enumerated Values
14 Enumerated Values <size xsi:noNamespaceSchemaLocation="enum.xsd" xmlns:xsi="
15 Restriction - Pattern Victorian Number Plate. –3 digits character followed by 3 digits number.
16 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. –?, +, *
17 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
18 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:
19 Derivation by List
20 Derivation by Union Derivation by union allows the definition of a new data type by merging of several built-in or user derived data types.
21 Derivation by Union
22 Derivation by Union (con’t)
23 Derivation by Union (con’t)
24 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
25 Person Named Type
26 Adding a Child-element
27 Adding an Attribute (1) <!–- Adding an attribute to a simple type to make a complex type
28 Adding an Attribute (2) <!–- adding an attribute to a complex type
29 Removing a Child Element
30 Person with Attribute – Named Type
31 Removing Attribute
32 Scope of a Declaration and Definition An element or an attribute can be declared as either a local or global declaration. An element or attribute declared as a child of a schema declaration is considered as a global element or attribute. An element or attribute declared as a child of another element declaration is considered a local element or attribute.
33 Global Declaration <xs:element name=“yearPublished” type=“xs:gYear”/> Elements author, editor, title and book are global elements. The element yearPublished is a local element.
34 Global or Local Declaration? Russian Doll –Use only the local declarations. Salami –Use only the global declarations. Venetian Blind –Use namedType.
35 Russian Doll Design
36 Salami Design
37 Venetian Design
38 Which one to use? Read –Global versus Local -
39 Named Type vs Global Declaration - Schema Named Type <xs:element name="firstname“ type="xs:string"/> <xs:element name="lastname“ type="xs:string"/> <xs:element name=“author” type=“person”/> Global Declaration <xs:element name="firstname“ type="xs:string"/> <xs:element name="lastname“ type="xs:string"/>
40 Named Type vs Global Declaration - XML Named Type <author xsi:noNamespaceSchemaLocation="na medTypeAuthor.xsd" xmlns:xsi=" /XMLSchema-instance"> Maria Indrawan Global Declaration <author xsi:noNamespaceSchemaLocation= "authorGlobal.xml“ xmlns:xsi=" 2001/XMLSchema-instance"> Maria Indrawan
41 Steps in Creating an XML Schema Identify possible elements. Visualise the relations between the elements (structure) using a diagram, eg tree diagram. Add attributes or change some elements to attributes when necessary. Consider the application of specific business rules, eg ranges, cardinality. Consider the possibility of re-use for some of the elements/attributes. –Consider named type and global declaration. Write the schema.
42 Writing the Schema Check the writeSchema.pdf.