Is it possible to specify a list length on an anonymous type?

xsd

Solution

The base type is a xs:restriction on xs:float.

<xs:simpleType name="ptype">
  <xs:restriction base="xs:float">
    <xs:minInclusive value="0.0" />
    <xs:maxInclusive value="2.0" />
  </xs:restriction>
</xs:simpleType>

This is wrapped in an xs:list.

<xs:simpleType name="ltype">
  <xs:list itemType="ptype"/>
</xs:simpleType>

Next, place a length restriction on the list.

<xs:simpleType name="rtype">
  <xs:restriction base="ltype">
    <xs:length value="10"/>
  </xs:restriction>
</xs:simpleType>

Finally, the element, with the default values

<xs:element name="pressure"
    default="0.22 0.33 0.44 0.55 0.66 0.77 0.88 0.88 0.88 0.88">
  <xs:simpleType>
    <xs:restriction base="rtype"/>
  </xs:simpleType>
</xs:element>

TO get the fully anonymous element, start at the top, and nest each construct into the next lower construct which references it. Finally, ended up with this;

<xs:element name="pressure"
        default="0.22 0.33 0.44 0.55 0.66 0.77 0.88 0.88 0.88 0.88">
  <xs:simpleType>
    <xs:restriction>
      <xs:simpleType>
        <xs:list>
          <xs:simpleType>
            <xs:restriction base="xs:float">
               <xs:minInclusive value="0.0" />
               <xs:maxInclusive value="2.0" />
            </xs:restriction>
          </xs:simpleType>
        </xs:list>
      </xs:simpleType>
      <xs:length value="10"/>
    </xs:restriction>
  </xs:simpleType>
</xs:element>

Problem

I am converting an older data set to schema/xml. It contains a few elements that are arrays with default values. I am close to a solution with xs:list; ``` <xs:element name="pressure" default="0.22 0.33 0.44 0.55 0.66 0.77 0.88 0.88 0.88 0.88"> <xs:simpleType> <xs:list> <xs:simpleType> <xs:restriction base="xs:float"> <xs:minInclusive value="0.0" /> <xs:maxInclusive value="2.0" /> </xs:restriction> </xs:simpleType> </xs:list> </xs:simpleType> </xs:element> ``` How can i limit the length of the list to 10? I.e., where in this would I put the ``` <xs:length value="10">? ```

Original source