Re: Trying to Understand Complex Abstract Types: How To Define?

Hi Eliot,

I think you can use abstract elements and substitution groups to achieve 
something similar with your example. See the following sample schema:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
     <xs:element name="InformationModule" abstract="true" 
type="InformationModuleType"/>
     <xs:complexType name="InformationModuleType">
         <xs:sequence>
             <xs:element ref="ObjectName"/>
             <xs:element ref="ShortDesc"/>
             <xs:element maxOccurs="unbounded" ref="InformationModuleItem"/>
         </xs:sequence>
     </xs:complexType>
     <xs:element name="ObjectName" abstract="true"/>
     <xs:element name="ShortDesc"/>
     <xs:element name="InformationModuleItem" abstract="true"/>

     <xs:element name="ElementType" substitutionGroup="InformationModule"/>
     <xs:element name="ElementTypeName" substitutionGroup="ObjectName"/>
     <xs:element name="Purpose" substitutionGroup="InformationModuleItem"/>
     <xs:element name="ContentModel" 
substitutionGroup="InformationModuleItem"/>
</xs:schema>

The following instance is valid against the schema:

<?xml version="1.0" encoding="UTF-8"?>
<ElementType xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:noNamespaceSchemaLocation="sample.xsd">
     <ElementTypeName></ElementTypeName>
     <ShortDesc></ShortDesc>
     <Purpose></Purpose>
     <ContentModel></ContentModel>
</ElementType>

Also the same instance is valid against a little more restricted schema 
as below:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
     <xs:element name="InformationModule" abstract="true" 
type="InformationModuleType"/>
     <xs:complexType name="InformationModuleType">
         <xs:sequence>
             <xs:element ref="ObjectName"/>
             <xs:element ref="ShortDesc"/>
             <xs:element maxOccurs="unbounded" ref="InformationModuleItem"/>
         </xs:sequence>
     </xs:complexType>
     <xs:element name="ObjectName" abstract="true"/>
     <xs:element name="ShortDesc"/>
     <xs:element name="InformationModuleItem" abstract="true"/>

     <xs:element name="ElementType" 
substitutionGroup="InformationModule" type="ElementTypeType"/>

     <xs:complexType name="ElementTypeType">
         <xs:complexContent>
             <xs:restriction base="InformationModuleType">
                 <xs:sequence>
                     <xs:element ref="ElementTypeName"/>
                     <xs:element ref="ShortDesc"/>
                     <xs:choice maxOccurs="unbounded">
                         <xs:element ref="Purpose"/>
                         <xs:element ref="ContentModel"/> 

                     </xs:choice>
                 </xs:sequence>
             </xs:restriction>
         </xs:complexContent>
     </xs:complexType>

     <xs:element name="ElementTypeName" substitutionGroup="ObjectName"/>
     <xs:element name="Purpose" substitutionGroup="InformationModuleItem"/>
     <xs:element name="ContentModel" 
substitutionGroup="InformationModuleItem"/>
</xs:schema>

Hope that helps,
George
---------------------------------------------------------------------
George Cristian Bina
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com


Eliot Kimber wrote:
> 
> What I'm trying to do is define an abstract type with a specific content 
> model that should act as the model for specialized types such that 
> specialized types must declare sub element types of the same type as in 
> my model.
> 
> For example, my abstract complex type is as follows, with an indication 
> of the desired specialization rules:
> 
> InformationModule [specialization required] goes to:
>   <ObjectName> [specialization required]
>   <ShortDesc> [specialization optional]
>   <InformationModuleItem>+ [specialization required]
> 
> 
> With the intent that InformationModule must be used as the type for 
> specialized elements and those elements must specialize <ObjectName> and
> <InformationModuleItem>, e.g.,
> 
> <ElementType> [xsi:type="InformationModule"]
>   <ElementTypeName> [xsi:type="ObjectName"]
>   <ShortDesc>
>   <Purpose>         [xsi:type="InformationModuleItem"]
>   <ContentModel>    [xsi:type="InformationModuleItem"]
> </Element>
> 
> What I want to be able to do, but I realize I can't, is define an 
> abstract type that defines its content model in terms of types, not in 
> terms of element types. But lacking that, I'm not sure how to do what I 
> want.
> 
> I think that substitution groups is the mechanism to use but it's not 
> immediagely clear now to do it and I fear that I'm not thinking about 
> this task in the right way, that I'm trying to be too object oriented 
> and that that is throwing me off.
> 
> Can anyone point me in the right direction or help me understand the 
> Schema way to think about this sort of problem?
> 
> What I'm trying to do is essentially what the old HyTime SGML 
> architecture mechanism let you do and what the DITA specialization 
> mechanism lets you do. There doesn't seem to be a direct correlation to 
> either of those mechanisms in XSD but I want to make sure I haven't 
> missed something.
> 
> Thanks,
> 
> Eliot

Received on Tuesday, 22 March 2005 07:32:38 UTC