Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


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

From: George Cristian Bina <george@----.-->
To: Eliot Kimber <ekimber@---------------.--->
Date: 3/22/2005 11:41:00 AM
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
www.---.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

From ht@i... Tue Mar 22 10:28:43 2005
Received: from lisa.w3.org ([128.30.52.41])
	by frink.w3.org with esmtp (Exim 4.44)
	id 1DDgct-0007rd-1c
	for xmlschema-de


transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent