Presentation is loading. Please wait.

Presentation is loading. Please wait.

Introduction to XML Schema Winter 2003. Sources XML Schema Part 1: Structures W3C Recommendation 2 May 2001,

Similar presentations


Presentation on theme: "Introduction to XML Schema Winter 2003. Sources XML Schema Part 1: Structures W3C Recommendation 2 May 2001,"— Presentation transcript:

1 Introduction to XML Schema Winter 2003

2 Sources XML Schema Part 1: Structures W3C Recommendation 2 May 2001, http://www.w3.org/TR/xmlschema-1/ http://www.w3.org/TR/xmlschema-1/ XML Schema Part 0 Primer Definitive XML Schema (Priscilla Walmsley) Database and Transaction Processing – An application-oriented Approach (Lewis, Bernstein and Kifer)

3 XML Schema Decouple element types and their names Many simple types (xsd:int etc.) Namespace awareness Derived types by extension and restriction Integrity constraints: key, keyref “ Deterministic ”

4 XML Schema Example File Alice Smith 123 Maple Street Mill Valley CA 90952 Robert Smith 8 Oak Avenue Old Town PA 95819

5 XML Schema Example File (Cont.) Hurry, my lawn is going wild! Lawnmower 1 148.95 Confirm this is electric Baby Monitor 1 39.98 1999-05-21

6 XML Schema for Example File Purchase order schema for Example.com. Copyright 2000 Example.com. All rights reserved.

7 XML Schema for Example File <xsd:attribute name="country" type="xsd:NMTOKEN" fixed="US"/>

8 XML Schema for Example File

9 XML Schema for Example File

10 Definitions and Declarations Complex types allow elements and attributes. Simple types cannot have element content and cannot have attributes. Definitions create new types (both simple and complex). Declarations enable elements and attributes with specific names and types (both simple and complex) to appear in document instances.

11 Defining the USAddress Type Robert Smith 8 Oak Avenue Old Town PA 95819

12 Defining PurchaseOrderType Observe: Attributes can only contain simple types.

13 Defining PurchaseOrderType In writing Comment must have been globally defined (not within element or type declaration).

14 Restricting Occurrences of Elements and Attributes minOccurs, maxOccurs limit the number of occurrences Default is 1. Attributes can appear at most once. use: required (e.g., partNum), optional, or prohibited. default attribute: for attributes, supply value if missing in instance (attribute must be optional) default element: values supplied only when instance elements ARE EMPTY (not when MISSING).

15 Restricting Occurrences of Elements and Attributes: Fixed fixed: ensure that the attributes and elements are set to particular values (e.g., country is declared with a fixed value US). Value appears: must be the fixed value. Value does not appear: the fixed value is supplied. default and fixed cannot be concurrently used.

16 MeaningAttributes use, fixed, default usefixeddefault Elements (minOccurs, maxOccurs) fixed, default minOccurs maxOccursfixed default element/attribute must appear once, it may have any value required, -, -(1, 1) -, - element/attribute must appear once, its value must be 37 required, 37, -(1, 1) 37, - element must appear twice or more, its value must be 37 N/a (2, unbounded) 37, - element/attribute may appear once, it may have any value optional, -, -(0, 1) -, - element/attribute may appear once, if it does appear its value must be 37, if it does not appear its value is 37 optional, 37, -(0, 1) 37, element/attribute may appear once; if it does not appear its value is 37, otherwise its value is that given optional, -, 37(0, 1) -, 37 element/attribute must not appearprohibited, -, -(0, 0) -, -

17 Restrictions on Global Elements Appear at top level of the document Cannot use ref Cannot use minOccurs, maxOccurs Cannot mention use

18 Restricting Simple Types Use facets for restricting instances. Many facets: length, minLength, maxLength, pattern, enumeration, whiteSpace …

19 Restricting Simple Types with a pattern " \d{3}-[A-Z]{2} " that is read "three digits followed by a hyphen followed by two upper-case ASCII letters".

20 Restricting Simple Types with an enumeration Restrict a simple type by enumerating possibilities. < xsd:enumeration value="AR"/>

21 Simple Types = Atomic Types, List Types, Union Types List types are comprised of sequences of atomic types. Three built-in list types: NMTOKENS, IDREFS, and ENTITIES. Can create new list types by derivation from existing atomic types. Cannot create list types from existing list types, nor from complex types.

22 List Types Type definition:: Element with a conforming content: 20003 15037 95977 95945

23 List with Facets: List Type for Six US States Conforming element: PA NY CA NY LA AK

24 Union types: Union Type for Zip codes <xsd:union memberTypes= "USState listOfMyIntType"/> Conforming elements of type zipUnion: – CA</zips – 95630 95977 95945 – AK

25 Anonymous Type Definitions

26 Conforming element: Elements with a simple content and attributes No elements

27 Dear Mr. Robert Smith. Your order of 1 Baby Monitor shipped from our warehouse on 1999-05- 21..... Mixed Content Example

28 Mixed Content Schema

29 Conforming element: Empty Content

30 Nested Choice and Sequence Groups (single or 2 addresses)

31 Top-level. Group's children must all be individual elements (no groups). Element in the content model may appear more than once, i.e. the permissible values of minOccurs and maxOccurs are 0 and 1. ALL GROUPS

32 Defining Attribute Groups

33 Using Attribute Groups

34 An element with xsi:nil="true" may not have any element content but it may still have attributes. Useful for representing missing information. NIL Values

35 Target Namespaces and Naming A target namespace identifies a collection (vocabulary) of type definitions and element declarations. Essentially a logical container. The author can decide whether or not the appearance of locally declared elements and attributes in an instance must be qualified by a namespace, using either an explicit prefix or implicitly by default.

36 Target Namespaces and Naming: The Big Picture Schema Level: The XML Schema namespace (xs, xsd) Possibly a target namespace Possibly a default xmlns namespace (probably target) Possibly other prefixes+namespaces Decide on instance qualifications Instance Level: Possibly the XSI namespace Possibly a default xmlns namespace (probably a target namespace) Probably some other namespace prefixes Implement prescribed qualifications.

37 PO Revisited <schema xmlns="http://www.w3.org/2001/XMLSchema" xmlns:po="http://www.example.com/PO1" targetNamespace="http://www.example.com/PO1" elementFormDefault="unqualified" attributeFormDefault="unqualified"> Refer to local instance elements/attrib utes

38 Conforming Instance <apo:purchaseOrder xmlns:apo="http://www.example.com/PO1" orderDate="1999-10-20"> Alice Smith 123 Maple Street Robert Smith 8 Oak Avenue Hurry, my lawn is going wild! elementFormDefault and attributeFormDefault require that the prefix is not applied to any of the locally declared elements such as shipTo.

39 Summary A sophisticated schema language. Namespaces play a major role. OO features (abstract classes). Deterministic characteristics.

40 Example Schema <xsd:schema targetNamespace="http://www.oded1.com" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://www.oded1.com">

41 Example

42 Instance <s:salesdata xmlns:s="http://www.oded1.com" xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance xsi:schemaLocation="http://www.oded1.com C:\salesdata.xsd" > 1996 central 34 east 34 west 12


Download ppt "Introduction to XML Schema Winter 2003. Sources XML Schema Part 1: Structures W3C Recommendation 2 May 2001,"

Similar presentations


Ads by Google