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

前端之家收集整理的这篇文章主要介绍了xml – 如何声明complexType只有一个子元素?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
使用 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的直接子元素.

猜你在找的XML相关文章