XML Schema - PowerPoint PPT Presentation

About This Presentation
Title:

XML Schema

Description:

Richer set of basic types. Better ways of deriving new type declarations from old ones ... Keys can be defined using XPath expressions xsd:key name='ssn' ... – PowerPoint PPT presentation

Number of Views:27
Avg rating:3.0/5.0
Slides: 13
Provided by: lambd
Learn more at: https://lambda.uta.edu
Category:
Tags: xml | keys | schema

less

Transcript and Presenter's Notes

Title: XML Schema


1
XML Schema
  • Leonidas Fegaras

2
XML Schema
  • Replaces DTD
  • Object-Oriented schemas
  • Richer set of basic types
  • Better ways of deriving new type declarations
    from old ones
  • type extension
  • type restriction
  • Database-style key concept
  • Uses namespaces
  • Compatible with other standards

3
Base Types
  • string, float, double, decimal, boolean
  • timeDuration
  • P10Y1M5T1H20M5S 10years1month5days1hour20'5'
    '
  • binary
  • uriReference
  • QName
  • ID, IDref
  • A basic type may have properties, called facets
  • length, minLength, maxLength
  • minInclusive, maxInclusive, minExclusive,
    maxExclusive
  • enumeration for string
  • pattern for string
  • encoding for binary (eg, base64)

4
Predefined Derived Types
  • Derived by restrictions on facets
  • ltxsdsimpleType name'integer' basexsddecimal'gt
  • ltscale value'0'gt
  • lt/xsdsimpleTypegt
  • or multiplied in lists
  • ltxsdsimpleType name'IDREFS' base'xsdIDREF'
    derivedBy'xsdlist'/gt
  • Other built-in derived types
  • Name
  • int
  • long
  • short
  • byte
  • positiveInteger

5
Defining Simple Types
  • Enumeration
  • ltxsdsimpleType name'animal' base'xsdstring'gt
  • ltxsdenumeration value'dog'/gt
  • ltxsdenumeration value'cat'/gt
  • lt/xsdsimpleTypegt
  • Range restriction
  • ltxsdsimpleType name'employeeAge'
    base'xsdpositiveInteger'gt
  • ltxsdminInclusive value'18'/gt
    ltxsdmaxInclusive value'70'/gt
  • lt/xsdsimpleTypegt
  • Pattern
  • ltxsdsimpleType name'ssn' base'xsdstring'gt
  • ltxsdpattern value'\d3-\d2-\d4'gt
  • lt/xsdsimpleTypegt
  • List
  • ltxsdsimpleType name'animals' base'animal'
    derivedBy'xsdlist'/gt

6
Elements
  • Example
  • ltxsdelement name'employee'gt
  • ltxsdcomplexTypegt
  • ltxsdsequencegt
  • ltxsdelement name'name' type'xsdstring'/gt
  • ltxsdelement name'address' type'xsdstring'/gt
  • ltxsdelement name'ssn' type'ssn'/gt
  • lt/xsdsequencegt
  • lt/xsdcomplexTypegt
  • lt/xsdelementgt
  • It corresponds to the DTD
  • lt!ELEMENT employee (name,address,ssn)gt
  • lt!ELEMENT name (PCDATA)gt
  • lt!ELEMENT address (PCDATA)gt
  • lt!ELEMENT ssn (PCDATA)gt

7
Element Attributes
  • Element attributes can only appear inside
    xsdcomplexType in an xsdelement
  • ltxsdattribute name'ssn' type'ssn'
    use'required'/gt
  • ltxsdattribute name'father' type'xsdstring'
    use'optional'/gt
  • Keys can be defined using XPath expressions
  • ltxsdkey name'ssn'gt
  • ltxsdselectorgtdept/personlt/xsdselectorgt
  • ltxsdfieldgt_at_ssnlt/xsdfieldgt
  • lt/xsdkeygt
  • the selector defines the applicable elements
  • the field defines the data that are unique
    withing the applicable elements
  • xsdunique may be used to define unique
    combination of values
  • Foreign keys are like IDRefs, but well-typed
  • ltxsdkeyref refer'ssn'gt
  • ltxsdselectorgtdept/personlt/xsdselectorgt
  • ltxsdfieldgt_at_motherlt/xsdfieldgt
  • ltxsdkeyrefgt

