Re: Attribute type in XMLSchema

Hi. I found out that my problem is a bit more complicated than this. I
want(if possible) to create attributes that will take as a value in the
xml file an actual xml schema datatype. Check out this xml instance:

<param name="lala" type="xs:string">stamatis</param>
<param name="lala2" type="xs:int">0</param>

Not only the attribute type must be of xml schema type but the element's
value must be of the same type so for the xml file to be valid. Is this
feasible?The only thoughts I am heaving is to declare it somehow like
this:
xsd file
--------

<xs:simpleType name="XSDTypes">
	<xs:union memberTypes="xs:float xs:int xs:string"/>
</xs:simpleType>

<xs:attributeGroup name="paramAttributes">
	<xs:attribute name="name" type="xs:string" use="required"/>
	<xs:attribute name="type" type="XSDTypes" use="required"/>
</xs:attributeGroup>

<xs:element name="param">
	<xs:complexType>
		<xs:simpleContent>
			<xs:extension base="XSDTypes">
				<xs:attributeGroup ref="paramAttributes"/>
			</xs:extension>
		</xs:simpleContent>
	</xs:complexType>
</xs:element>

Thanx!
Stamatis

On Fri, 27 Jun 2003, Jeni Tennison wrote:

>
> Hi Stamatis,
>
> > Hello. I am a beginner in XML Schema and I have a question. I want
> > to set an attribute to be of type either xsd:string or xsd:int
> > or...or...e.t.c Can I use somehow the Choice indicator in the
> > attribute declaration?
>
> You can create a union type of all the types that you want to allow.
> Note that you should arrange the member types in an order so that the
> most specific type is first -- if you put xs:string first then all the
> attributes will be counted as being strings because all attribute
> values are in the lexical space of xs:string.
>
> Try:
>
> <xs:attribute name="foo" type="manyTypes" />
>
> <xs:simpleType name="manyTypes">
>   <xs:union memberTypes="xs:int xs:string" />
> </xs:simpleType>
>
> Cheers,
>
> Jeni
>
> ---
> Jeni Tennison
> http://www.jenitennison.com/
>
>

Received on Tuesday, 1 July 2003 05:08:44 UTC