XSD restrictions - both string and numerical

V

voorth

I was wondering if it is possible to define an restricted attribute
such that the following forms are both valid:

<myElement value="hi"/> <!-- value should be "hi" or "lo" -->
<myElement value="100"/><!-- value should be between 50-150 -->
 
M

Martin Honnen

voorth said:
I was wondering if it is possible to define an restricted attribute
such that the following forms are both valid:

<myElement value="hi"/> <!-- value should be "hi" or "lo" -->
<myElement value="100"/><!-- value should be between 50-150 -->

You can define a union type of two simple types:

<xs:attribute name="value">
<xs:simpleType>
<xs:union>
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="hi"/>
<xs:enumeration value="lo"/>
</xs:restriction>
</xs:simpleType>
<xs:simpleType>
<xs:restriction base="xs:int">
<xs:minInclusive value="50"/>
<xs:maxInclusive value="100"/>
</xs:restriction>
</xs:simpleType>
</xs:union>
</xs:simpleType>
</xs:attribute>

See section "2.5.1.3 Union datatypes" in
<URL:http://www.w3.org/TR/xmlschema-2/#datatype-dichotomies>
 
U

usenet

I was wondering if it is possible to define an restricted attribute
such that the following forms are both valid:

<myElement value="hi"/> <!-- value should be "hi" or "lo" -->
<myElement value="100"/><!-- value should be between 50-150 -->

You can use XML schema xs:union construct to do this. Something along
the lines of:

<xs:attribute name="value">
<xs:simpleType>
<xs:union>
<xs:simpleType>
<xs:restriction base="xs:int">
<xs:minInclusive value="50"/>
<xs:maxInclusive value="150"/>
</xs:restriction>
</xs:simpleType>
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="hi"/>
</xs:restriction>
</xs:simpleType>
</xs:union>
</xs:simpleType>
</xs:attribute>

Although you probably don't want the string part as restricted as
this!

HTH,

Pete Cordell
Codalogic
Visit http://www.codalogic.com/lmx/ for XML C++ data binding
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top