2

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"/>
ModdyFire
  • 706
  • 3
  • 9
  • 19
  • `A mixed complex type element can contain attributes, elements, and text.` [Source](http://www.w3schools.com/schema/schema_complex_mixed.asp) Could you post some examples of the XML? – user1424311 Sep 18 '12 at 14:50
  • Possible duplicate of [Difference of mixed="true" and xs:extension in XML Schema](http://stackoverflow.com/questions/6084431/difference-of-mixed-true-and-xsextension-in-xml-schema) – james.garriss Mar 16 '16 at 18:44

3 Answers3

5

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.

Michael Kay
  • 156,231
  • 11
  • 92
  • 164
  • "while using a mixed complex content type with no elements allows refinement by adding elements to the model" what does this mean? can u add an example maybe? Thanks. – hariszhr Nov 16 '16 at 21:02
2

The use of mixed with an empty content model is perfectly standard. If you don't like their content model, you'll need a different argument.

In general, mixed="true" means that character content is allowed among the child elements in a given complex type; in this case, since there are no child elements in the content model, the only legal content of the parent element will be character data, comments, and processing instructions. The upshot will be that the element declaration accepts the same set of elements as it would if the element were typed using a complex type with simple content declared as an extension of xs:string.

The choice between mixed-content and string is a design decision. In general, mixed content is better for natural-language prose, even if the initial design of an element does not foresee the need for sub-elements. In general, xs:string is easier to use if as the basis for restrictions of the set of expected values. (If you want to constrain the stateProvinceName to accept only the codes defined by particular postal services, xs:string is a better basis for your work than mixed content.)

C. M. Sperberg-McQueen
  • 24,596
  • 5
  • 38
  • 65
  • It's not about _liking_ their model. It's about suggesting a workaround until I fix this bug, which may take a while (and longer if they need to wait for next release) – ModdyFire Sep 18 '12 at 23:22
  • Sorry, you've lost me. The question you asked was what the declaration means. The question doesn't mention a bug or make clear what problem is to be worked around. Sorry if the phrase "if you don't like their model" rubbed you the wrong way; it was my attempt to paraphrase the view suggested in the original posting, that mixed content with an empty content model was in some way less standard than `xs:string`. It's not. Good luck fixing the bug, whatever it is. – C. M. Sperberg-McQueen Sep 20 '12 at 22:48
0

It means that you have an element named stateProvinceName that has one or more attributes (as defined by xml:attlist.global-attributes) whose content is a string. As is, it's no different from the structure that you recommended.

Their potential difference, however, is their extensibility, as @Michael Kay noted.

Community
  • 1
  • 1
james.garriss
  • 12,959
  • 7
  • 83
  • 96