[XML-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

An element with more than one possible type

  • From: "pau carre" <pau.carre@g...>
  • To: xml-dev@l...
  • Date: Fri, 2 Feb 2007 12:08:08 +0100

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]


PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
 

Stylus Studio has published XML-DEV in RSS and ATOM formats, enabling users to easily subcribe to the list from their preferred news reader application.


Stylus Studio Sponsored Links are added links designed to provide related and additional information to the visitors of this website. they were not included by the author in the initial post. To view the content without the Sponsor Links please click here.

Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.