OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.

 


Help: OASIS Mailing Lists Help | MarkMail Help

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Really Understood W3C Schema Complex Types?




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@yahoo.com