XML Schema - PowerPoint PPT Presentation

1 / 31
About This Presentation
Title:

XML Schema

Description:

Regular Expression. A pattern definition language used to perform ... Adding a Child-element xs:element name='author' xs:complexType xs:complexContent ... – PowerPoint PPT presentation

Number of Views:35
Avg rating:3.0/5.0
Slides: 32
Provided by: Indr1
Category:

less

Transcript and Presenter's Notes

Title: XML Schema


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
  • lt?xml version"1.0"?gt
  • ltxsschema xmlnsxs"http//www.w3.org/2001/XMLSch
    ema"gt
  • ltxselement name"person"gt
  • ltxscomplexTypegt
  • ltxssequencegt
  • ltxselement name"firstname"
    type"xsstring"/gt
  • ltxselement name"lastname"
    type"xsstring"/gt
  • lt/xssequencegt
  • ltxsattribute name"ID" type"xsID"/gt
  • lt/xscomplexTypegt
  • lt/xselementgt
  • lt/xsschemagt

4
Anonymous Type
  • A type that is defined without a name associated
    with it.
  • ltxscomplexTypegt
  • ltxssimpleContentgt
  • ltxsextension base"xsstring"gt
  • ltxsattribute name"language"
  • type"xsstring"
  • use"required"/gt
  • lt/xsextensiongt
  • lt/xssimpleContentgt
  • lt/xscomplexTypegt

5
Named Type
  • lt?xml version"1.0" encoding"UTF-8"?gt
  • ltxsschema xmlnsxs"http//www.w3.org/2001/XMLSch
    ema"gt
  • ltxscomplexType name"person"gt
  • ltxssequencegt
  • ltxselement name"firstname"
    type"xsstring"/gt
  • ltxselement name"lastname" type"xsstring"/gt
  • lt/xssequencegt
  • lt/xscomplexTypegt
  • ltxselement name"book"gt
  • ltxscomplexTypegt
  • ltxssequencegt
  • ltxselement name"author" type"person"/gt
  • ltxselement name"editor" type"person"/gt
  • lt/xssequencegt
  • lt/xscomplexTypegt
  • lt/xselementgt
  • lt/xsschemagt

6
Named Type
  • lt?xml version"1.0" encoding"UTF-8"?gt
  • ltbook xmlnsxsi"http//www.w3.org/2001/XMLSchema-
    instance" xsinoNamespaceSchemaLocation"namedType
    .xsd"gt
  • ltauthorgt
  • ltfirstnamegtJohnlt/firstnamegt
  • ltlastnamegtHowardlt/lastnamegt
  • lt/authorgt
  • lteditorgt
  • ltfirstnamegtGeorgelt/firstnamegt
  • ltlastnamegtBushlt/lastnamegt
  • lt/editorgt
  • lt/bookgt

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 xsrestriction
  • 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
  • lt?xml version"1.0"?gt
  • ltxsschema xmlnsxs"http//www.w3.org/2001/XMLSch
    ema"gt
  • ltxselement name"myAge"gt
  • ltxssimpleTypegt
  • ltxsrestriction base"xsdecimal"gt
  • ltxstotalDigits value"2"/gt
  • lt/xsrestrictiongt
  • lt/xssimpleTypegt
  • lt/xsschemagt

11
Restriction Range
  • Restriction
  • Example height integer 150 to 250 cm
  • ltxssimpleType nameheightgt
  • ltxsrestriction basexsintegergt
  • ltxsminInclusive value150/gt
  • ltxsmaxExclusive value251/gt
  • lt/xsrestrictiongt
  • lt/xssimpleTypegt
  • ltxselement namestudentHeight typeheightgt

12
Restriction Enumerated Values
  • lt?xml version"1.0"?gt
  • ltxsschema xmlnsxs"http//www.w3.org/2001/XMLSch
    ema"gt
  • ltxselement name"size"gt
  • ltxssimpleTypegt
  • ltxsrestriction base"xsstring"gt
  • ltxsenumeration value"S"/gt
  • ltxsenumeration value"M"/gt
  • ltxsenumeration value"L"/gt
  • ltxsenumeration value"XL"/gt
  • lt/xsrestrictiongt
  • lt/xssimpleTypegt
  • lt/xselementgt
  • lt/xsschemagt

13
Enumerated Values
  • lt?xml version"1.0"?gt
  • ltsize xsinoNamespaceSchemaLocation"enum.xsd"
  • xmlnsxsi"http//www.w3.org/2001/XMLSchema-insta
    nce"gtXLlt/sizegt

14
Restriction - Pattern
  • Victorian Number Plate.
  • 3 digits character followed by 3 digits number.
  • ltxselement name"numberPlate"gt
  • ltxssimpleTypegt
  • ltxsrestriction base"xsstring"gt
  • ltxslength value"6"/gt
  • ltxspattern value"A-Z30-93"/gt
  • lt/xsrestrictiongt
  • lt/xssimpleTypegt
  • lt/xselementgt

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
  • gt Matches one of any character enclosed, eg.
    abcd
  • lowerBound-upperBound gt Matches any character
    within the range of lowerBound and upperBound, eg
    1-9.
  • gt Matches any character EXCEPT those
    enclosed, eg cat
  • Examples
  • 00,21?5?
  • 00,2 gt up to two 0s are permitted.
  • 1?gt 0 or 1 occurrence of the number 1
  • 5?gt 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 ltintegerListgt 5 6 7 8 9 10
    11lt/integerListgt

