licryle
04-29-2009, 02:11 PM
Hi all,
I'm trying to describe some structure that works based on restrictions.
On the first level, I have a general description of my model (this constitutes a first Schema, let's say I describe office furnitures).
On the second level, I have a more specific description (let's say I define the characteristics of tables, this is a second Schema based on restrictions of the first one).
The instance will be so a specific table.
To achieve this model, I use restrictions, which enables me to have something really abstracted on the first level. However, I ran into troubles with the use of restricted subtypes, on how to specifically declare them in the instance and as well in some cases in the restriction itself.
To make it simpler, I wrote a simple XSD file which you can see bellow and 2 associated questions:
1. tSubRoot is a kind of tRoot, how in the instance can I specify that I want to use the tSubRoot and not the tRoot for the "root" element? This affects the possible children ...
2. This document will not validate because of the restriction "tSubRoot": even though I could describe in the instance a "data" child of tData type and a "data" child of tSubData type (since tSubData restricts tData), it seems that I can't specify this restriction:
-- if I change the name of the node, it's not a good restriction anymore
-- if I use the same name "data", it complains as well...
I would very much appreciate some comment/help on this :)
Thanks a lot,
Cyrille
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns="ns1"
targetNamespace="ns1">
<xs:element name="root" type="tRoot" />
<xs:complexType name="tRoot">
<xs:sequence>
<xs:choice maxOccurs="unbounded">
<xs:element name="data" type="tData" minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="dataOther" type="tDataOther" minOccurs="0" maxOccurs="unbounded" />
</xs:choice>
</xs:sequence>
</xs:complexType>
<xs:complexType name="tSubRoot">
<xs:complexContent>
<xs:restriction base="tRoot" >
<xs:sequence>
<xs:element name="data" type="tData" />
<xs:element name="data" type="tSubData" />
</xs:sequence>
</xs:restriction>
</xs:complexContent>
</xs:complexType>
<xs:complexType name="tData">
<xs:sequence>
<xs:choice maxOccurs="unbounded">
<xs:element name="el1" type="xs:integer" />
<xs:element name="el2" />
<xs:element name="el3" />
</xs:choice>
</xs:sequence>
</xs:complexType>
<xs:complexType name="tSubData">
<xs:complexContent>
<xs:restriction base="tData" >
<xs:sequence>
<xs:element name="el1" type="xs:byte" />
</xs:sequence>
</xs:restriction>
</xs:complexContent>
</xs:complexType>
<xs:complexType name="tDataOther">
<xs:sequence>
</xs:sequence>
</xs:complexType>
</xs:schema>
I'm trying to describe some structure that works based on restrictions.
On the first level, I have a general description of my model (this constitutes a first Schema, let's say I describe office furnitures).
On the second level, I have a more specific description (let's say I define the characteristics of tables, this is a second Schema based on restrictions of the first one).
The instance will be so a specific table.
To achieve this model, I use restrictions, which enables me to have something really abstracted on the first level. However, I ran into troubles with the use of restricted subtypes, on how to specifically declare them in the instance and as well in some cases in the restriction itself.
To make it simpler, I wrote a simple XSD file which you can see bellow and 2 associated questions:
1. tSubRoot is a kind of tRoot, how in the instance can I specify that I want to use the tSubRoot and not the tRoot for the "root" element? This affects the possible children ...
2. This document will not validate because of the restriction "tSubRoot": even though I could describe in the instance a "data" child of tData type and a "data" child of tSubData type (since tSubData restricts tData), it seems that I can't specify this restriction:
-- if I change the name of the node, it's not a good restriction anymore
-- if I use the same name "data", it complains as well...
I would very much appreciate some comment/help on this :)
Thanks a lot,
Cyrille
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns="ns1"
targetNamespace="ns1">
<xs:element name="root" type="tRoot" />
<xs:complexType name="tRoot">
<xs:sequence>
<xs:choice maxOccurs="unbounded">
<xs:element name="data" type="tData" minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="dataOther" type="tDataOther" minOccurs="0" maxOccurs="unbounded" />
</xs:choice>
</xs:sequence>
</xs:complexType>
<xs:complexType name="tSubRoot">
<xs:complexContent>
<xs:restriction base="tRoot" >
<xs:sequence>
<xs:element name="data" type="tData" />
<xs:element name="data" type="tSubData" />
</xs:sequence>
</xs:restriction>
</xs:complexContent>
</xs:complexType>
<xs:complexType name="tData">
<xs:sequence>
<xs:choice maxOccurs="unbounded">
<xs:element name="el1" type="xs:integer" />
<xs:element name="el2" />
<xs:element name="el3" />
</xs:choice>
</xs:sequence>
</xs:complexType>
<xs:complexType name="tSubData">
<xs:complexContent>
<xs:restriction base="tData" >
<xs:sequence>
<xs:element name="el1" type="xs:byte" />
</xs:sequence>
</xs:restriction>
</xs:complexContent>
</xs:complexType>
<xs:complexType name="tDataOther">
<xs:sequence>
</xs:sequence>
</xs:complexType>
</xs:schema>