使用
XML Schema声明complexType只有一个子元素时,以下三种方法都实现了目标:
<xs:complexType> <xs:sequence> <xs:element ref="somevalue"/> </xs:sequence> </xs:comlexType> <xs:complexType> <xs:choice> <xs:element ref="somevalue"/> </xs:choice> </xs:comlexType> <xs:complexType> <xs:all> <xs:element ref="somevalue"/> </xs:all> </xs:comlexType>
显然,序列,选择和所有对于单个元素都不是必需的,因为它们应该用于指示多个元素的顺序.是否有更简洁的方法来声明只有一个子元素的complexType? (即,以某种方式消除序列,全部或选择的使用.)
解决方法
只是消除xs:sequence,xs:choice或xs:all,不是一个选项:
<xs:complexType name="cType"> <xs:element name="e"/> </xs:complexType>
无效.
请参见XML Representation of Complex Type Definitions,其中complexType的内容模型定义如下:
(annotation?,(simpleContent | complexContent | ((group | all
| choice | sequence)?,((attribute | attributeGroup)*,
anyAttribute?))))
元素不是complexType的直接子元素.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。