- From: Joey Coyle <joey@xcoyle.com>
- Date: Wed, 13 Mar 2002 12:02:59 -0500 (EST)
- To: Jeni Tennison <jeni@jenitennison.com>
- Cc: xmlschema-dev@w3.org
thanks Jeni, I finally understand substitution groups. Even though that works, it would be convenient if they added a way to restrict the wildcard method, because it is simple and is the way most programmers think about making arrays of a Parent class, which allows the array to have any subtype of that parent. And then you would't have to declare global elements. Maybe something like this ... <complexType name="basetype"> <sequence> <any restriction="myType" maxOccurs="unbounded"/> </sequence> </complexType> This would allow only a sequence of "myType" or restrictions of "myType", Then this would be valid ... <complexType name="newtype"> <complexContent> <restriction base="my:basetype"> <sequence> <element name="e1" type="myTypeRestriction1"/> <element name="e2" type="myTypeRestriction2"/> <element name="e3" type="myTypeRestriction3"/> </sequence> </restriction> </complexContent> </complexType> thanks again, joey At 12:30 PM 3/13/2002 +0000, you wrote: >Hi Joey, > > > I read in this list that this first example is OK, but is there a > > way to do this with a type other than "any". Instead of any, I would > > like my own type, then I would like to substitute derived types as > > is done here. My example is after the $$$$$$$$$$$$$$$$$$$$$$$$$, and > > I hope it is valid. > >I'm afraid that what you have definitely isn't valid. When you do a >restriction, elements that are valid according to the restricted type >must also be valid according to the base type. In your case, if you >had: > > <foo> > <e1 /> > </foo> > >which is valid according to your newtype: > > > <complexType name="newtype"> > > <complexContent> > > <restriction base="my:basetype"> > > <sequence> > > <element name="e1" type="myTypeRestriction"/> > > <element name="e2" type="myTypeRestriction2" minOccurs="0"/> > > <element name="e3" type="myTypeRestriction3" minOccurs="0"/> > > </sequence> > > </restriction> > > </complexContent> > > </complexType> > >it wouldn't be valid according to your base type, which only allows >'item' elements within the element: > > > <complexType name="basetype"> > > <sequence> > > <element name="item" type="myType" maxOccurs="unbounded"/> > > </sequence> > > </complexType> > >The reason that you can do the restriction with the xs:any wildcard >is that the base type then allows any element. > >What you could do, however, is create a substitution group for the >four elements, with 'item' as the head element. The elements have to >be declared globally, as follows: > ><element name="item" type="myType" /> ><element name="e1" type="myTypeRestriction" substitutionGroup="item" /> ><element name="e2" type="myTypeRestriction2" substitutionGroup="item" /> ><element name="e3" type="myTypeRestriction3" substitutionGroup="item" /> > >[Note that myTypeRestriction must be derived from MyType.] > >You can then define your base type by referring to that item element: > ><complexType name="basetype"> > <sequence> > <element ref="item" maxOccurs="unbounded"/> > </sequence> ></complexType> > >and likewise your newtype by referring to the global declarations of >the other elements: > ><complexType name="newtype"> > <complexContent> > <restriction base="my:basetype"> > <sequence> > <element ref="e1" /> > <element ref="e2" minOccurs="0"/> > <element ref="e3" minOccurs="0"/> > </sequence> > </restriction> > </complexContent> ></complexType> > >This works because if you take account of the substitution group, the >basetype type definition is equivalent to: > ><complexType name="basetype"> > <sequence> > <choice maxOccurs="unbounded"> > <element ref="item" /> > <element ref="e1" /> > <element ref="e2" /> > <element ref="e3" /> > </choice> > </sequence> ></complexType> > >Cheers, > >Jeni > >--- >Jeni Tennison >http://www.jenitennison.com/
Received on Thursday, 14 March 2002 14:11:57 UTC