Restrict Data Range

B

bogus1one

To all you XML experts, let's say I have the following in an XML doc:

<heading units="TRUE">55</heading>

I would like to develop a schema that will both provide for an
enumeration for the attribute and restrict the input to some range of
values. In the example above, I want the enumeration to be restricted
to TRUE and MAG. And, I want the valid values the text to be 0 through
359. I seem to be able to get one or the other but not both. This is
what I have currently:

<xs:element name="heading">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:unsignedShort">
<xs:attribute name="units" use="required">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="TRUE"/>
<xs:enumeration value="MAG"/>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>

It is my understanding that facets can only be applied to simple types
and that once you add an attribute to an element, it becomes a complex
type. So, how do you work around this?

Thanks for your help.
 
S

Stan Kitsis [MSFT]

<xs:simpleType name="tfType">

<xs:restriction base="xs:string">

<xs:enumeration value="TRUE"/>

<xs:enumeration value="MAG"/>

</xs:restriction>

</xs:simpleType>



<xs:simpleType name="myNumbers">

<xs:restriction base="xs:unsignedShort">

<xs:minInclusive value="0"/>

<xs:maxInclusive value="359"/>

</xs:restriction>

</xs:simpleType>



<xs:complexType name="headingType">

<xs:simpleContent>

<xs:extension base="myNumbers">

<xs:attribute name="units" type="tfType"/>

</xs:extension>

</xs:simpleContent>

</xs:complexType>



<xs:element name="heading" type="headingType"/>


--
Stan Kitsis
Program Manager, XML Technologies
Microsoft Corporation

This posting is provided "AS IS" with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm
 

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

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top