如何为无序列表创建模式,其中一些出现一次,一些出现多次 [英] How to make a schema for an unordered list where some occur once, some many times

查看:29
本文介绍了如何为无序列表创建模式,其中一些出现一次,一些出现多次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是一个与 如何为带有出现约束的无序列 XML 节点列表创建模式,但实际上稍微简单一些.然而,我很难理解序列和选择背后的逻辑(尤其是当它们嵌套在选择序列或序列选择中时),尽管我已经研究了很长时间,但我无法理解上面的例子有效.

This is a similar question to How to create a schema for an unordered list of XML nodes, with occurrence constraints, but actually slightly simpler. However I am having great trouble understanding the logic behind sequences and choices (and especially when they are nested into sequences of choices or choices of sequences), and although I've studied it for a long time I can't understand how the example above works.

我需要的是节点列表 ChildA 和 ChildB 的模式,其中 ChildA 可以出现 0-n 次,但 ChildB 只能出现 0-1 次.(实际上我需要每种类型的几个节点,但是如果我可以为 ChildA 和 ChildB 做到这一点,那么将其扩展到 ChildX 等和 ChildY 等应该很简单).应该没有顺序限制.我很感激任何帮助.任何深入解释架构指标的链接也会有所帮助.

What I need is schema for a list of nodes, ChildA and ChildB, whereby ChildA can occur 0-n times, but ChildB only 0-1 times. (Actually I need several nodes of each type, but if I can do it for ChildA and ChildB, extending it to ChildX etc. and ChildY etc. should be simple). There should be no order constraint. I'd appreciate any help. Any links that explain schema indicators in depth would also be helpful.

推荐答案

这将是我很快想到的最简单的解决方案.这里的关键点是在主"序列中使用另一个序列.通过将内部序列设置为以 <ChildB> 开头和 保持可选,通过将该序列的基数设置为 0-1 来保持模式的确定性.

This would be the simplest solution that quickly came to my mind. The key point here is to use another sequence inside the "main" sequence. The schema is kept deterministic by setting the inner sequence to start with <ChildB> and <ChildB> is kept optional by setting the cardinality of that sequence to 0-1.

这是一个 XMLSchema 1.0 解决方案.

This is an XMLSchema 1.0 solution.

<xs:schema elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">

  <!-- Schema for elements ChildA and ChildB
      The requirements are as follows:
          * ChildA and ChildB may occur in any order.
          * ChildA is optional and may occur multiple times.
          * ChildB is optional and may occur once only.
  -->

  <xs:element name="root">
    <xs:complexType>
      <xs:sequence>
        <xs:element maxOccurs="unbounded" name="AB-container" type="AB-type" />
      </xs:sequence>
    </xs:complexType>
  </xs:element>

  <xs:complexType name="AB-type">
    <xs:sequence>
      <xs:element minOccurs="0" maxOccurs="unbounded" name="ChildA" type="xs:string" />
      <xs:sequence minOccurs="0">
        <xs:element name="ChildB" type="xs:string" />
        <xs:element minOccurs="0" maxOccurs="unbounded" name="ChildA" type="xs:string" />
      </xs:sequence>
    </xs:sequence>
  </xs:complexType>

</xs:schema>

这篇关于如何为无序列表创建模式,其中一些出现一次,一些出现多次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