Thanks for coming back to me on this Eric,
but my challenge is how to avoid having to specify in the schema that I am
allowing objects of type A or type B, I just want to specify that elements
of type Model (or members of that substitution group) can be inserted into
the list.
This will prevent me having to remember to change the ListType definition
when I add a new model type. In my sample, the ListB element works ok (and
that has been the way I've always done it), I just want to move forward to
specifying sub-elements using the ListB type definition.
Cheers,
Ian
"Eric Sirois" <> wrote in message
news:bg8j1k$sa6$...
> Hello Ian,
>
> If you want to use the globally defined elements <A> and <B>, change the
> following content model
>
> <xs:complexType name="ListTypeB">
> <xs:choice minOccurs="0" maxOccurs="unbounded">
> <xs:element name="A" type="TypeA"/>
> <xs:element name="B" type="TypeB"/>
> </xs:choice>
> </xs:complexType>
>
> to:
>
> <xs:complexType name="ListTypeB">
> <xs:choice minOccurs="0" maxOccurs="unbounded">
> <xs:element ref="A" />
> <xs:element ref="B" />
> </xs:choice>
> </xs:complexType>
>
> There is a difference bettwen the two content models. The top defines
> and use local element <A> and <B>. They are not the same as the two
> global element defintion. Think of it as defining a local variable in
> a method with the same name as global variable in a class.
>
> Kind regards,
> Eric
>
>
> Ian Mayo wrote:
> > Thanks again for that advice Michael.
> >
> > It's worked fine for defining my structure to model "the real world".
> >
> > Unfortunately my XML editor (XMLSpy) doesn't appear to be property
> > recognising the model, but there's a strong chance that this is caused
by my
> > incorrect schema definition.
> >
> > In the sample xsd (below) a scenario object can contain a ListA - which
> > contains multiple instances of a Model (or child thereof). It can a
ListB
> > which includes instances of the same objects (defined using my "old" way
of
> > doing it).
> >
> > My editor can see that into ListA I can but objects of type A or type B,
but
> > it isn't aware of their properties = whereas when I insert them into
ListB -
> > it provides direct access to their properties.
> >
> > Is this because my schema definition is too vague to provide it with
that
> > information? Or is this in fact a problem with my XML editor?
> >
> > Many thanks in advance,
> >
> > Ian Mayo
> >
> >
> >
> > ================================================== ===========
> >
> > <?xml version="1.0" encoding="UTF-8"?>
> > <!-- edited with XMLSPY v5 rel. 4 U (http://www.xmlspy.com) by Ian Mayo
> > (PlanetMayo Ltd) -->
> > <!--W3C Schema generated by XMLSPY v5 rel. 4 U
(http://www.xmlspy.com)-->
> > <xs:schema xmlns
s="http://www.w3.org/2001/XMLSchema"
> > elementFormDefault="qualified">
> >
> > <xs:element name="Scenario">
> > <xs:annotation>
> > <xs:documentation>Container for a chain</xs:documentation>
> > </xs:annotation>
> > <xs:complexType>
> > <xs:sequence>
> > <xs:element name="ListA" type="ListTypeA"/>
> > <xs:element name="ListB" type="ListTypeB"/>
> > </xs:sequence>
> > </xs:complexType>
> > </xs:element>
> >
> > <xs:complexType name="ListTypeA">
> > <xs:choice minOccurs="0" maxOccurs="unbounded">
> > <xs:element ref="Model" />
> > </xs:choice>
> > </xs:complexType>
> >
> > <xs:complexType name="ListTypeB">
> > <xs:choice minOccurs="0" maxOccurs="unbounded">
> > <xs:element name="A" type="TypeA"/>
> > <xs:element name="B" type="TypeB"/>
> > </xs:choice>
> > </xs:complexType>
> >
> > <!-- -->
> > <!-- DECISION MODELS -->
> > <!-- -->
> > <xs:element name="Model" abstract="true"/>
> > <xs:complexType name="ModelType">
> > <xs:annotation>
> > <xs:documentation>Base type for models</xs:documentation>
> > </xs:annotation>
> > <xs:attribute name="Name" type="xs:string" use="required"/>
> > </xs:complexType>
> >
> > <xs:element name="A" type="TypeA" substitutionGroup="Model"/>
> > <xs:complexType name="TypeA">
> > <xs:complexContent>
> > <xs:extension base="ModelType">
> > <xs:attribute name="attA_A" type="xs:float" use="required"/>
> > <xs:attribute name="attA_B" type="xs:float" use="required"/>
> > </xs:extension>
> > </xs:complexContent>
> > </xs:complexType>
> >
> > <xs:element name="B" type="TypeB" substitutionGroup="Model"/>
> >
> > <xs:complexType name="TypeB">
> > <xs:complexContent>
> > <xs:extension base="ModelType">
> > <xs:attribute name="attB_A" type="xs:string" use="required"/>
> > <xs:attribute name="attB_B" type="xs:string" use="required"/>
> > </xs:extension>
> > </xs:complexContent>
> > </xs:complexType>
> > </xs:schema>
> >
> >
>