What is the meaning of xs:mixed without elements?
Asked Answered
R

3

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"/>
Relativistic answered 18/9, 2012 at 9:22 Comment(2)
A mixed complex type element can contain attributes, elements, and text. Source Could you post some examples of the XML?Toffeenosed
Possible duplicate of Difference of mixed="true" and xs:extension in XML SchemaHypercritical
E
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.

Eradis answered 18/9, 2012 at 20:56 Comment(1)
"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.Bram
L
3

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.)

Latham answered 18/9, 2012 at 16:54 Comment(2)
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)Relativistic
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.Latham
H
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.

Hypercritical answered 16/3, 2016 at 18:20 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.