1

混合复杂类型元素在其子元素之间也可以有文本。孩子们是否也继承了这种混合特征?换句话说,如果孩子不是混合类型,他们的孩子之间也可以有文字吗?

4

1 回答 1

1

不,mixed不被子元素继承。

鉴于此 XSD:

<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="root">
    <xs:complexType mixed="true">
      <xs:sequence>
        <xs:element name="child" minOccurs="0" maxOccurs="unbounded">
          <xs:complexType>
            <xs:sequence>
              <xs:element name="grandchild" minOccurs="0" maxOccurs="unbounded">
              </xs:element>
            </xs:sequence>
          </xs:complexType>
        </xs:element>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
</xs:schema>

此 XML 文档实例:

<root>
  text1
  <child>
    text2
    <grandchild/>
  </child>
</root>

将无效,因为 的mixed内容模型root未传递给 的内容模型child

验证解析器会发出如下错误:

元素 'child' 不能有字符 [children],因为该类型的内容类型是仅元素。

另请参阅类似但不同的问题扩展 complexType 时是否混合继承?

于 2014-01-10T19:37:43.257 回答