Page 1 of 1

using mixed="true" and trying to set a type

Posted: Fri Feb 13, 2009 10:33 pm
by ryanparrish
I may be going at this the entirely wrong way, so don't shy away from pointing out glaring mistakes :)

What I'm trying to get is an element that looks like this

Code: Select all

<Weight unit="lbs">12.5</Weight>
with the following schema...

Code: Select all


<element name="Weight">
<complexType mixed="true">
<attribute name="unit" use="required">
<simpleType>
<restriction base="xs:string">
<enumeration value="lbs"/>
<enumeration value="kgs"/>
</restriction>
</simpleType>
</attribute>
</complexType>
</element>
And that works fine and all except I would like to define a type (xs:decimal) to the <Weight> element so users of my schema cannot put in strings. However it appears to not be valid to set a type when I have mixed="true", so what am I to do?

Re: using mixed="true" and trying to set a type

Posted: Fri Feb 13, 2009 10:46 pm
by george
You need mixed to specify that you have elements and text. In that case you cannot put any other restriction on the text. However, in your case you do not have elements so you can just extend a complex type with simple content from decimal and add the attribute you need:

Code: Select all


    <xs:element name="Weight">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:decimal">
<xs:attribute name="unit" use="required">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="lbs"/>
<xs:enumeration value="kgs"/>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
Best Regards,
George

Re: using mixed="true" and trying to set a type

Posted: Fri Feb 13, 2009 11:06 pm
by ryanparrish
Thank you so much, that is exactly what I have been looking for for days now :D