Lesson 4 - XML Schem

advertisement

XML - Level I Basic

Unit 4 – XML Schema

www.profburnett.com

Unit 4 - Schema

Unit objectives

 Identify the limitations of DTDs

 Describe schema and its components

 Create and modify schema

Copyright © Carl M. Burnett

7/14/2013 2

Topic A

 Topic A: XML Schema

 Topic B: Schema description and components

 Topic C: Creating a schema

7/14/2013

Copyright © Carl M. Burnett

3

XML Schema

 Document type definitions (DTDs) provide a mechanism for modeling XML languages

 Developed to overcome the limitations of DTDs

7/14/2013

Copyright © Carl M. Burnett

4

Disadvantages of DTDs

 Special syntax

 Can not be processed by a standard XML processor

 Limited ability to describe the data in elements and attributes

 Limited support for namespaces

 New names required for similar elements in different contexts of the same document

Copyright © Carl M. Burnett

7/14/2013 5

XML Schema recommendations

Schema

 An application of XML

 Defines a model for describing the structure and content of data

 Referred to as XML Schema or XSchema

 Facilitates development of better data descriptions and definitions of shared markup vocabularies

Copyright © Carl M. Burnett

7/14/2013 6

Topic B

 Topic A: XML Schema

 Topic B: Schema description and components

 Topic C: Creating a schema

7/14/2013

Copyright © Carl M. Burnett

7

Schema model

 Constraint defines what can appear in a given language or document

 Content model constraint

 Defines the elements that can appear

 Datatype constraint

 Describes the units of data that the schema considers valid

 Class of documents - individual schemas

 Instance documents - XML documents that conform to a particular schema

Copyright © Carl M. Burnett

7/14/2013 8

Schema components

 The prolog

 First 3 lines of the schema

 First line is the XML declaration (<?xml..?>) - mandatory

 Next 2 lines are comment lines (<!-….-- >)

7/14/2013

Copyright © Carl M. Burnett

9

Schema element

 Namespace in schema

 <xs:schema ..> schema element

 Conforms to W3C Schema recommendation

 Namespace declaration

 xmlns:xs=http://www.w3.org/2001/XMLSchema

 “xmlns” - namespace declaration

 “xs” - abbreviation to relate the respective elements or datatypes to the namespace

 http://www.w3.org/2001/XMLSchema - the unique Uniform

Resource Identifier (URI) continued

10 7/14/2013

Copyright © Carl M. Burnett

Schema element, continued

 Qualified and unqualified locals

 Local elements are declared in subelements of the schema element, but not in the scope of schema

 Global declared elements are declared in the

<schema> element

 Prefixed element names are qualified names

 Element names without prefixes are unqualified names

Copyright © Carl M. Burnett

7/14/2013 11

XML schema document validation

7/14/2013

Copyright © Carl M. Burnett

12

Qualified locals

7/14/2013

Copyright © Carl M. Burnett

13

Unqualified locals

7/14/2013

Copyright © Carl M. Burnett

14

Element types and compositors

 Complex type

 Determines appearance and content in XML-related instance documents

 Contains attributes and/or subelements

 Simple type

 Contains no attributes or subelements, just character data

 Compositors

 Define groups of element and attributes

 Might be nested inside of one another

Copyright © Carl M. Burnett

7/14/2013 15

Types of compositors

 Sequence compositor

 Elements must appear in the same order as indicated in the schema

 Choice compositor

 Allows only one element to appear in the XML document at that point

 All compositor

 Allows any of the elements to appear in any order

Copyright © Carl M. Burnett

7/14/2013 16

Attributes and cardinality

 The number of times an element may occur in instance document

 Denoted by a plus sign (+) that indicates it must occur at least once

 No limit to the number of times it might occur

 XML Spy substituted attributes:

 minOccur and maxOccur (minimum and maximum number of occurrences)

Copyright © Carl M. Burnett

7/14/2013 17

Subelements

 Simple types of elements

 Defined in the W3C Schema Recommendation (XML

Schema)

 Use prefix xs:

 Defined by the schema designer according to specific needs

 Russian Doll or nesting approach - A full element declaration is inserted every time the element is needed

 Flat catalog approach – employs global references

Copyright © Carl M. Burnett

7/14/2013 18

Simple types

7/14/2013

Copyright © Carl M. Burnett

19

Other schema facets

7/14/2013

Copyright © Carl M. Burnett

20

Topic C

 Topic A: XML Schema

 Topic B: Schema description and components

 Topic C: Creating a schema

7/14/2013

Copyright © Carl M. Burnett

21

Creating schemas

 You can use XML Spy to create schemas

 You can use XML Spy to convert an existing

DTD to a schema

7/14/2013

Copyright © Carl M. Burnett

22

Student Exercises

 Topic C – Creating a Schema

 C-1: Converting a DTD to Schema

 C-2: Creating XML Schema from scratch

 C-3: Adding Global Components in a Schema

Copyright © Carl M. Burnett

7/14/2013 23

Unit summary

 Identify the limitations of DTDs

 Described schema and its components

 Learned how to create and modify schema

7/14/2013

Copyright © Carl M. Burnett

24

Download