RE: Extending Types

> 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 14:01:17 UTC