如何解决XSD 架构:使元素 *List 可选
在一些 XML 配置方面确实需要您的帮助。我有一个像这样的架构:
<Root ...>
.
.
<xs:complexType name="GlobalDataType">
<xs:sequence>
<xs:element name="Other1ELement" minOccurs="0">
<xs:element name="MyELementList" minOccurs="0" maxOccurs="1">
<xs:complexType>
<xs:sequence>
<xs:element name="MyELement" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="Element1" type="T_Custom" minOccurs="0"/>
<xs:element name="Element2" type="T_Custom" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="Element1Visible" type="xs:boolean" default="true" minOccurs="0"/>
<xs:element name="Element2Visible" type="xs:boolean" default="true" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="Other2ELement" minOccurs="0">
</xs:sequence>
</xs:complexType>
.
.
对我来说一切正常,除了符合:name="MyELementList" minOccurs="0"
我的验证器抛出一个错误,该列表应该在提供的 .xml 文件中,例如 <MyELementList/>
,无论我为此元素设置了 minOccurs="0"
。对于嵌套元素,一切正常。
解决方法
一个复杂类型定义了一个内容模型,这就是你说一个特定元素是否是可选的。可选性是元素使用位置的属性,而不是元素本身的属性。因此 minOccurs 仅与在复杂类型中声明的元素相关 - 从技术上讲,它是元素粒子的属性,而不是元素声明的属性。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。