加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

xml – 如何声明complexType只有一个子元素?

发布时间:2020-12-16 23:00:42 所属栏目:百科 来源:网络整理
导读:使用 XML Schema声明complexType只有一个子元素时,以下三种方法都实现了目标: xs:complexType xs:sequence xs:element ref="somevalue"/ /xs:sequence /xs:comlexTypexs:complexType xs:choice xs:element ref="somevalue"/ /xs:choice /xs:comlexTypexs:co
使用 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的直接子元素.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读