OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.


Help: OASIS Mailing Lists Help | MarkMail Help

[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index]
An element with more than one possible type

I am trying to code a XML Schema (XSD file) for a web service in such a way:

   <product name = "water" volume ="22">
   <product name = "meat" weight = "10" >

It is to say, if name is "water" , then use the "volume" attribute.
When name is "meat" then use "weight" attribute.

What I have done is to define a simple type for name attribute

<xs:simpleType name="nameType">
	<xs:restriction base="xs:string">
		<xs:enumeration value="water"/>
		<xs:enumeration value="meat"/>

Then I defined an abstract complex type for "product" element:

<xs:complexType name="productType" abstract = "true">
	<xs:attribute name = "name" type = "nameType"/>

I restricted the "name" attribute to "meat":

<xs:complexType name="productTypeMeat">
		<xs:restriction base="productType">
			<xs:attribute name = "name" type = "nameType"   fixed="meat"/>

... and finally I added an attribute "weight":

<xs:complexType name="productTypeMeatWeight">
		<xs:extension base="productTypeMeat">
			<xs:attribute name = "weight" type = "xs:int"/>

For the "water" is the same as "meat". First I restricted the "name"
attribute to "water":
<xs:complexType name="productTypeWater">
		<xs:restriction base="productType">
			<xs:attribute name = "name" type = "nameType"   fixed="water"/>

... and finally I added the "volume" attribute

<xs:complexType name="productTypeWaterVolume">
		<xs:extension base="productTypeWater">
			<xs:attribute name = "volume" type = "xs:int"/>

The problem is to define the type for "product" element. If I use
"productType" as type it the XML does not validated because
"productType" is abstract. I I use:

<xs:element  name="products">
				<xs:element name="product" type="productTypeWaterVolume"/>
				<xs:element name="product" type="productTypeMeatWeight"/>

the XML does not validate because the validator assumes that the
"product" type is the first defined (productTypeWaterVolume). If I
change the declaration of "product"  element then the validator
assumes that the type of "product" is "productTypeMeatWeight".

Do you know how to solve this problem?

Thanks in advance.


[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index]

News | XML in Industry | Calendar | XML Registry
Marketplace | Resources | MyXML.org | Sponsors | Privacy Statement

Copyright 1993-2007 XML.org. This site is hosted by OASIS