I have an attribute that can have only two value.
What is it better to use?
Pattern?
<xsd:attribute name="sex">
<xsd:simpleType>
<xsd:restriction base="xsd:string">
<xsd:pattern value="male|female" />
</xsd:restriction>
</xsd:simpleType>
</xsd:attribute>
Or enumetation?
<xsd:attribute name="sex">
<xsd:simpleType>
<xsd:restriction base="xsd:string">
<xsd:enumeration value="male"></xsd:enumeration>
<xsd:enumeration value="female"></xsd:enumeration>
</xsd:restriction>
</xsd:simpleType>
</xsd:attribute>
If there is not difference, I will use pattern (one line less)
Both are legal XSD, neither seems likely to pose problems for any conforming or even partially conforming implementation of XSD simple types, and I expect it would take huge volumes of data and very precise measurement to detect any speed difference between them. So the question “which is better?” essentially amounts to the question “which one is going to be easier for those who read the schema to understand?”
That’s a question only you can answer.
For what it’s worth, I’ll observe that the formulation using enumeration makes it possible to provide documentation on the meaning or expected usage of each value; it’s probably for that reason that I normally use enumerations in cases like this. (The values “male” and “female” seem straightforward enough, but in some schemas an enumeration like this one would also need to include values for “unknown” and “declined-to-state”, and users may need guidance on when to use which value.)