【发布时间】:2021-03-21 10:27:50
【问题描述】:
在一个 xml 文档中(我不能更改)我有这样的结构:
<rootMeta> // all children can occur in any order
<requiredExample1 value="someValue" /> // Should only be allowed to occur once. REQUIRED
<nonRequiredExample2 value="someValue" /> // Should only be allowed to occur once. NOT REQUIRED
<nonRequiredExample3 value="someValue" /> // All these are NOT REQUIRED but can occur many times.
<nonRequiredExample3 value="someValue" />
<nonRequiredExample3 value="someValue" />
</rootMeta>
我尝试了“全部”和“选择”,但还没有找到一种方法来满足所有强制要求(第一次尝试构建模式)。我试图寻找重复的问题,但只能找到需要我更改 xml 的解决方案。我当前的迭代如下所示:
<xs:element name="rootMeta">
<xs:complexType>
<xs:choice maxOccurs="unbounded">
<xs:element name="requiredExample1" minOccurs="1" maxOccurs="1">
<xs:complexType>
<xs:attribute name="value" type="xs:string" use="required" />
</xs:complexType>
</xs:element>
<xs:element name="nonRequiredExample2" maxOccurs="1">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:maxLength value="200" />
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="nonRequiredExample3">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:maxLength value="200" />
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:choice>
<xs:complexType>
</xs:element>
【问题讨论】: