W3C home > Mailing lists > Public > xmlschema-dev@w3.org > April 2004

RE: Multiple Types for an element

From: Xan Gregg <Xan.Gregg@jmp.com>
Date: Thu, 8 Apr 2004 13:04:54 -0400
Message-ID: <939FBCFFFF9B0C40BF8B53294E2296DB4AFA50@merc20.na.sas.com>
To: "Shashikala Shamarao" <shashikala_shamarao@yahoo.com>, <xmlschema-dev@w3.org>
I was thinking of something like (off the top of my head -- syntax may be wrong):
 
<element name="Feature1" type="x1:Feature1"/> 

     

<complexType name="Feature1">

          <sequence>

               <element name="property1" type="x1:anyHotel" />

          </sequence>

</complexType>

     

<complexType name="anyHotel">

          <sequence>

               <any minOccurs="0" macOccurs="unbounded"/>

          </sequence>

</complexType>

 

<complexType name="hotel1">

     <restriction base="x1:anyHotel>

          <attribute name="name" type="string" fixed="H1"/>

          <attribute name="address1" type="string" fixed="A1"/>

     </restriction>

</complexType>

     

<complexType name="hotel2">

     <restriction base="x1:anyHotel>

          <attribute name="name" type="string" fixed="H2"/>

          <attribute name="address1" type="string" fixed="A2"/>

     </restriction>

</complexType>

...
alowing XML like:
 
<Feature1 xmlns:xsi="...">

     <property1 xsi:type="hotel1" name="H1" address1="A1"/>

     <property1 xsi:type="hotel2" name="H2" address1="A2"/>

</Feature1>

 
xan

________________________________

From: Shashikala Shamarao [mailto:shashikala_shamarao@yahoo.com] 
Sent: Wednesday, April 07, 2004 6:32 PM
To: Xan Gregg; xmlschema-dev@w3.org
Subject: RE: Multiple Types for an element


Thank you much for your response. But I don't think I understood quite well, if you could give me an example, it would be great.
 
Thanks,
Shashi
 
For your reference I am attaching the XSD
 
<element name="Feature1" type="x1:Feature1"/> 

     

     <complexType name="Feature1">

          <sequence>

               <element name="property1" type="x1:hotel1" />

          </sequence>

     </complexType>

     

     <complexType name="hotel1">

          <attribute name="name" type="string" fixed="H1"/>

          <attribute name="address1" type="string" fixed="A1"/>

     </complexType>

     

     <complexType name="hotel2">

          <attribute name="name" type="string" fixed="H2"/>

          <attribute name="address1" type="string" fixed="A2"/>

     </complexType>

 

which would give me an XML like below

 

<Feature1>

     <property1 name="H1" address1="A1"/>

</Feature1>

 

but if I want an XML like below:

 

<Feature1>

     <property1 name="H1" address1="A1"/>

     <property1 name="H2" address1="A2"/>

</Feature1>



Xan Gregg <Xan.Gregg@jmp.com> wrote:

	Your message came through a bit garbled, but I think what you are trying to do might be best done with either substitution groups or xsi:type.  With xsi:type, you would define:
	 
	type anyHotel
	type hotel1 derived from anyHotel
	type hotel2 derived from anyHotel
	element property1 of type anyHotel
	 
	then the instance would contain something like
	 
	<property1 xsi:type="hotel1" name="H1" address="A1"/>
	 
	xan

________________________________

	From: xmlschema-dev-request@w3.org [mailto:xmlschema-dev-request@w3.org] On Behalf Of Shashikala Shamarao
	Sent: Monday, March 29, 2004 8:19 PM
	To: xmlschema-dev@w3.org
	Subject: Multiple Types for an element
	
	

		Is there a way to define multiple types for an element?

		For example

		 ...

		but if I want an XML like below:

		 

		<Feature1>

		     <property1 name="H1" address1="A1"/>

		     <property1 name="H2" address1="A2"/>

		</Feature1>

		 

		How can I define XML Schema? Basically I want one property element to have hotel1 as type and other one as hotel2. Is there a way to do such things? If so could somebody please mail me a Schema which does that.

		 

________________________________

Do you Yahoo!?
Yahoo! Small Business $15K Web Design Giveaway <http://us.rd.yahoo.com/evt=23609/*http://promotions.yahoo.com/design_giveaway/static/index2.html>  - Enter today
Received on Thursday, 8 April 2004 13:05:03 UTC

This archive was generated by hypermail 2.3.1 : Wednesday, 5 February 2014 07:15:11 UTC