It is possible to restrict the values of an element in the XSD, using some specific restriction tags.

Below is a code snippet, which provides an example of how to restrict an attribute value in the xsd. This will lead to restrict the client application from setting up any other values to the restricted attribute.

<?xml version="1.0" encoding="UTF-8"?>

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://example.org/prod" elementFormDefault="qualified" targetNamespace="http://example.org/prod">

<xs:element name="transaction" type="TransactionType"/>

<xs:element fixed="10" name="size" type="xs:integer"/>

<xs:complexType name="TransactionType">

<xs:sequence>

<xs:element name="name">

<xs:simpleType>

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

<xs:minLength value="1"/>

<xs:enumeration value="type1"/>

<xs:enumeration value="type2"/>

<xs:enumeration value="type3"/>

</xs:restriction>

</xs:simpleType>

</xs:element>

<xs:element minOccurs="0" ref="size"/>

</xs:sequence>

</xs:complexType>

</xs:schema>




Sandeep Joshi
Mathematics, Technology and Programming are my passion. I am a part of Java Ecosystem and through this blog, I contribute to it. I am here to blog about my interests, views and experiences.
I am on Google+ and Facebook.
I feel proud to be listed as a "National Memory Record Holder" in the Limca Book of Records, 2009 and have attempted for an International Memory record in the Guiness Book of Records. I can remember the value of PI upto 10,000 digits after the decimal (3.1415.....). You can contact me on javagenious.com(At)gmal.com ; I would like to hear from you :)