Thursday, June 11, 2020

XSD - enumeration -Restrictions on a Set of Values of a element

Restrictions on a Set of Values
To limit the content of an XML element to a set of acceptable values, we would use the enumeration constraint.

The example below defines an element called "Color" with a restriction. The only acceptable values are: green, red, blue:

<?xml version="1.0" encoding="windows-1252" ?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://www.example.org"
            targetNamespace="http://www.example.org" elementFormDefault="qualified">
  <xsd:element name="SomeElement">
    <xsd:complexType>
      <xsd:sequence>
        <xsd:element name="Color" type="xsd:colorT"/>
        <xsd:element name="code" type="xsd:string"/>
      </xsd:sequence>
    </xsd:complexType>
  </xsd:element>
      <xsd:simpleType name="colorT">
      <xsd:restriction base="xsd:string">
        <xsd:enumeration value="green"/>
        <xsd:enumeration value="red"/>
        <xsd:enumeration value="blue"/>
      </xsd:restriction>
    </xsd:simpleType>
</xsd:schema>

No comments:

Post a Comment

Featured Post

11g to 12c OSB projects migration points

1. Export 11g OSB code and import in 12c Jdeveloper. Steps to import OSB project in Jdeveloper:   File⇾Import⇾Service Bus Resources⇾ Se...