nevermind
nevermind

Reputation: 137

using restriction base in XML Schemas on attributes

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>

Upvotes: 0

Views: 981

Answers (1)

Tony Hopkinson
Tony Hopkinson

Reputation: 20320

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>

Upvotes: 1

Related Questions