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]

RE: Really Understood W3C Schema Complex Types?



There are many things about using W3C schemas not covered in my article,
most obviously a "gotchas" alert or anything akin to a "best practices" use
of complex types. Anyone who reads it knows that.

I simply exploited a distinction you made in your article: the difference
between "understanding" and "using" complex types. My article
straightforwardly addresses the understanding side of that divide, in terms
of the syntax that expresses those types. I denied, and still deny, that
complex types are so complicated people ought not try to understand them
when they use them.

But now the adverb "really" appears. I take that to signal a change in
subject from that addressed in my article.

So far as the "problem" of type substitution goes, your own characterization
is revealing: if the problem is that developers and programmers don't know
the side effects of type substitution, the obvious answer is to educate
them.  The assertion "people don't know that using X produces the side
effect Y" is no basis for criticism of the technology represented by X; it
is a criticism of their knowledge of X.

So far as your example of the fragility of the type system goes, while I
think I understand what you are asking for in this example, I don't
understand the type "repeating.derived" or the basis of your objection.

You want the "repeating" type to extend the base type of "annotation" (which
is not specified) with the group "list.classes". OK.

Since I can't be sure what the type of "annotation" is, I can't be sure what
the type "repeating.derived" is supposed to be doing, relative to what
"repeating" is doing. (Was this a typo? Did you mean to restrict
"repeating"?) You say that whatever it's doing isn't allowed by W3C schemas,
so I'm not following your thinking.

I've included below some schema types that provide what you are asking for,
but I can only presume that you will consider this a breaking of the type
system. You'll have to explain to me why this is a breaking of the type, or
whatever other objections you have to it.

Regards,

Don Smith

<xs:schema xmlns:xs = "http://www.w3.org/2001/XMLSchema"
	 targetNamespace = "blahblahblah"
	 xmlns:nsm = "blahblahblah"
	 elementFormDefault = "qualified">

<xs:element name="GGG" type="nsm:repeating" />
<xs:element name="HHH" type="nsm:notSameRepeating" />

<xs:complexType name="annotation">
  <xs:complexContent>
    <xs:restriction base="xs:anyType">
      <xs:sequence>
        <xs:element name="Z" type="xs:string" minOccurs="1" maxOccurs="1"/>
        <xs:element name="Y" type="xs:string" minOccurs="1" maxOccurs="1"/>
      </xs:sequence>
    </xs:restriction>
  </xs:complexContent>
</xs:complexType>

<xs:group name="list.class">
  <xs:sequence>
    <xs:element name="A" type="xs:string" />
    <xs:element name="B" type="xs:string" />
    <xs:element name="C" type="xs:string" />
  </xs:sequence>
</xs:group>

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

<xs:complexType name="newAtype">
  <xs:complexContent>
    <xs:restriction base="xs:anyType">
      <xs:sequence>
        <xs:element name="A" type="xs:string" />
      </xs:sequence>
    </xs:restriction>
  </xs:complexContent>
</xs:complexType>


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

</xs:schema>


-----Original Message-----
From: Kohsuke KAWAGUCHI [mailto:kohsukekawaguchi@yahoo.com]
Sent: Friday, August 31, 2001 2:58 PM
To: xml-dev@lists.xml.org
Subject: 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


-----------------------------------------------------------------
The xml-dev list is sponsored by XML.org <http://www.xml.org>, an
initiative of OASIS <http://www.oasis-open.org>

The list archives are at http://lists.xml.org/archives/xml-dev/

To subscribe or unsubscribe from this elist use the subscription
manager: <http://lists.xml.org/ob/adm.pl>