XML 架构 - 允许某些元素多次出现并要求其他元素出现
XML Schema - Allow multiple occurrences of some elements and require others
在 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>
在 XSD 1.1 中,您可以使用 xs:all.
允许任何顺序并定义基数约束
在XSD 1.0中,如果你想限制出现的次数,那么你也必须限制顺序。
在 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>
在 XSD 1.1 中,您可以使用 xs:all.
允许任何顺序并定义基数约束在XSD 1.0中,如果你想限制出现的次数,那么你也必须限制顺序。