RE: Extending Types

Your reply was off-list, I'm copying it back to the list.

The problem I think is that when you extend a type, the extension always
goes at the end.

Regards,

Michael Kay
http://www.saxonica.com/
http://twitter.com/michaelhkay 

> -----Original Message-----
> From: Flavio Cordova [mailto:flavio.cordova@gmail.com] 
> Sent: 01 December 2009 18:01
> To: Michael Kay
> Subject: Re: Extending Types
> 
> Well.. I have changed some things but that's how it looks like now:
> 
> In definition.xsd
> 
> DEFINITION:
>     <xs:complexType name="AbstractBusinessContentType" 
> abstract="true">
>     	<xs:sequence>
>     		<xs:element name="CustomInformation">
>                                      ....
>     		</xs:element>
>     	</xs:sequence>
>     </xs:complexType>
> 
> ELEMENT:
> <xs:element name="BusinessContent"
> type="AbstractBusinessContentType"></xs:element>
> 
> 
> in item.xsd, I have this:
> 
> 	<xs:redefine schemaLocation="../definition.xsd">
> 		<xs:complexType name="AbstractBusinessContentType">
> 			<xs:complexContent>
> 				<xs:extension 
> base="AbstractBusinessContentType">
> 					<xs:sequence>
> 						<xs:element 
> name="Code" type="xs:string"></xs:element>
> 						<xs:element 
> name="Description" type="xs:string"></xs:element>
> 					</xs:sequence>
> 				</xs:extension>
> 			</xs:complexContent>
> 		</xs:complexType>
> 	</xs:redefine>
> 
> But it doesn't work too.. When I create the XML the validator 
> shows that Code is not a valid child for BusinessContent.
> 
>     <BusinessContent>
>       <Code>UN</Code> <!-- ### Invalid child ### -->
>       <Description>Unidade</Description>
>       <CustomInformation>
>       	<Table name="labInfo">
>       		<Record>
>       			<Field name="quanticMass">120</Field>
>       			<Field 
> name="fusionMethod">Nuclear</Field>
>       		</Record>
>       	</Table>
>       </CustomInformation>
>     </BusinessContent>
> 
> Talking about compositions or inheritance, I don't know 
> exactly how it would work (I mean, I know the concepts, but I 
> really don't what it would do with my xml.. :D)
> 
> I'll try to find something about named model groups to see if 
> I could use them...
> 
> 
> On Tue, Dec 1, 2009 at 12:00 PM, Michael Kay 
> <mike@saxonica.com> wrote:
> >> I have an XML that looks like this:
> >>
> >> <MyMessage>
> >>   <HeaderInfo>
> >>      ....
> >>   </HeaderInfo>
> >>   <BusinessContent>
> >>     #someSpecificInformation# <!-- This will be defined in 
> a "child" 
> >> XSD
> >>     <GenericInfo>
> >>        <information>a</information>
> >>     </GenericInfo>
> >>   </BusinessContent>
> >> </MyMessage>
> >>
> >> In a file called definition.xsd, I defined the whole structure, 
> >> including the BusinessContent ComplexType.. Then, I 
> defined another 
> >> XSD, called item.xsd, where I'd like to define only the content of 
> >> the BusinessContent, so I did something like this:
> >>
> >> <xs:include schemaLocation="definition.xsd"></xs:include>
> >> <xs:complexType name="BusinessContentTypeImpl">
> >>   <xs:complexContent>
> >>     <xs:extension base="GenericBusinessContentType">
> >>       <xs:sequence>
> >>         <xs:element name="Code" type="xs:string"></xs:element>
> >>         <xs:element name="Description" 
> type="xs:string"></xs:element>
> >>       </xs:sequence>
> >>     </xs:extension>
> >>   </xs:complexContent>
> >> </xs:complexType>
> >
> > What does the element declaration for BusinessContent look 
> like? Is it 
> > using the GenericBusinessContentType or 
> BusinessContentTypeImpl? You 
> > can only use the BusinessContentTypeImpl content model if 
> the type is 
> > declared as BusinessContentTypeImpl either in the element 
> declaration, 
> > or in an xsi:type attribute in the instance.
> >
> > Have you considered using named model groups instead? As with any 
> > object-oriented design, people sometimes overlook that 
> composition is 
> > more powerful than inheritance.
> >
> > Regards,
> >
> > Michael Kay
> > http://www.saxonica.com/
> > http://twitter.com/michaelhkay
> >
> >
> >>
> >> When I create an XML (adding tags Code and Description), I get an 
> >> error because tags Code and Description are not valid children for 
> >> BusinessContent, although I've extended it...
> >>
> >> I'd also like to force extension of BusinessContent. Then 
> I tried to 
> >> use the abstract attribute, but then I couldn't add the 
> <GenericInfo> 
> >> child...
> >>
> >> So, my questions are:
> >> 1) how should I extend BusinessContent
> >> (GenericBusinessContentType) so I could keep the current elements 
> >> (GenericInfo) add more elements..
> >> 2) how could I force a "child" xsd file to import the 
> definitions.xsd 
> >> and extend BusinessContent.
> >>
> >> Thanks !
> >>
> >>
> >
> >

Received on Tuesday, 1 December 2009 18:20:34 UTC