Golang Tutorials - Learn Go Programming with Easy Step-by-Step Guides

Explore comprehensive Golang tutorials for beginners and advanced programmers. Learn Go programming with easy-to-follow, step-by-step guides, examples, and practical tips to master Go language quickly.

Xsd Restrictions in XML

Xsd Restrictions in XML

? XSD Restrictions in XML Schema

Restrictions in XSD allow you to limit or constrain the values that an element or attribute can have. This is useful to enforce data validity rules like length, range, pattern, enumeration, etc.


? Common Restriction Types

RestrictionDescriptionExample
xs:minLengthMinimum length of stringMin 3 characters
xs:maxLengthMaximum length of stringMax 10 characters
xs:patternRegex pattern the value must matchOnly digits [0-9]+
xs:minInclusiveMinimum numeric value (inclusive)? 1
xs:maxInclusiveMaximum numeric value (inclusive)? 100
xs:enumerationAllowed fixed set of values"red", "green", "blue"
xs:totalDigitsMax number of digits in a numberMax 5 digits
xs:fractionDigitsMax number of digits after decimal pointMax 2 decimals

? Example: Restricting a String and Number

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">  <!-- Restricted string: length 3-10, pattern letters only -->  <xs:simpleType name="NameType">    <xs:restriction base="xs:string">      <xs:minLength value="3"/>      <xs:maxLength value="10"/>      <xs:pattern value="[A-Za-z]+"/>    </xs:restriction>  </xs:simpleType>  <!-- Restricted integer: between 1 and 100 -->  <xs:simpleType name="AgeType">    <xs:restriction base="xs:integer">      <xs:minInclusive value="1"/>      <xs:maxInclusive value="100"/>    </xs:restriction>  </xs:simpleType>  <xs:element name="person">    <xs:complexType>      <xs:sequence>        <xs:element name="name" type="NameType"/>        <xs:element name="age" type="AgeType"/>      </xs:sequence>    </xs:complexType>  </xs:element></xs:schema>

? Valid XML

<person>  <name>John</name>  <age>25</age></person>

? Invalid XML Examples

  • Name too short: <name>Jo</name>

  • Name contains numbers: <name>John123</name>

  • Age out of range: <age>150</age>


Would you like me to create a full XML + XSD sample with restrictions included?

Disclaimer for AI-Generated Content:
The content provided in these tutorials is generated using artificial intelligence and is intended for educational purposes only.
html
docker
php
kubernetes
golang
mysql
postgresql
mariaDB
sql