<enumeration>
The
enumerationfacet limits a simple type to a set of distinct values. For example, we can use theenumerationfacet to define a new simple type calledUSState, derived fromstring, whose value must be one of the standard US state abbreviations:
<xsd:simpleType name="USState">
<xsd:restriction base="xsd:string">
<xsd:enumeration value="AK"/>
<xsd:enumeration value="AL"/>
<xsd:enumeration value="AR"/>
<!-- and so on ... -->
</xsd:restriction>
</xsd:simpleType>
We can use case objects to express these restrictions. Here’s what scalaxb generates:
trait USState
object USState {
def fromXML(seq: scala.xml.NodeSeq): USState = fromString(seq.text)
def fromString(value: String): USState = value match {
case "AK" => AK
case "AL" => AL
case "AR" => AR
case "DE" => DE
}
}
case object AK extends USState { override def toString = "AK" }
case object AL extends USState { override def toString = "AL" }
case object AR extends USState { override def toString = "AR" }