How do you restrict an element in XSD?

Srinivas Ganaparthi
Srinivas Ganaparthi

Posted On: Feb 22, 2018

 

The restriction element in the XSD is used to define restrictions on the simpleType, simple content, or complex content definition.

//syntax
<xs:restriction base = "element-type"> restrictions </xs:restriction>

Here, the base defines the type of the element on which the restriction is to be applied. The restrictions are the range of conditions that is to be applied to the element.

//example
<xs:element name = "marks">
   <xs:simpleType>
      <xs:restriction base = "xs:integer">
         <xs:minInclusive value = "0"/>
         <xs:maxInclusive value = "100"/>
      </xs:restriction>
   </xs:simpleType>
</xs:element>

Now, we apply the restriction to the marks element. The restriction is that the value of the mark should be between 0 and 100.

    Related Questions

    Please Login or Register to leave a response.

    Related Questions

    XSD Interview Questions

    What is XSD?

    XSD (XML Schema Definition) is a language definition that defines how to describe the elements in the Extensible Markup Language (XML). This definition is a recommendation of the World Wide Web Consor...

    XSD Interview Questions

    Explain the benifits of using XSD?

    The advantages of using XSD over other schema languages are,XSD is extensible. That is, You can use XSD to derive new elements from the existing elements. XSD doesn&rsquo;t require intermediate p...

    XSD Interview Questions

    How attribute is different from a element in XSD?

    Element in XSD is nothing but an XML element such as opening tag, content, closing tag, etc. XSD Elements are the building blocks of your XML document. Elements are defined by their occurrence. An ele...