是否可以在匿名类型上指定列表长度?

CAB*_*CAB 2 xsd

我正在将旧数据集转换为schema/xml.它包含一些具有默认值的数组元素.我接近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>
Run Code Online (Sandbox Code Playgroud)

如何将列表的长度限制为10?也就是说,我会把它放在哪里

    <xs:length value="10">?
Run Code Online (Sandbox Code Playgroud)

CAB*_*CAB 7

基类型是对xs:float的xs:restriction.

<xs:simpleType name="ptype">
  <xs:restriction base="xs:float">
    <xs:minInclusive value="0.0" />
    <xs:maxInclusive value="2.0" />
  </xs:restriction>
</xs:simpleType>
Run Code Online (Sandbox Code Playgroud)

这包含在xs:列表中.

<xs:simpleType name="ltype">
  <xs:list itemType="ptype"/>
</xs:simpleType>
Run Code Online (Sandbox Code Playgroud)

接下来,在列表上放置长度限制.

<xs:simpleType name="rtype">
  <xs:restriction base="ltype">
    <xs:length value="10"/>
  </xs:restriction>
</xs:simpleType>
Run Code Online (Sandbox Code Playgroud)

最后,元素具有默认值

<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>
Run Code Online (Sandbox Code Playgroud)

要获取完全匿名元素,请从顶部开始,并将每个构造嵌套到引用它的下一个较低构造中.最后,结束了这个;

<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>
Run Code Online (Sandbox Code Playgroud)