在XSD中有空的complexType有效吗?

时间:2014-11-10 10:51:03

标签: xml xsd

我有一个我需要处理的XML模式,在其中间有这一行:

<xsd:complexType name="SomeName"/>

这是有效的XSD架构,还是complexType总是有某种内容(子元素,属性,什么)?

2 个答案:

答案 0 :(得分:2)

是的,它是有效的。

请参阅schema了解架构。

 <xs:complexType name="complexType" abstract="true">
  <xs:complexContent>
   <xs:extension base="xs:annotated">
    <xs:group ref="xs:complexTypeModel"/>
    <xs:attribute name="name" type="xs:NCName"/>
    <xs:attribute name="mixed" type="xs:boolean" use="optional" default="false"/>
    <xs:attribute name="abstract" type="xs:boolean" use="optional" default="false"/>
    <xs:attribute name="final" type="xs:derivationSet"/>
    <xs:attribute name="block" type="xs:derivationSet"/>
   </xs:extension>
  </xs:complexContent>
 </xs:complexType>

 <xs:group name="complexTypeModel">
  <xs:choice>
      <xs:element ref="xs:simpleContent"/>
      <xs:element ref="xs:complexContent"/>
      <xs:sequence>
       <xs:group ref="xs:typeDefParticle" minOccurs="0"/>
       <xs:group ref="xs:attrDecls"/>
      </xs:sequence>
  </xs:choice>
 </xs:group>

 <xs:group name="attrDecls">
  <xs:sequence>
   <xs:choice minOccurs="0" maxOccurs="unbounded">
    <xs:element name="attribute" type="xs:attribute"/>
    <xs:element name="attributeGroup" type="xs:attributeGroupRef"/>
   </xs:choice>
   <xs:element ref="xs:anyAttribute" minOccurs="0"/>
  </xs:sequence>
 </xs:group>

所以最小值是:

<xs:complexType name="someNCName"/>

您的问题就是这种情况。

答案 1 :(得分:1)

是的,这是一个非常有效的'空元素'。常用作“旗帜”。看看http://www.w3schools.com/schema/schema_complex_empty.asp。该示例包含具有属性的类型,但讨论有效。

[编辑 - 新网址] https://www.w3schools.com/xml/schema_complex_empty.asp

相关问题