Jump to content

Inheritance


Kahor
 Share

Recommended Posts

Updated Hello,At one point in my xml schema, I had to declare a complex element that could have chield elements as many times as wanted and in whatever order, so I used a nested <sequence> <choice> type declaration, as follow :

<xs:complexType ="mainType">	<xs:sequence>		<xs:choice minOccurs="0" maxOccurs="unbounded">			<xs:element ref="element1" minOccurs="0" maxOccurs="unbounded" />			<xs:element ref="element2" minOccurs="0" maxOccurs="unbounded" />		</xs:choice>	</xs:sequence></xs:complexType>

Now I want to extend this type like this

 <xs:complexType name="extendedType>	<xs:complexContent>		<xs:extension base="mainType">			<xs:sequence>				<xs:choice minOccurs="0" maxOccurs="unbounded">					<xs:element ref="element3" minOccurs="0" maxOccurs="unbounded" />				</xs:choice>			</xs:sequence>		</xs:extension>	</xs:complexContent></xs:complexType>

The way I see it, type expension described in my two first code sample give this kind of result (not really sure) :

<xs:complexType ="finalType">	<xs:sequence>		<xs:choice minOccurs="0" maxOccurs="unbounded">			<xs:element ref="element1" minOccurs="0" maxOccurs="unbounded" />			<xs:element ref="element2" minOccurs="0" maxOccurs="unbounded" />			</xs:choice>		<xs:choice minOccurs="0" maxOccurs="unbounded">			<xs:element ref="element3" minOccurs="0" maxOccurs="unbounded" />		</xs:choice>	</xs:sequence></xs:complexType>

OR(?)

<xs:complexType ="finalType">	<xs:sequence>		<xs:choice minOccurs="0" maxOccurs="unbounded">			<xs:element ref="element1" minOccurs="0" maxOccurs="unbounded" />			<xs:element ref="element2" minOccurs="0" maxOccurs="unbounded" />			</xs:choice>	</xs:sequence>	<xs:sequence>		<xs:choice minOccurs="0" maxOccurs="unbounded">			<xs:element ref="element3" minOccurs="0" maxOccurs="unbounded" />		</xs:choice>	</xs:sequence></xs:complexType>

But I want something that would be equivalent to (basicaly merging the two <choice>) :

		<xs:complexType ="finalType">	<xs:sequence>		<xs:choice minOccurs="0" maxOccurs="unbounded">			<xs:element ref="element1" minOccurs="0" maxOccurs="unbounded" />			<xs:element ref="element2" minOccurs="0" maxOccurs="unbounded" />			<xs:element ref="element3" minOccurs="0" maxOccurs="unbounded" />		</xs:choice>	</xs:sequence></xs:complexType>

but by using extension.Is my understanding of extension right ? If so, how can I solve my problem ? If not, how does extension work ?Any idea ?

Link to comment
Share on other sites

As far as I know, xs:all is not supported in extensions by xml schema 1.0, anyway if I remember correctly xs:all as a maxOccurs limited to "1" which means you couldn't use the same element several times.I think this problem has no solution in the current version of xml schema, I used groups and restrictions to get around and it kinda works (probably not as well) (edit 2 : actualy it does not work at all according to JAXP but it works according to eclipse)edit : Also another limit of <extension>, I noticed is that you can only extend a type by an element that can only appear at the end of the sequence (you can't extend a type and then say this new element will appear at the beginning of the extended type)I hope they're thinking about that for their next version of xml schema.Does anyone know where one can find such informations ? (about new releases etc...)

Link to comment
Share on other sites

Perhaps in XML Schema's birthplace. Note that even when XML Schema 1.1 goes final, it will take some time before fully compliant implementations are available.If if you set xs:all's maxOccurs to "unbounded", it should allow all elements to appear as many times as you want, and in any order.

Link to comment
Share on other sites

http://www.w3schools.com/Schema/el_all.aspAs I said, the macOccurs param on <xs:all> is restricted to be 1 (or 0 but that would make no sense)you'd get the following error if you tried to use maxOccurs="unbounded"." the {maxOccurs} of an element in an 'all' model group must be 0 or 1..."same if you tried to put elements in a xs:all model to maxOccurs="unbounded"Thx for the link.
Link to comment
Share on other sites

Darn. I was really hoping that would be it.Well, the only thing I can suggest is that you try the mailing lists on that page. If you find something, do tell.

Link to comment
Share on other sites

In the "Spcecifications and development" section of the W3C page above:

discussion: xmlschema-dev@w3.org, xml-dev@lists.xml.org, comp.text.xml
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...