Presentation is loading. Please wait.

Presentation is loading. Please wait.

Deriving Complex Types In XML Schema By: Roy Navon.

Similar presentations


Presentation on theme: "Deriving Complex Types In XML Schema By: Roy Navon."— Presentation transcript:

1 Deriving Complex Types In XML Schema By: Roy Navon

2 What will we talk about? Remember complex types Motivation Complex type extensions Complex type restrictions Type substitution Controlling type derivation and substitution And many many examples…

3 Simple Content Just like simple types with attributes Schema: XML: 10

4 Element-only content Contains only other elements: Schema: XML: 557 Ruler 10

5 Mixed Content Can contain both character data and child elements. Schema: XML: Dear Roy Navon, On the date of 2003-30-10 you have ordered…

6 Empty Content Allows neither character data nor child elements Schema: XML:

7 Why derive types? Subsetting Safe extensions Type substitution Reuse Future use

8 Complex Types Extensions BASE TYPE Complex typeSimple type EmptyMixedElement- only Simple content No Simple type Derived type No Yes Simple content Complex type YesNoYesNo Element- only Yes No Mixed YesNo Empty

9 Simple content extension Used only to add attributes. Either from a simple type or from another complex type. Schema: XML: 10 Could have been a complex type here with simple content

10 Complex Content Extension Add attributes, and add elements to the end of the content model Can be looked at as if the base type content model and the new content model were together in a sequence group.

11 Complex Content Extension Original type:

12 Complex Content Extension Derived type:

13 Complex Content Extension The derived type can be looked at as:

14 Extending Choice Groups Let’s say we want to extend the choice group to also include a sweater and a suit

15 Extending Choice Groups Can we write something like: NO!!! ?

16 Mixed Content Extensions Don ’ t forget!

17 Empty Content Extensions Original Type: Derived Type:

18 Complex Type Restrictions The main thing to remember about type restrictions is that if A derived from B, then A is a subset of B, and therefore a legal instance of A, must also be a legal instance of B.

19 Complex Type Restrictions BASE TYPE Complex typeSimple type EmptyMixedElement- only Simple content No YesSimple type Derived type NoYes*NoYesNoSimple content Complex type NoYes No Element- only NoYesNo Mixed YesYes* No Empty * If all children are optional

20 Simple type restrictions Simple type Simple type (using facets)

21 Simple content restriction <xsd:attribute name="system" type="xsd:token" use="required"/> The size is now between 2 and 6 The attribute is now required

22 Complex content restrictions Base type:

23 Complex content restrictions Derived type:

24 Eliminating meanigless groups Groups with no children. Groups that have minOccurs and maxOccurs equal to 1, and only have one child. Sequence groups that have minOccurs and maxOccurs equal to 1 and are contained in another sequence group (see example).

25 Eliminating meanigless groups Base group: Legal restriction:

26 Restricting Element Declarations The occurrence constraint in the derived element declaration must be equal or more restrictive. Base group: Legal restriction: Illegal restriction:

27 Restricting Element Declarations If the base element declaration specified a fixed value, the derived element declaration must specify the same fixed value. Base group: Legal restriction: Illegal restriction:

28 Restricting Element Declarations The data type in the derived element declaration must be a restriction of the data type (or the same data type) in the base element declaration. Base group: Legal restriction: Illegal restriction:

29 Restricting groups As long as it is a valid instance, you can replace a group with an element declaration. Base group: Legal restriction:

30 Restricting groups When restricting an all, choice or sequence group, the order of the children must be preserved. Base group: Legal restriction: Illegal!

31 Restricting choice groups When replacing a choice group with another choice group, the child element declarations of the derived group must be a subset of those in the base group. Base group: Legal restriction: d Illegal!

32 Replacing a choice group with a sequence group Base group: Legal restriction: Illegal restriction:

33 Mixed Content Restriction Derived type:

34 Mixed content restricted to simple content Derived type: Remember, all children must be optional

35 Empty Content Restrictions Base type: Derived type: An empty content type can only be restricted to an empty content type

36 Attribute Restrictions What ’ s legal: Change the attribute type, as long as the new type is a restriction of the original type. Add, change or remove a default value. Add a fixed value if none is present in the base type Make optional attributes required Make optional attributes prohibited.

37 Attribute Restrictions What ’ s Illegal: Change the attribute ’ s type to one that is not a restriction of the original type. Change or remove a fixed value. Make required attributes optional. Make required attributes prohibited.

38 Type Substitution This allows us to use a derived type in an instance where the base type is expected

39 Type Substitution 557 Short-Sleeved Linen Blouse

40 Controlling type derivation and substitution In some cases, we may want to control the creation or substitution of derived types. We have 3 properties for this: final block abstract

41 final: Preventing complex type derivation The final attribute may have one of the following values: “#all” prevents any other types from extending or restricting your type. “extension” prevents any other type from extending your type. “restriction” prevents any other type from restricting your type. “” (an empty string) means that there are no restrictions. Used mainly to override the value of finalDefault.

42 final: example ProductType cannot be restricted or extended by any other type.

43 block: Blocking substitution of derived types If we want to allow only the original types to be used in the instances, we can use the block attribute.. The allowed values are the same for the final attribute.

44 abstract: Forcing derivation Abstract complex types are types that cannot be used in instances. They exist solely as placeholders for their derived types.

45 abstract: an example

46 abstract: an example Legal instances: 557 Short-Sleeved Linen Blouse 557 Short-Sleeved Linen Blouse Illegal instance: 557 Short-Sleeved Linen Blouse

47 What will we talk about? Remember complex types Motivation Complex type extensions Complex type restrictions Type substitution Controlling type derivation and substitution And many many examples… did

48 Questions?


Download ppt "Deriving Complex Types In XML Schema By: Roy Navon."

Similar presentations


Ads by Google