8
Other Specifiers of xsdelement
  • Other attributes of xsdelement
  • minOccurs minimum number of occurrences
  • default '1'
  • maxOccurs maximum number of occurrences
  • default '1' if minOccurs is not given
  • default '' otherwise
  • optional is when minOccurs'0' and maxOccurs1'
  • nullable 'true'
  • ref 'type-name'
  • Other attributes of xsdcomplexType
  • content 'empty'
  • content 'mixed'
  • content 'elementOnly'
  • derivedBy 'extension'
  • derivedBy 'restriction'

9
xsdcomplexType
  • Any content
  • ltxsdanygt
  • Concatenation (A1, A2, ..., An)
  • ltxsdsequencegt A1 A2 ... An lt/xsdsequencegt
  • Alternation (A1 A2 ... An)
  • ltxsdchoicegt A1 A2 ... An lt/xsdchoicegt
  • All but in any order (A1 A2 ... An)
  • ltxsdallgt A1 A2 ... An lt/xsdallgt

10
Using xsdcomplexType
  • ltxsdsimpleType name'state' base'xsdstring'gt
  • ltxsdenumeration value'TX'gt
  • ltxsdenumeration value'CA'gt
  • lt/xsdsimpleTypegt
  • ltxsdsimpleType name'zip' base'xsdstring'gt
  • ltxsdpattern value'\d5'gt
  • lt/xsdsimpleTypegt
  • ltxsdcomplexType name'Address'
    content'elementOnly'gt
  • ltxsdsequencegt
  • ltxsdelement name'name' type'xsdstring'/gt
  • ltxsdelement name'street'
    type'xsdstring'/gt
  • ltxsdelement name'state' type'state'/gt
  • ltxsdelement name'zip' type'zip'/gt
  • lt/xsdsequencegt
  • lt/xsdcomplexTypegt
  • ltxsdelement name'PurchaseOrder'gt
  • ltxsdcomplexType content'elementOnly'gt
  • ltxsdsequencegt
  • ltxsdelement name'From' type'Address'/gt

11
Reusing Types
  • Extending types
  • ltxsdcomplexType name'GraduateStudent'
    base'Student' derivedBy'extension'gt
  • ltxsdelement name'gpa' type'xsdpositiveInt
    eger'/gt
  • lt/xsdcomplexTypegt
  • Restricting types
  • ltxsdsimpleType name"SKU"gt
  • ltxsdrestriction base"xsdstring"gt
  • ltxsdpattern value"\d3-A-Z2"/gt
  • lt/xsdrestrictiongt
  • lt/xsdsimpleTypegt

12
Using Schemas
  • Schema po.xsd
  • ltschema xmlns"http//www.w3.org/2001/XMLSchema"gt
  • ltelement name'PurchaseOrder'gt
  • ltcomplexType content'elementOnly'gt
  • ...
  • lt/complexTypegt
  • lt/elementgt
  • lt/schemagt
  • Using targetNamespace
  • ltschema xmlns"http//www.w3.org/2001/XMLSchema"
  • xmlnspo"http//lambda.uta.edu/PO"
  • targetNamespace"http//lambda.uta.edu/PO"
    gt
  • ltelement name'PurchaseOrder'gt
  • ltcomplexType content'elementOnly'gt
  • ...
  • lt/complexTypegt
  • lt/elementgt
  • lt/schemagt
  • XML data that conforms to this XML Schema
Write a Comment
User Comments (0)
About PowerShow.com