Search code examples
xmlxsdmixed

What is the meaning of xs:mixed without elements?


I got the following XSD bit from a customer. It is part of a legacy schema that spans over dozens of files.

<xs:element name="stateProvinceName">
  <xs:complexType mixed="true">
    <xs:attributeGroup ref="xml:attlist.global-attributes"/>
  </xs:complexType>
</xs:element>

I'm trying to figure out what they actually want. There are no sub-elements, so what is the meaning of this 'xs:mixed'? is it supposed to be simpleContent, or no content?

I told them that they should use more standard construct, e.g.

<xs:element name="stateProvinceName">
  <xs:complexType>
    <xs:simpleContent>
       <xs:extension base="xs:string">
         <xs:attributeGroup ref="xml:attlist.global-attributes"/>
       </xs:extension>
     </xs:simpleContent>
  </xs:complexType>
</xs:element>

But they are not sure it means the same thing. Both schemas accept

<stateProvinceName ID="345643">California</stateProvinceName>

and

<stateProvinceName ID="345643"/>

Solution

  • The two types might be equivalent on the surface, but their extensibility is different. Using a simple content type of xs:string allows refinement of the type by constraining the string for example with a regular expression, while using a mixed complex content type with no elements allows refinement by adding elements to the model.