RE: SubstitutionGroup / Derivation Clarification

Hi,

Your "role" and "remark" element declarations are not allowed because, as
others have said, their type is not derived from contextType.  However,
"accept" _is_ legal, because it does not specify a type.  When an element
declaration does not specify a type, but does specify a substitution group,
the declared element automatically takes on the type of its substitution
group head, namely contextType.

In any case, you can achieve what you want by including all of them in the
choice group instead of using a substitution group, e.g.

<xsd:complexType name="contextType">
  <xsd:choice minOccurs="0" maxOccurs="unbounded">
    <xsd:element ref="context"/>
    <xsd:element ref="contextElement"/>
    <xsd:element ref="role"/>
    <xsd:element ref="remark"/>
    <xsd:element ref="accept"/>
  </xsd:choice>
  <xsd:attributeGroup ref="IDGroup"/>
</xsd:complexType>

This approach has the same effect, it is just less extensible.  The other
approach would be to create an abstract element that has the anyType, and
put all four elements in _its_ substitution group, e.g.

<xsd:complexType name="contextType">
  <xsd:choice minOccurs="0" maxOccurs="unbounded">
    <xsd:element ref="context"/>
    <xsd:element ref="anyElement"/>
  </xsd:choice>
  <xsd:attributeGroup ref="IDGroup"/>
</xsd:complexType>

<xsd:element name="anyElement" abstract="true"/>
<xsd:element name="contextElement" type="contextType"
substitutionGroup="anyElement"/>
<xsd:element name="role"
substitutionGroup="contextElement">...</xsd:element>
<xsd:element name="remark" type="xsd:string">
substitutionGroup="anyElement"/>
<xsd:element name="accept" substitutionGroup="anyElement"/>


Hope that helps,
Priscilla
-----------------------------------------------------------
Priscilla Walmsley                   priscilla@walmsley.com
Vitria Technology                     http://www.vitria.com
Author, Definitive XML Schema    (Prentice Hall, Dec. 2001)
-----------------------------------------------------------

> -----Original Message-----
> From: xmlschema-dev-request@w3.org
> [mailto:xmlschema-dev-request@w3.org]On Behalf Of xsd@themartian.com
> Sent: Saturday, December 01, 2001 1:29 PM
> To: xmlschema-dev@w3.org
> Subject: SubstitutionGroup / Derivation Clarification
>
>
> Just a clarification on these (not for me):
>
> Do these three parts of the schema work together?  In
> particular can the role, remark, and
> accept elements legally be in a substitutionGroup with the
> contextElement as its head
> (even though their types are not derived from contextType)?
>
> <xsd:complexType name="contextType">
>   <xsd:choice minOccurs="0" maxOccurs="unbounded">
>     <xsd:element ref="context" minOccurs="0" maxOccurs="unbounded"/>
>     <xsd:element ref="contextElement" minOccurs="0"
> maxOccurs="unbounded"/>
>   </xsd:choice>
>   <xsd:attributeGroup ref="IDGroup"/>
> </xsd:complexType>
>
> <xsd:element name="context" type="contextType"/>
>
> <xsd:element name="contextElement" type="contextType"/>
>
> <xsd:element name="role" substitutionGroup="contextElement">
>   <xsd:complexType>
>     <xsd:simpleContent>
>       <xsd:extension base="xsd:string">
>         <xsd:attribute name="idscheme" use="optional">
>           <xsd:simpleType>
>             <xsd:restriction base="xsd:NMTOKEN">
>               <xsd:enumeration value="MARC"/>
>               <xsd:enumeration value="ONIX"/>
>               <xsd:enumeration value="MPEG7"/>
>             </xsd:restriction>
>           </xsd:simpleType>
>         </xsd:attribute>
>       </xsd:extension>
>     </xsd:simpleContent>
>   </xsd:complexType>
> </xsd:element>
>
> <xsd:element name="remark" type="xsd:string"
> substitutionGroup="contextElement"/>
>
> <xsd:element name="accept" substitutionGroup="contextElement"/>
>
> Thanks in advance.
> From: xsd@themartian.com
> To: xmlschema-dev@w3.org
> Subject: SubstitutionGroup / Derivation Clarification
>
> Just a clarification on these (not for me):
>
> Do these three parts of the schema work together?  In
> particular can the role, remark, and
> accept elements legally be in a substitutionGroup with the
> contextElement as its head
> (even though their types are not derived from contextType)?
>
> <xsd:complexType name="contextType">
>   <xsd:choice minOccurs="0" maxOccurs="unbounded">
>     <xsd:element ref="context" minOccurs="0" maxOccurs="unbounded"/>
>     <xsd:element ref="contextElement" minOccurs="0"
> maxOccurs="unbounded"/>
>   </xsd:choice>
>   <xsd:attributeGroup ref="IDGroup"/>
> </xsd:complexType>
>
> <xsd:element name="context" type="contextType"/>
>
> <xsd:element name="contextElement" type="contextType"/>
>
> <xsd:element name="role" substitutionGroup="contextElement">
>   <xsd:complexType>
>     <xsd:simpleContent>
>       <xsd:extension base="xsd:string">
>         <xsd:attribute name="idscheme" use="optional">
>           <xsd:simpleType>
>             <xsd:restriction base="xsd:NMTOKEN">
>               <xsd:enumeration value="MARC"/>
>               <xsd:enumeration value="ONIX"/>
>               <xsd:enumeration value="MPEG7"/>
>             </xsd:restriction>
>           </xsd:simpleType>
>         </xsd:attribute>
>       </xsd:extension>
>     </xsd:simpleContent>
>   </xsd:complexType>
> </xsd:element>
>
> <xsd:element name="remark" type="xsd:string"
> substitutionGroup="contextElement"/>
>
> <xsd:element name="accept" substitutionGroup="contextElement"/>
>
> Thanks in advance.
>
>
>

Received on Wednesday, 5 December 2001 09:04:36 UTC