Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

XMS schema and Generalisation of ComplexType

Status
Not open for further replies.

noon

Programmer
Mar 2, 2003
2
FR
Does the concept of Generalization (present in object language) exist in XML Schema ?

Here is a simple XML example of what i'd like to write :

<FruitBag>
<Apple color=&quot;red&quot; radius=&quot;2&quot;/>
<Orange color=&quot;orange&quot; radius=&quot;2&quot;/>
<Banana color=&quot;yellow&quot; heigth=&quot;5&quot;/>
</FuitBag>

And here is the kind of declaration i'd like to have :

a fruit :

<xs:complexType name=&quot;FruitType&quot;>
<xs:attribute name=&quot;color&quot; type=&quot;xs:string&quot; />
</xs:complexType>

an apple :

<xs:complexType name=&quot;AppleType&quot;>
<xs:complexContent>
<xs:extension base=&quot;FruitType&quot;>
<xs:attribute name=&quot;radius&quot; type=&quot;xs:string&quot;/>
</xs:extension>
</xs:complexContent>
</xs:complexType>

a banana :

<xs:complexType name=&quot;BananaType&quot;>
<xs:complexContent>
<xs:extension base=&quot;FruitType&quot;>
<xs:attribute name=&quot;heigth&quot; type=&quot;xs:string&quot;/>
</xs:extension>
</xs:complexContent>
</xs:complexType>


and for the FuitBag, i'd like to define it like a container of FruitType. It can contain Apple, and/or Banana, because Apple and Banana are FruitType.

But if i define it like this :

<xs:complexType name=&quot;FruitBag&quot;>
<xs:sequence>
<xs:element name=&quot;Fruit&quot; type=&quot;FruitType maxOccurs=&quot;unbounded&quot;/>
</xs:sequence>
</xs:complexType>


A valid XML would be :

<FruitBag>
<Fruit color=&quot;red&quot; />
<Fruit color=&quot;orange&quot; />
<Fruit color=&quot;yellow&quot; />
</FuitBag>

And that's not what I want.
I don't want to define FruitBag like a container of Apple Banana, etc,
because I can have a lot of different fruits type, and if I define another kind of Fruit, i would have to add it to the declaration of my FruitBag.

So does this concept exist in XML schema ?
Or is there any way to do something like this ?

Thanks for the answers.
(Sorry if the question have allready been asked)


 
No, there is no such thing in xml schemas (at least, none I know about; I would welcome somebody who knows this way or the other for sure).

But, instead generalizing, I would suggest using aggregation, so have a fruit complext type which is a collection of all other fruits, selected by a choice statement...

That is, keep your fruit bag as it is, but have the fruit type as:

Code:
<xsd:element &quot;Fruits&quot;>
     <xsd:choice>
       <xsd:element name=&quot;Banana&quot; type=&quot;BananaType&quot;/>       
       <xsd:element name=&quot;Apple&quot; type=&quot;AppleType&quot;/>
etc...


I don't know if this would suit you...
HTH

You will have to add all the new fruits to your Fruits datatype. [red]Nosferatu[/red]
We are what we eat...
There's no such thing as free meal...
once stated: methane@personal.ro
 
It doesn't really suit to hat i want to do, but its an idea.

Thanks for your answer.




 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top