XML.orgXML.org
FOCUS AREAS |XML-DEV |XML.org DAILY NEWSLINK |REGISTRY |RESOURCES |ABOUT
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:

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

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"/>
	</xs:restriction>
</xs:simpleType>

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

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

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

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

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

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

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

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

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

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:complexType>
		<xs:sequence>
			<xs:choice>
				<xs:element name="product" type="productTypeWaterVolume"/>
				<xs:element name="product" type="productTypeMeatWeight"/>
			</xs:choice>
		</xs:sequence>
	</xs:complexType>
</xs:element>

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.

Pau


[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