[XML-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Really Understood W3C Schema Complex Types?

  • From: Kohsuke KAWAGUCHI <kohsukekawaguchi@y...>
  • To: xml-dev@l...
  • Date: Fri, 31 Aug 2001 12:57:50 -0700

w3c schema editor

Just in case someone is still interested in this topic, there are some
stories which were not told in Mr.Smith's article: "Understanding W3C
Schema Complex Types"

Sure, it's easy when all you need is two or three types, but we need to
think about non-trivial schemas, don't we.



Type Substitutability
=====================
Complex types automatically gives you type substitutability. If you
define a schema as follows:

<xs:complexType name="base">
  ...
</xs:complexType>

<xs:complexType name="derived">
  <xs:complexContent>
    <xs:extension base="base">
      ...
</xs:complexType>

<xs:element name="foo" type="base"/>


Then you are allowing the following document:

<foo xsi:type="derived">
  ... the content model of the derived type
</foo>


First question. How many of the schema authors know this side effect when
s/he innocently writes this type hierarchy?  I personally saw these kind
of mistakes made by relatively experienced schema authors.


Second question. Say the schema author is fully aware of what s/he is
doing, how many developers are aware of this side effect?  Since they
are valid documents, an application has to accept them and to do a
proper processing.




Fragility
=========

Say you've defined the following type (A|B|C)*

<xs:group name="list.class">
  <xs:choice>
    <xs:element ref="A"/>
    <xs:element ref="B"/>
    <xs:element ref="C"/>
  </xs:choice>
</xs:group>

<xs:complexType name="repeating">
  <xs:complexContent>
    <xs:extension base="annotated">
      <xs:group ref="list.class" minOccurs="0" maxOccurs="unbounded"/>
    </xs:extension>
  </xs:complexContent>
</xs:complexType>

Now, let's say you want to define "A,(A|B|C)*". That is, you want to fix
the first item to A.

<xs:complexType name="repeating.derived">
  <xs:complexContent>
    <xs:restriction base="annotated">
      ....
      <xs:element ref="A"/>
      <xs:group ref="list.class" minOccurs="0" maxOccurs="unbounded"/>
    </xs:restriction>
  </xs:complexContent>
</xs:complexType>



First, according to the spec, this is not a valid restriction. So you
can't do this.
(By the way, one of the horrible fact is that the author used a schema
editor to produce this schema and still he couldn't detect this error.)

Now what will you do? You basically need to break the type hierarchy and
derive the "repeating.derived" type directly from the "repeating" type.
If you need to break the type hierarchy, what is the whole point of
using types?



Those problems do happen if you use W3C XML Schema in the real world.
Now are you really sure that you understood W3C Schema complex types?


regards,
----------------------
K.Kawaguchi
E-Mail: kohsukekawaguchi@y...


PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
 

Stylus Studio has published XML-DEV in RSS and ATOM formats, enabling users to easily subcribe to the list from their preferred news reader application.


Stylus Studio Sponsored Links are added links designed to provide related and additional information to the visitors of this website. they were not included by the author in the initial post. To view the content without the Sponsor Links please click here.

Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.