xml元素枚举属性和xsd中的枚举值 [英] xml element enumerated attribute and enumerated value in xsd
问题描述
感兴趣的是以下 xml 子元素:
Of interest is the following xml child element:
<optInItem type='MARKETING_EMAILS'>NO</optInItem>
我想枚举属性type"的可能值(假设有 2 个可能的值)并枚举 optInItem 的文本值的可能值(值可以是 Yes | No).我从以下 xsd 开始,但不确定如何添加两个单独的枚举.
I'd like to enumerate possible values (assume 2 possible values) for attribute 'type' and enumerate possible values for the text value of optInItem (values could be Yes | No). I am starting with the following xsd but am not sure how to add in the two separate enumerations.
<xs:element name="optInItem" maxOccurs="2" minOccurs="2">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute type="xs:string" name="type" use="required"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
任何建议/指点将不胜感激.
Any suggestions/pointers would be appreciated.
谢谢
推荐答案
经过多次迭代,看起来以下方法奏效了:
After many iterations, it looks like the following does the trick:
<xs:element name="account">
<xs:complexType>
<xs:sequence>
<xs:element type="optInItemType" name="optInItem" maxOccurs="2" minOccurs="2">
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:complexType name="optInItemType">
<xs:simpleContent>
<xs:extension base="elementOptInItemType">
<xs:attribute name="type" type="attrOptInItemType"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
<xs:simpleType name="elementOptInItemType">
<xs:restriction base="xs:string">
<xs:enumeration value="YES"/>
<xs:enumeration value="NO"/>
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="attrOptInItemType">
<xs:restriction base="xs:string">
<xs:enumeration value="MARKETING_EMAILS"/>
<xs:enumeration value="UPDATE_NOTIFICATIONS"/>
</xs:restriction>
</xs:simpleType>
那比我想象的要复杂得多.简单的内容扩展基础允许用户定义类型,因此是拉动它的关键都在一起.
That was a more complicated than I thought it would be. The simpleContent extension base allowed a user defined type and thus was the key to pulling it all together.
这篇关于xml元素枚举属性和xsd中的枚举值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!