Presentation is loading. Please wait.

Presentation is loading. Please wait.

Dr. Azeddine Chikh IS446: Internet Software Development.

Similar presentations


Presentation on theme: "Dr. Azeddine Chikh IS446: Internet Software Development."— Presentation transcript:

1 Dr. Azeddine Chikh IS446: Internet Software Development

2 Part 4. Advanced XML

3 I. XML Schema

4 4 Objectives The purpose of an XML Schema is to define the legal building blocks of an XML document, just like a DTD. An XML Schema: defines elements that can appear in a document defines attributes that can appear in a document defines which elements are child elements defines the order of child elements defines the number of child elements defines whether an element is empty or can include text defines data types for elements and attributes defines default and fixed values for elements and attributes

5 Introduction 5 XML Schemas are the Successors of DTDs Very soon XML Schemas will be used in most Web applications as a replacement for DTDs. Here are some reasons : 1.XML Schemas are extensible to future additions 2.XML Schemas are richer and more powerful than DTDs 3.XML Schemas are written in XML 4.XML Schemas support data types 5.XML Schemas support namespaces XML Schema became a W3C Recommendation 02. May 2001.

6 6 History of XML Schema Langages Schemas and data are completely decoupled in XML Data can exist with or without schemas Or with multiple schemas Schema evolutions rarely impose evolving the data Schemas can be designed before the data, or extracted from the data

7 7 Correctness of XML documents Well formed documents Verify the basic XML constraints, e.g. Valid documents Verify the additional DTD structural constraints Non well formed XML documents cannot be processed Non-valid documents can still be processed (queried, transformed, etc)

8 8 Overview XML Schema ComplexTypes and SimpleTypes ComplexType correspond to Records "string” is an example of a SimpleType Built-in and user-defined Types ComplexTypes are always user-defined Elements have complexTypes or simpleTypes; Attributes have simpleTypes Type of Root element of a document is global Schemas are XML Documents (Syntax) Namespaces etc. are part of XML Schemas

9 9 Example Schema "http://www.w3.org/2001/XMLSchema"

10 10 Example Schema "http://www.w3.org/2001/XMLSchema"... Schema in a separate XML Document Vocabulary of Schema defined in special Namespace. Prefix "xsd" is commonly used There is a Schema for Schemas ” Schema” Element is always the Root

11 11 Example Schema ”element” element in order to declare elements ”name” attribute defines the name of the element. ”type” defines the type of the element Declarations under ”schema” are global Global element declarations are potential roots Example: "book" is the only global element, root element of a valid document must be a "book". The type of a "book" is BookType (defined next).

12 12 Example Schema... User-defined complextype Defines a sequence of sub-elements Attribute "name" specifies name of Type This Type definition is global. Type can be used in any other definition.

13 13 Example Schema Local element declaration within a complex type (” title” cannot be root element of documents) ” name” and ” type” as before ” xsd:string” is built-in type of XML Schema

14 14 Example Schema Local element declaration ” PersonType” is user-defined type ” minOccurs", ” maxOccurs” specify cardinality of "author” Elements in ” BookType". Default: minOccurs=1, maxOccurs=1

15 15 Example Schema he same syntax as for BookType.

16 16 Example Schema Local element declaration Every book has exactly one ” publisher” minOccurs, maxOccurs by default 1 ” anyType” is built-in Type ” anyType” allows any content ” anyType” is default type. Equivalent definition:

17 17 Example Schema "http://www.w3.org/2001/XMLSchema"

18 18 Valid Document Die Wilde Wutz D. K. Addison Wesley, CA, USA

19 19 Valid Document Die Wilde Wutz D. K. Addison Wesley, CA, USA Root is book

20 20 Valid Document Die Wilde Wutz D. K. Addison Wesley, CA, USA Exactly one title of Type string

21 21 Valid Document Die Wilde Wutz D. K. Addison Wesley, CA, USA At least one author of Type PersonType One publisher with arbitrary content. Subelements In right order

22 22 Global vs. Local Declarations Instances of global element declarations are potential root elements of documents Global declarations can be referenced...... Constraints ” ref” not allowed in global declarations No ” minOccurs", ” maxOccurs” in global Decl.

23 23 Attribute Declarations Attributes may only have a SimpleType SimpleTypes are, e.g., ” string” (more later) Attribute declarations can be global Reuse declarations with ref Compatible to Attribute lists in DTDs Default values possible Required and optional attributes Fixed attributes (In addition, there are ” prohibited” attributes)

24 24 Attribute Declarations... <xsd:attribute name= ” isbn” type= ” xsd:string” use= ” required” /> <xsd:attribute name= ” price” type= ” xsd:decimal" use= ” optional” /> <xsd:attribute name= ” curr” type= ” xsd:string" fixed= ” EUR” /> <xsd:attribute name= ” index” type= ” xsd:IDREFS" default= "” />

25 25 Anonymous Types PersonType needs not be ” named"......

26 26 Simple Elements + Attributes Valid Instance: 69.95

27 27 Element + Attributes, no Content Valid Instance:

28 28 Pre-defined SimpleTypes Numeric Values Integer, Short, Decimal, Float, Double, HexBinary,... Date, Timestamps, Periods Duration, DateTime, Time, Date, gMonth,... Strings String, NMTOKEN, NMTOKENS, NormalizedString Others AnyURI, ID, IDREFS, Language, Entity,...

29 29 Derived SimpleTypes Restrict domain minInclusive, maxInclusive are "Facets"

30 30 Derived SimpleTypes Restriction by Pattern Matching Currencies have three capital letters

31 31 Derived SimpleTypes Restriction by Enumeration

32 32 Derived SimpleTypes There are 15 different kinds of Facets e.g., minExclusive, totalDigits,... Most built-in types are derived from other built-in types by restriction e.g., Integer is derived from Decimal there are only 19 base types (out of 44)

33 33 List Types SimpleType for Lists Built-in List Types: IDREFS, NMTOKENS User-defined List Types Items in instances are separed by whitespace "5 -10 7 -20" Facets for Restrictions: length, minLength, maxLength, enumeration

34 34 Facets of List Types

35 35 Union Types Corresponds to the "|" in DTDs (Variant Records in Pascal or Union in C) Valid instances are valid to any of the types Valid Instances " bus" "1 3 17" "vehicle" "15" Supported Facets pattern, enumeration

36 36 Choice: "Union” in ComplexTypes A book has either an "author" or an "editor" <xsd:element name = "author" type = "Person" maxOccurs = "unbounded" />

37 37 Derived Complex Types Two concepts of subtyping / inheritance Subtyping via Extension Add Element Similar to inheritance in OO Subtyping via Restriction e.g., constrain domains of types used Further "features„ Abstracte Types

38 38 Subtyping via Extension A "book" is a "publication"

39 39 Subtyping via Extension A "bib” contains "Publications” <xsd:element name = "pub" type = "Publication" maxOccurs = "unbounded"/> "pub " Elements may be books! Instances have "xsi:type” Attribute Wilde Wutz 1984 D.A.K.

40 40 Subtyping via Restriction The following restrictions are allowed Instances of subtypes have default values Instances of subtypes are fixed (i.e., constant) Instances of subtypes have stronger types (e.g., string vs. anyType) Instances of subtypes have mandatory fields which are optional in supertype Supertype.minOccurs = Subtype.maxOccurs

41 41 Subtyping via Restriction

42 42 Abstract Elements and Types No instances exist Only instances of subtypes exist person in Book must be an author or editor......


Download ppt "Dr. Azeddine Chikh IS446: Internet Software Development."

Similar presentations


Ads by Google