[英]Restriction of xsd:list with enumeration
有沒有辦法用枚舉字符串限制xsd:list
? 在我的示例中,我希望ab
(或aab
、 ba
、..)有效,但abc
無效。 但是, ab
似乎也無效。
Xsd 架構:
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:element name="example">
<xsd:complexType>
<xsd:all>
<xsd:element name="stringList" type="restrictedStringList"/>
</xsd:all>
</xsd:complexType>
</xsd:element>
<xsd:simpleType name="restrictedStringList">
<xsd:restriction base="stringListType">
<xsd:enumeration value="a"/>
<xsd:enumeration value="b"/>
</xsd:restriction>
</xsd:simpleType>
<xsd:simpleType name="stringListType">
<xsd:list itemType="xsd:string"/>
</xsd:simpleType>
</xsd:schema>
XML 實例:
<?xml version="1.0" encoding="UTF-8"?>
<example xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="example.xsd">
<stringList>a b</stringList>
</example>
上面的例子驗證失敗:
值“ab”不在枚舉列表中。 它必須是以下之一:
- 一種
- b
我認為你需要例如
<xsd:simpleType name="enumerationList">
<xsd:restriction base="xsd:string">
<xsd:enumeration value="a"/>
<xsd:enumeration value="b"/>
</xsd:restriction>
</xsd:simpleType>
<xsd:simpleType name="stringListType">
<xsd:list itemType="enumerationList"/>
</xsd:simpleType>
<xsd:element name="stringList" type="stringListType"/>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.