Question

I need to put a restriction onto an attribute of "yes or no" - but not too sure of how to structure it - I'm trying the below but not sure how right or wrong it is: (advice would be appreciated) thanks

<xs:element name="DistinctiveMarks">
  <xs:ComplexType>
    <xs:SimpleContent>
      <xs:extension base="xs:string">
        <xs:attribute name="present" type="xs:string">
          <xs:restriction base="xs:string">
            <xs:pattern value="yes|no"/>
          </xs:restriction>
        </xs:attribute>
      </xs:extension>
    </xs:SimpleContent>
  </xs:ComplexType>
</xs:element>
Was it helpful?

Solution

That should work. If you are going to reuse it though, another optionn is to declare a simple type. Then you can just do type = MY_YesNoType, include the namespace prefix if you have one. Another option that might suit is using an enumeration. Nice if you want to mine then xsd to build up an option list for data entry, instead of validating against a regex.

  <xs:simpleType name="MY_YesNoType">
    <xs:restriction base="xs:string">
      <xs:enumeration value="no" />
      <xs:enumeration value="yes" />
    </xs:restriction>
  </xs:simpleType>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top