XML Schema中mixed="true"和xs:extension的区别

7
这两者之间的实际差异是什么?
<xs:element name="A">
 <xs:complexType mixed="true">
  <xs:attribute name="att" type="xs:boolean"/>
 </xs:complexType>
</xs:element>

<xs:element name="B">
 <xs:complexType>
  <xs:simpleContent>
   <xs:extension base="xs:string">
    <xs:attribute name="att" type="xs:boolean"/>
   </xs:extension>
  </xs:simpleContent>
 </xs:complexType>
</xs:element>

请参考Michael Kay在此处的回答:http://stackoverflow.com/questions/12474018/what-is-the-meaning-of-xsmixed-without-elements/36043922#36043922 - james.garriss
1个回答

12
两者不同。您的第一个例子使用mixed="true",表示混合内容,即字符数据与子元素混合在一起。而您的第二个例子将元素内容限制为xs:string类型。两者都表明存在属性。
就您的例子而言,两者几乎相同。但是,如果您没有计划添加子元素,即不打算使用混合内容,则第二个版本更清晰。

1
即使在VS2010中,错误消息也是相同的:“元素'X'不能包含子元素'Y',因为父元素的内容模型仅为文本。” - Luiz Borges

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接