How to define a constant in XSD

Is there a way to define a constant value and use this constant in a previous XSD? I have a generic value that I want to use for various maxXccurs attributes of xs: element attributes. Like constants in other languages, I want to make changes in one place if the value supporting MyConst ever changes.

<!-- Can I do this? -->
<ConstantValue id="MyConst" value="10"/>
...
<xs:element name="sandwich_meat" type="xs:string" minOccurs="0" maxOccurs="MyConst"/>
<xs:element name="sandwich_name" type="xs:string" minOccurs="0" maxOccurs="MyConst"/>
+3
source share
3 answers

No, it is not. However, you can define your own type with a fixed value in it somewhere on top of your XSD (put arguments) and use this type for elements.

+1
source

This is not possible with a simple schema, but maybe XML entities will do the trick?

+1

:

  <xs:simpleType name="AConstantHere">
    <xs:restriction base="xs:string">
      <xs:enumeration value="CONSTANT_VALUE_HERE"/>
    </xs:restriction>
  </xs:simpleType>

.

0

All Articles