scorpion wrote:
I have a simple type like this:
<xs:simpleTyp e name="SizeType" >
<xs:restricti on base="xs:token" >
<xs:enumerati on value="small"/>
<xs:enumerati on value="medium"/>
<xs:enumerati on value="large"/>
<xs:enumerati on value="xlarge"/>
</xs:restriction>
</xs:simpleType>
Now, I need to have an id attribute to that, so I'm trying to make it a
complex type by extending to
<xs:complexTy pe name="SizeType" >
<xs:simpleConte nt>
<xs:extension base="xs:token" >
....
</xs:extension>
</xs:simpleConten t>
</xs:complexType>
Now, I'm stuck. How do I change that to a complex type, with the
enumeration
there? Better, is there a way to give an id to a simpleType, without
changing it
to a complexType, as the complexType is, er..., complex for such simple
thing?
As soon as you want an element to have an attribute you need a complex
type for it, you can only use a simple type if the element has only text
data as its content and no child elements and no attributes.
As for your example it is not quite clear what you want to have, if you
want to have an element with its content being of your SizeType and an
additional ID attribute then the schema is
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:simpleTyp e name="SizeType" >
<xs:restricti on base="xs:token" >
<xs:enumerati on value="small"/>
<xs:enumerati on value="medium"/>
<xs:enumerati on value="large"/>
<xs:enumerati on value="xlarge"/>
</xs:restriction>
</xs:simpleType>
<xs:complexTy pe name="SizeIdTyp e">
<xs:simpleConte nt>
<xs:extension base="SizeType" >
<xs:attribute name="id" type="xs:ID" />
</xs:extension>
</xs:simpleConten t>
</xs:complexType>
<xs:element name="size" type="SizeIdTyp e" />
</xs:schema>
and an example document is
<?xml version="1.0" encoding="UTF-8"?>
<size xmlns:xsi="http ://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespace SchemaLocation= "test20040424Xs d.xml"
id="theSize">me dium</size>
--
Martin Honnen
http://JavaScript.FAQTs.com/