【问题标题】:XSD Schema using maxOccurs and minOccurs in complextype在 complextype 中使用 maxOccurs 和 minOccurs 的 XSD 架构
【发布时间】:2011-11-04 15:38:43
【问题描述】:

我正在 Visual Studio 2010 中编写一个 XSD 架构文件。我想定义一个不需要的复杂类型,并且在 xml 中有无限的整体。我使用了 minOccurs 和 maxOccurs 属性,但在编辑器中出现错误,即不允许使用这些属性(minOccurs / maxOccurs)。我可以将它们添加到简单类型,但不能添加到复杂类型。如何定义一个复杂类型可以有 0 到多次出现?

这是我使用的 xsd:

<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="patient" minOccurs="0"  maxOccurs="unbounded">
    <xs:complexType>
      <xs:sequence>
        <xs:element name="to" type="xs:string"/>
        <xs:element name="from" type="xs:string"/>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
</xs:schema>

【问题讨论】:

    标签: xsd schema


    【解决方案1】:

    这应该仍然是有效的 XSD 语法。 VS 编辑器只是突出显示它并告诉您它是不允许的吗?它可能只是报告不正确。

    编辑:哦,你需要一个复杂类型的序列!

    <?xml version="1.0" encoding="utf-8"?>
    <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
      <xs:element name="patients">
        <xs:complexType>
          <xs:sequence>
            <xs:element name="patient" minOccurs="0"  maxOccurs="unbounded">
              <xs:complexType>
                <xs:sequence>
                  <xs:element name="to" type="xs:string"/>
                  <xs:element name="from" type="xs:string"/>
                </xs:sequence>
              </xs:complexType>
            </xs:elemennt>
          </xs:sequence>
        </xs:complexType>
      </xs:element>
    </xs:schema>
    

    【讨论】:

    • 我不明白您的编辑。 “您需要一系列复杂类型”是什么意思?我是 xsd 的新手。我为上面的复杂类型定义了一个序列。
    • 我实际上是匆匆浏览了我的示例代码。现在上面应该是正确的。您需要一个根节点 (patients),它是一个包含一系列 patient 元素的 complexType。就是这个序列可以出现 0 次或更多次。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-04-26
    • 1970-01-01
    • 2013-03-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多