18
Derivation by List
  • ltxselement name"size"gt
  • ltxssimpleTypegt
  • ltxslist itemType"xsinteger"/gt
  • lt/xssimpleTypegt
  • lt/xselementgt

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
  • lt?xml version"1.0"?gt
  • ltxsschema xmlnsxs"http//www.w3.org/2001/XMLSch
    ema"gt
  • ltxssimpleType name"sizeLetter"gt
  • ltxsrestriction base"xsstring"gt
  • ltxsenumeration value"S"/gt
  • ltxsenumeration value"M"/gt
  • ltxsenumeration value"L"/gt
  • ltxsenumeration value"XL"/gt
  • lt/xsrestrictiongt
  • lt/xssimpleTypegt

21
Derivation by Union (cont)
  • ltxssimpleType name"sizeNumber"gt
  • ltxsrestriction base"xsinteger"gt
  • ltxsenumeration value"26"/gt
  • ltxsenumeration value"30"/gt
  • ltxsenumeration value"34"/gt
  • ltxsenumeration value"38"/gt
  • lt/xsrestrictiongt
  • lt/xssimpleTypegt

22
Derivation by Union (cont)
  • ltxselement name"myJeans"gt
  • ltxscomplexTypegt
  • ltxssimpleContentgt
  • ltxsextension base"xsstring"gt
  • ltxsattribute name"size"gt
  • ltxssimpleTypegt
  • ltxsunion memberTypes"sizeNumber
    sizeLetter"/gt
  • lt/xssimpleTypegt
  • lt/xsattributegt
  • lt/xsextensiongt
  • lt/xssimpleContentgt
  • lt/xscomplexTypegt
  • lt/xselementgt
  • lt/xsschemagt

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
  • ltxselement name"authorgt
  • ltxscomplexTypegt
  • ltxscomplexContentgt
  • ltxsextension base"person"gt
  • ltxssequencegt
  • ltxselement name"nationality
    type"xsstring"/gt
  • lt/xssequencegt
  • lt/xsextensiongt
  • lt/xscomplexContentgt
  • lt/xscomplexTypegt
  • lt/xselementgt

25
Adding an Attribute (1)
  • lt!- Adding an attribute to a simple type to make
    a complex type?
  • ltxselement name"title"gt
  • ltxscomplexTypegt
  • ltxssimpleContentgt
  • ltxsextension base"xsstring"gt
  • ltxsattribute name"language"
    type"xsstring" use"required"/gt
  • lt/xsextensiongt
  • lt/xssimpleContentgt
  • lt/xscomplexTypegt
  • lt/xselementgt

26
Adding an Attribute (2)
  • lt!- adding an attribute to a complex type ?
  • ltxselement name"author"gt
  • ltxscomplexTypegt
  • ltxscomplexContentgt
  • ltxsextension base"person"gt
  • ltxsattribute name"sex"/gt
  • lt/xsextensiongt
  • lt/xscomplexContentgt
  • lt/xscomplexTypegt
  • lt/xselementgt

27
Removing a Child-Element
  • lt?xml version"1.0"?gt
  • ltxsschema xmlnsxs"http//www.w3.org/2001/XMLSch
    ema"gt
  • ltxscomplexType name"person"gt
  • ltxssequencegt
  • ltxselement name"firstname" type"xsstring"/gt
  • ltxselement name"lastname" type"xsstring"/gt
  • lt/xssequencegt
  • lt/xscomplexTypegt

28
  • ltxselement name"book"gt
  • ltxscomplexTypegt
  • ltxssequencegt
  • ltxselement name"author"gt
  • ltxscomplexTypegt
  • ltxscomplexContentgt
  • ltxsrestriction base"person"gt
  • ltxssequencegt
  • ltxselement name"lastname"
    type"xsstring"/gt
  • lt/xssequencegt
  • lt/xsrestrictiongt
  • lt/xscomplexContentgt
  • lt/xscomplexTypegt
  • lt/xselementgt
  • ltxselement name"editor" type"person"/gt
  • lt/xssequencegt
  • lt/xscomplexTypegt
  • lt/xselementgt
  • lt/xsschemagt

29
Removing Attribute
  • ltxselement name"book"gt
  • ltxscomplexTypegt
  • ltxssequencegt
  • ltxselement name"author"gt
  • ltxscomplexTypegt
  • ltxscomplexContentgt
  • ltxsrestriction base"person"gt
  • ltxssequencegt
  • ltxselement name"firstname"
    type"xsstring"/gt
  • ltxselement name"lastname"
    type"xsstring"/gt
  • lt/xssequencegt
  • ltxsattribute name"nationality"
    type"xsstring" use"prohibited"/gt
  • lt/xsrestrictiongt
  • lt/xscomplexContentgt
  • lt/xscomplexTypegt
  • lt/xselementgt
  • ltxselement name"editor" type"person"/gt
  • lt/xssequencegt
  • lt/xscomplexTypegt

30
Global Declaration
  • ltxsschema xmlnsxs"http//www.w3.org/2001/XMLSch
    ema"gt
  • ltxselement name"author" type"xsstring"/gt
  • ltxselement name"editor" type"xsstring"/gt
  • ltxselement name"title" type"xsstring"/gt
  • ltxselement name"book"gt
  • ltxscomplexTypegt
  • ltxssequencegt
  • ltxselement ref"author"/gt
  • ltxselement ref"editor"/gt
  • ltxselement ref"title"/gt
  • lt/xssequencegt
  • lt/xscomplexTypegt
  • lt/xselementgt
  • lt/xsschemagt

31
Summary
y
y
Write a Comment
User Comments (0)
About PowerShow.com