1 Substitution Groups in XML Schemas Tomer Shiran Winter 2003/4 Semester.

Slides:



Advertisements
Similar presentations
XML Schema Heewon Lee. Contents 1. Introduction 2. Concepts 3. Example 4. Conclusion.
Advertisements

1 Web Data Management XML Schema. 2 In this lecture XML Schemas Elements v. Types Regular expressions Expressive power Resources W3C Draft:
An Introduction to XML Based on the W3C XML Recommendations.
XML Schema techniques: issues and recommendations SAML F2F #4 Eve Maler 28 August 2001.
Copyright © Open Applications Group, Inc. All rights reserved 1 OAGi XML Schema User Report June 21, Michael.
1 XML DTD & XML Schema Monica Farrow G30
Chapter 8 Inheritance Part 2. © 2004 Pearson Addison-Wesley. All rights reserved8-2 Outline Creating Subclasses Overriding Methods Class Hierarchies Inheritance.
Achieving Distributed Extensibility and Versioning in XML Dave Orchard W3C Lead BEA Systems.
XHTML1 Building Document Structure. XHTML2 Objectives In this chapter, you will: Learn how to create Extensible Hypertext Markup Language (XHTML) documents.
Document Type Definitions
Introduction to XLink Transparency No. 1 XML Information Set W3C Recommendation 24 October 2001 (1stEdition) 4 February 2004 (2ndEdition) Cheng-Chia Chen.
XML Schemas and Namespaces Lecture 11, 07/10/02. BookStore.dtd.
Sunday, June 28, 2015 Abdelali ZAHI : FALL 2003 : XML Schemas XML Schemas Presented By : Abdelali ZAHI Instructor : Dr H.Haddouti.
Tutorial 11 Creating XML Document
Document Type Definitions. XML and DTDs A DTD (Document Type Definition) describes the structure of one or more XML documents. Specifically, a DTD describes:
Health Level Seven Experience Report Paul V. Biron Kaiser Permanente W3C XML Schema User Experience Workshop, Jun 21-22, 2005.
17 Apr 2002 XML Schema Andy Clark. What is it? A grammar definition language – Like DTDs but better Uses XML syntax – Defined by W3C Primary features.
XP New Perspectives on XML Tutorial 4 1 XML Schema Tutorial – Carey ISBN Working with Namespaces and Schemas.
XP New Perspectives on XML Tutorial 3 1 DTD Tutorial – Carey ISBN
VICTORIA UNIVERSITY OF WELLINGTON Te Whare Wananga o te Upoko o te Ika a Maui SWEN 432 Advanced Database Design and Implementation XML Schema 1 Lecturer.
XML Schema Vinod Kumar Kayartaya. What is XML Schema?  XML Schema is an XML based alternative to DTD  An XML schema describes the structure of an XML.
Creating Extensible Content Models XML Schemas: Best Practices A set of guidelines for designing XML Schemas Created by discussions on xml-dev.
1 XML Schemas. 2 Useful Links Schema tutorial links:
Dr. Azeddine Chikh IS446: Internet Software Development.
Neminath Simmachandran
McGraw-Hill/Irwin © 2004 by The McGraw-Hill Companies, Inc. All rights reserved. Schemas Ellen Pearlman Eileen Mullin Programming the Web Using XML.
XML CPSC 315 – Programming Studio Fall 2008 Project 3, Lecture 1.
XP 1 CREATING AN XML DOCUMENT. XP 2 INTRODUCING XML XML stands for Extensible Markup Language. A markup language specifies the structure and content of.
1 © Netskills Quality Internet Training, University of Newcastle Introducing XML © Netskills, Quality Internet Training University.
XP 1 DECLARING A DTD A DTD can be used to: –Ensure all required elements are present in the document –Prevent undefined elements from being used –Enforce.
XML A web enabled data description language 4/22/2001 By Mark Lawson & Edward Ryan L’Herault.
Of 33 lecture 3: xml and xml schema. of 33 XML, RDF, RDF Schema overview XML – simple introduction and XML Schema RDF – basics, language RDF Schema –
Beginning XML 4th Edition. Chapter 5: XML Schemas.
New Perspectives on XML, 2nd Edition
XML Schema. Why Schema? To define a class of XML documents Serve same purpose as DTD “Instance document" used for XML document conforming to schema.
XSDL & Relax : 2 new schema languages for XML Rajasekar Krishnamurthy.
An OO schema language for XML SOX W3C Note 30 July 1999.
XML – Part III. The Element … This type of element either has the element content or the mixed content (child element and data) The attributes of the.
1 CIS336 Website design, implementation and management (also Semester 2 of CIS219, CIS221 and IT226) Lecture 5 XML Schema (Based on Møller and Schwartzbach,
Sheet 1XML Technology in E-Commerce 2001Lecture 2 XML Technology in E-Commerce Lecture 2 Logical and Physical Structure, Validity, DTD, XML Schema.
XML 2nd EDITION Tutorial 4 Working With Schemas. XP Schemas A schema is an XML document that defines the content and structure of one or more XML documents.
1 Tutorial 14 Validating Documents with Schemas Exploring the XML Schema Vocabulary.
Tutorial 13 Validating Documents with Schemas
Object Oriented Software Development
Introduction to c++ programming - object oriented programming concepts - Structured Vs OOP. Classes and objects - class definition - Objects - class scope.
Processing of structured documents Spring 2003, Part 3 Helena Ahonen-Myka.
SNU OOPSLA Lab. Logical structure © copyright 2001 SNU OOPSLA Lab.
Internet & World Wide Web How to Program, 5/e. © by Pearson Education, Inc. All Rights Reserved.2.
Working with XML Schemas ©NIITeXtensible Markup Language/Lesson 3/Slide 1 of 36 Objectives In this lesson, you will learn to: * Declare attributes in an.
Introduction to XML Schema John Arnett, MSc Standards Modeller Information and Statistics Division NHSScotland Tel: (x2073)
David Orchard W3C Lead BEA Systems Web service and XML Extensibility and Versioning.
Interfaces About Interfaces Interfaces and abstract classes provide more structured way to separate interface from implementation
XSD: XML Schema Language Kanda Runapongsa Dept. of Computer Engineering Khon Kaen University.
XML Schema Definition (XSD). Definition of a Schema It is a model for describing the structure and content of data The XML Schema was developed as a content.
Deriving Complex Types In XML Schema By: Roy Navon.
Experience with XML Schema Ashok Malhotra Schema Usage  Mapping XML Schema and XML documents controlled by the Schema to object classes and instances.
Using XML Schema to define NETCONF Content Sharon Chisholm Alex Clemm TJ Tjong
CIS 228 The Internet 9/20/11 XHTML 1.0. “Quirks” Mode Today, all browsers support standards Compliant pages are displayed similarly There are multiple.
CITA 330 Section 4 XML Schema. XML Schema (XSD) An alternative industry standard for defining XML dialects More expressive than DTD Using XML syntax Promoting.
XML SCHEMA 1 CH 20. Objective 2 What’s wrong with DTDs? What is a schema? The W3C XML Schema Language Hello schemas Complex types Simple types Deriving.
4 Copyright © 2004, Oracle. All rights reserved. Validating XML by Using XML Schema.
XML Schemas Dr. Awad Khalil Computer Science Department AUC.
XML QUESTIONS AND ANSWERS
Eugenia Fernandez IUPUI
Data Modeling II XML Schema & JAXB Marc Dumontier May 4, 2004
Lecture 14 - Abstract Classes
Namespace Review 21-Nov-18.
Namespace Review 29-Dec-18.
Namespace Review 14-Oct-19.
New Perspectives on XML
Presentation transcript:

1 Substitution Groups in XML Schemas Tomer Shiran Winter 2003/4 Semester

2 What’s included? Why substitution groups? Substitutions in an XML instance Declaring a substitution group The substitution group hierarchy Type constraints for substitution groups Controlling substitution groups Alternatives to substitution groups

3 Why substitution groups? example1.xml 111 Ten-Gallon Hat Short-Sleeved Linen Blouse 40 Red … 444 Special Seasonal

4 Why Substitution Groups? (Cont.) The previous design has various problems: We want to allow different content models for different kinds of products: Shirts have a mandatory size and an optional color Hats have a mandatory size Umbrellas have a mandatory radius We want to use descriptive element names that indicate the type of product (e.g., shirt and hat instead of product ). We want to accept new kinds of products without altering the original schema. Substitution groups address these issues…

5 Substitutions in an XML instance example2.xml <items xmlns:xsi= xsi:noNamespaceSchemaLocation="example2.xsd"> 111 Ten-Gallon Hat Short-Sleeved Linen Blouse 40 Red … 444 Special Seasonal Whenever the head element is referenced in a content model, one of the member elements may be substituted in place of the head.

6 Declaring a substitution group example2.xsd Any global element can be the head of a substitution group.

7 Declaring a substitution group (Cont.) example2.xsd (Cont.)

8 Declaring a substitution group (Cont.) example2.xsd (Cont.)

9 The substitution group hierarchy Each substitution group has one head element and one or more members. If the head element is in a different namespace (i.e., the schema document in which it is declared has a target namespace), a prefix must be used in the substitutionGroup attribute (e.g., ord:product ). Each element declaration can only be a direct member of one substitution group – membership is transitive, but not symmetric. An element declaration can be a member of a substitution group and the head of a different substitution group.

10 The substitution group hierarchy (Cont.) hat, shirt, blouse, tShirt, and umbrella can substitute for product. blouse and tShirt can substitute for shirt.

11 Type constraints for substitution groups Members of a substitution group must have types that are: The same as the type of the head, or Derived from the head by either extension or restriction (directly or indirectly, through multiple levels of restriction or extension) XMLSPY 2004 doesn’t enforce this rule. If an element declaration doesn’t specify a type attribute or a simpleType or complexType child, the type definition of the declaration is the same type as the element specified by the substitutionGroup attribute (the head of the group).

12 Controlling substitution groups The final attribute limits the declaration of substitution groups in schemas. The block attribute limits the use of substituted elements in instances. The abstract attribute forces element substitution in instances.

13 The final attribute Preventing substitution group declarations ValueDescription "#all" "extension restriction" "restriction extension" Cannot be used as the head of a substitution group "extension" Prevents extension in substitution group members "restriction" Prevents restriction in substitution group members "" (an empty string) There are no restrictions (overrides the finalDefault attribute) No final attribute The final attribute defaults to the value of finalDefault of the schema element (if it exists – otherwise there are no restrictions)

14 The block attribute Blocking substitution in instances With this declaration of product, the schema in example2.xsd would have been legal, but the instance in example2.xml would have been illegal.

15 final vs. block Terminology: final specifies “substitution group exclusions”, which is a static constraint – it affects the element derivation hierarchy block specifies “disallowed substitutions”, which is a runtime constraint – it affects the instance structure substitutionGroup specifies “substitution group affiliation” There are 32 different ways to set the constraints: 2 2 for final ( extension and restriction ) 2 3 for block ( substitution, extension, and restriction )

16 final vs. block (Cont.) An example A type hierarchy: Element declarations: What substitutions can be made in the instance? middle instead of top ? bottom instead of middle ? bottom instead of top ? This is valid because there is no static constraint in middle. Yes No Yes

17 The abstract attribute Forcing substitution An abstract element declaration can never apply to an instance element. It can serve as the head of a substitution group (like an abstract class in Java/C#). In XMLSPY 2004 (but not in the standard or in other implementations), members of a substitution group with an abstract head must explicitly specify a type. … … 444 Special Seasonal

18 The abstract attribute (Cont.) example3.xsd Specifies that local elements (e.g., number ) also belong to the target namespace (avoids prefixes in the instance).

19 The abstract attribute (Cont.) example3.xsd (Cont.) …

20 The abstract attribute (Cont.) example3ext.xsd …

21 The abstract attribute (Cont.) example3.xml 111 Ten-Gallon Hat 27 … 444 Super Sweater 38 Blue 555 Million-Dollar Suit Notice the whitespace! Won’t work in XMLSPY 2004 (because the suit element declaration doesn’t explicitly specify a type in the schema)!

22 Alternatives to substitution groups Reusable choice groups Substituting a derived type in the instance

23 Reusable choice groups example4.xsd... …

24 Reusable choice groups (Cont.) Pros: Easy to see the list of members of the “substitution group” Cons: Cumbersome to add new element declarations to the “substitution group” (a redefinition is needed, and it can only be done in schema documents with the same target namespace)

25 Derived type substitution in the instance Instead of declaring shirt, hat, and umbrella, we just declare their data types and specify all products as product elements. The derived types are substituted in the instance by specifying the xsi:type attribute. The block attribute of complexType or element can be specified in the schema in order to block substitution of derived types. If the block attribute is used in an element declaration (an element element), and its value is " #all " or " substitution ", then the element cannot be substituted in the instance.

26 Derived type substitution (Cont.) example5.xsd … … … …

27 Derived type substitution (Cont.) example5.xml 111 Ten-Gallon Hat Short-Sleeved Linen Blouse 40 Red … 444 Special Seasonal If ProductType was an abstract type, the xsi:type would be required.

28 Derived type substitution (Cont.) Pros: Instance may be easier to process Cons: Looks slightly more complicated, and requires a declaration of the XML Schema Instance Namespace Difficult concept for those who unacquainted with schemas (they expect the tag name to identify the “type” of the element) Impossible to write a DTD that would validate this instance to the same degree

29 Requirements for XML Schema 1.1 Categories in the requirements document: A requirement must be met in XML Schema 1.1. A desideratum should be met in XML Schema 1.1. An opportunistic desideratum may be met in XML Schema 1.1. Requirements: Improve interaction between exclusions and disallowed substitutions in the element component. Address problems with the interaction between wildcards and substitution groups. Specifically, resolve the bug where if complex type A has a wildcard, and B restricts A, then it can restrict the wildcard to a set of elements that match the wildcard. Not all elements in the substitution groups of those elements necessarily match the wildcard – so B is not a subset of A. Desiderata: Allow an element declaration to be in more than one substitution group.

30 Summary Substitution groups – flexibility as a two-edged sword Pros: Content models can accept additional elements from a variety of namespaces and schema documents (unlike reusable choice groups, which require redefine to extend) No special syntax is needed in an instance (no xsi:type required)

31 Summary (Cont.) Substitution groups – flexibility as a two-edged sword Cons: Hard to tell which elements are actually substitutable – especially when they belong to different schema documents and different namespaces Instance may be hard to process (but block and final can help) JAXB and.NET XML serialization don’t support schemas with substitution groups Schema authors must be well acquainted with most of the features of XML schemas (namespaces, complex types, type derivation, etc.)

32 Any questions?