【问题标题】:XSD type that is a list and has attributesXSD 类型是一个列表并具有属性
【发布时间】:2018-04-17 13:05:13
【问题描述】:

以下是我希望能够作为 XML 示例执行的操作的示例(注意 file 元素):

...
<run-list>
  <topic name="topic1"/>
  <topic name="topic2">
    <file number="2"/>
    <file number="3">
      /a/b/c /a/b/d /a/b/g/h/i
    </file>
  </topic>
</run-list>
...

run-list 元素可以包含任意数量的topic 元素。 topic 元素可能包含零个或多个 file 元素。 file 元素具有 number 属性(必需)并且可以包含零个或多个路径字符串(列表)。

我不知道如何定义架构类型以允许定义如上所述的file 元素。我需要file 元素具有number 属性,并且我希望能够指定路径值的可选列表。我已经能够为其他情况定义简单的列表类型,但它们没有任何属性。

我已经能够做一些与此类似的事情,但需要为路径定义另一种模式类型并将其实现为file 元素中的一个元素。所以我会有这样的东西:

...
<file number="3">
   <path>/a/b/c</path>
   <path>/a/b/d</path>
   <path>/a/b/g/h/i</path>
</file>
...

我想避免必须定义单独的架构类型和元素来指定给定 file 元素下的路径。

任何帮助将不胜感激。

【问题讨论】:

    标签: list xsd attributes


    【解决方案1】:

    我想我明白了。这是似乎可行的架构:

    <xs:complexType name="TestSpecification">
      <xs:sequence>
        <xs:element name="topic" type="TopicSpecification"
          minOccurs="1" maxOccurs="unbounded" />
      </xs:sequence>
    </xs:complexType>
    
    <xs:complexType name="TopicSpecification">
      <xs:sequence>
        <xs:element name="file" type="FileSpecification" minOccurs="0"
          maxOccurs="unbounded" />
      </xs:sequence>
      <xs:attribute name="name" type="xs:string" use="required" />
    </xs:complexType>
    
    <xs:complexType name="FileSpecification">
      <xs:simpleContent>
        <xs:extension base="EntityPathList">
          <xs:attribute name="number" type="xs:positiveInteger" use="required" />
        </xs:extension>
      </xs:simpleContent>
    </xs:complexType>
    
    <xs:simpleType name="EntityPathList">
      <xs:list itemType="xs:string" />
    </xs:simpleType>
    

    如果有人对此有任何潜在问题、如何改进或替代方案的建议,请随时发表评论。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-05-16
      • 2017-01-15
      • 1970-01-01
      • 2019-01-18
      • 2022-01-26
      • 2014-01-13
      • 2019-01-04
      • 1970-01-01
      相关资源
      最近更新 更多