Click here to Skip to main content
15,892,674 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
XML
<applicationstatus code="2" />


I want to validate it using enumeration to Restrict a Set of Values(1 or 2 or 3)
code value may be 1 or 2 or 3

where code is attribute of element ApplicationStatus


Please help its urgent...
Posted
Updated 3-Feb-14 23:17pm
v9

1 solution

You can create your own type, like so:

XML
<xs:simpleType name="rangedInt">
    <xs:restriction base="xs:integer">
        <xs:minInclusive value="1" />
        <xs:maxInclusive value="3" />
    </xs:restriction>
</xs:simpleType>


And then use it like this
XML
<xs:attribute name="code" type="rangedInt" />


See also W3Schools[^]

This will create an integer type that allows the values 1, 2 and 3.
The type of your attribute should then be rangedInt, instead of a regular integer like it is now (probably).
 
Share this answer
 
v3
Comments
Maarten Kools 4-Feb-14 5:19am    
CodeProject messed up the paste, that wasn't supposed to be in there.
Maarten Kools 4-Feb-14 5:39am    
Just click on the link, it has various examples, including enumerations.
Maarten Kools 4-Feb-14 5:49am    
Now it is, sorry about that. The element tag shouldn't have been around it.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900