Download presentation
Presentation is loading. Please wait.
Published bySharlene McCormick Modified over 9 years ago
1
Unit 4 – XML Schema www.profburnett.com XML - Level I Basic
2
Unit objectives Identify the limitations of DTDs Describe schema and its components Create and modify schema Unit 4 - Schema 7/14/2013 Copyright © Carl M. Burnett 2
3
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
4
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
5
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 7/14/2013 Copyright © Carl M. Burnett 5
6
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 7/14/2013 Copyright © Carl M. Burnett 6
7
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
8
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 7/14/2013 Copyright © Carl M. Burnett 8
9
Schema components The prolog First 3 lines of the schema First line is the XML declaration ( ) - mandatory Next 2 lines are comment lines ( ) 7/14/2013 Copyright © Carl M. Burnett 9
10
Schema element Namespace in 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 7/14/2013 Copyright © Carl M. Burnett 10
11
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 element Prefixed element names are qualified names Element names without prefixes are unqualified names 7/14/2013 Copyright © Carl M. Burnett 11
12
XML schema document validation 7/14/2013 Copyright © Carl M. Burnett 12
13
Qualified locals 7/14/2013 Copyright © Carl M. Burnett 13
14
Unqualified locals 7/14/2013 Copyright © Carl M. Burnett 14
15
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 7/14/2013 Copyright © Carl M. Burnett 15
16
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 7/14/2013 Copyright © Carl M. Burnett 16
17
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) 7/14/2013 Copyright © Carl M. Burnett 17
18
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 7/14/2013 Copyright © Carl M. Burnett 18
19
Simple types 7/14/2013 Copyright © Carl M. Burnett 19
20
Other schema facets 7/14/2013 Copyright © Carl M. Burnett 20
21
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
22
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
23
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 7/14/2013 23 Copyright © Carl M. Burnett
24
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
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.