I want to use the following enumaration in multiple plac开发者_StackOverflow社区es, but as you can see now, it is tied to one complex type, how do I extract it out so I can define it once and use it in multiple places.
<xs:complexType name="MessageType">
<xs:sequence>
<xs:element name="Control" type="ControlType" minOccurs="1" maxOccurs="1" />
<xs:element name="LOS" type="LOSTYPE" minOccurs="0" maxOccurs="1" />
<xs:element name="UID" type="UIDTYPE" minOccurs="1" maxOccurs="1" />
<xs:element name="RS" type="RSTYPE" minOccurs="0" maxOccurs="1" />
</xs:sequence>
<xs:attribute name="BL" type="xs:string" use="optional"></xs:attribute>
<xs:attribute name="BLM" use="optional">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="One" />
<xs:enumeration value="Two"/>
<xs:enumeration value="Three"/>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
</xs:complexType>
Basically, I want to extract the BLM enumeration attribute out so I can define it once and use it multiple places if need so I don't have to repeat it. DRY in a nutshell :)
You can create a named xs:simpleType
out of it.
<xs:simpleType name="myEnum">
<xs:restriction base="xs:string">
<xs:enumeration value="One" />
<xs:enumeration value="Two"/>
<xs:enumeration value="Three"/>
</xs:restriction>
</xs:simpleType>
And then use it with
<xs:attribute name="BLM" use="optional" type="myEnum"/>
精彩评论