Difference of mixed="true" and xs:extension in XML Schema
Asked Answered
H

1

7

What is the practical diference between these two:

<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>
Headstone answered 21/5, 2011 at 21:2 Comment(1)
See @Michael Kay's answer here: #12474518Anaesthesia
P
13

The two are different. Your first example uses mixed="true" which denotes mixed content, i.e. character data mixed in with child elements. Whereas your second example restricts the element content to the xs:string type. Both indicate the presence of an attribute.

With your example, both are practically the same. However, if you do not plan on having mixed content, i.e. you do not plan to add child elements, the second version is much clearer.

Palatial answered 21/5, 2011 at 21:9 Comment(1)
Even the error message is the same in VS2010: The element 'X' cannot contain child element 'Y' because the parent element's content model is text only.Headstone

© 2022 - 2024 — McMap. All rights reserved.