如果 XSD 未指定 maxOccurs,XML 文档中的最大元素数是多少?

发布于 2024-12-22 09:04:10 字数 3113 浏览 1 评论 0原文

我有一个 XSD 架构,它定义文档中的多个元素。我希望成为集合的两组元素。一组元素定义如下:

<xsd:element name="Prospects" minOccurs="0">
<xsd:complexType>
  <xsd:sequence>
    <xsd:element name="ROW" minOccurs="0" maxOccurs="unbounded">
      <xsd:complexType>
        <xsd:sequence>
          <xsd:element name="ID" type="xdv:guidKey" nillable="false" />
          <xsd:element name="Name" minOccurs="0">
            <xsd:complexType>
              <xsd:simpleContent>
                <xsd:extension base="xdv:stringLen50">
                  <xsd:attribute name="origVal" type="xdv:stringLen50" use="optional" />
                </xsd:extension>
              </xsd:simpleContent>
            </xsd:complexType>
          </xsd:element>
          ... more stuff...
    </xsd:element>
  </xsd:sequence>
  <xsd:attribute name="name" type="xsd:string" use="required" fixed="Prospects" />
  <xsd:attribute name="alias" type="xsd:string" use="required" fixed="Prospects" />
  <xsd:attribute name="keys" type="xsd:string" use="required" fixed="ProposalID" />
  <xsd:attribute name="codeTableColVal" type="xdv:codeTableColVal" use="optional" />
</xsd:complexType>

另一组元素如下所示:

<xsd:element name="Employees" minOccurs="0" maxOccurs="1">
<xsd:complexType>
  <xsd:sequence>
    <xsd:element name="ROW">
      <xsd:complexType>
        <xsd:sequence>
          <xsd:element name="ID" type="xdv:guidKey" nillable="false" />
          <xsd:element name="Seq" type="xdv:guidKey" nillable="false" />
          <xsd:element name="CompanyName" minOccurs="0">
            <xsd:complexType>
              <xsd:simpleContent>
                <xsd:extension base="xdv:stringLen32">
                  <xsd:attribute name="origVal" type="xdv:stringLen32" use="optional" />
                </xsd:extension>
              </xsd:simpleContent>
            </xsd:complexType>
          </xsd:element>
          ... more stuff...
    </xsd:element>
  </xsd:sequence>
  <xsd:attribute name="name" type="xsd:string" use="required" fixed="Employees" />
  <xsd:attribute name="alias" type="xsd:string" use="required" fixed="Employees" />
  <xsd:attribute name="keys" type="xsd:string" use="required" fixed="OpportunityID,Seq" />
  <xsd:attribute name="codeTableColVal" type="xdv:codeTableColVal" use="optional" />
</xsd:complexType>

主要区别在于,前者为 Prospects 指定 minOccurs="0" 并且不出现最大值,然后为 ROW 定义 minOccurs=0 和 maxOccurs=unbounded。

对于后者,它为员工定义了 minOccurs=0 和 maxOccurs=1,而对于 ROW,它没有定义 minOccurs 或 maxOccurs。

当我运行实用程序 Xsd2Code 时,它会生成我的 C# 代码,对于 Prospects,它会创建一个带有 ROWs 集合(作为 List())的 Prospects 属性,但对于Employees,它会创建一个具有 ROW 属性的员工属性,而不是集合。

我的问题:这个的架构规则是什么?既然没有 在员工的 ROW 上定义的 maxOccurs 会计算该员工的最小值和最大值 父应用还是应该是一个集合?

我试图确定创建代码的实用程序是否错误或者 .xsd 文件是否错误。

I have an XSD schema that defines multiple elements in a document. Two sets of the elements I expect to be collections. One set of elements is defined like follow:

<xsd:element name="Prospects" minOccurs="0">
<xsd:complexType>
  <xsd:sequence>
    <xsd:element name="ROW" minOccurs="0" maxOccurs="unbounded">
      <xsd:complexType>
        <xsd:sequence>
          <xsd:element name="ID" type="xdv:guidKey" nillable="false" />
          <xsd:element name="Name" minOccurs="0">
            <xsd:complexType>
              <xsd:simpleContent>
                <xsd:extension base="xdv:stringLen50">
                  <xsd:attribute name="origVal" type="xdv:stringLen50" use="optional" />
                </xsd:extension>
              </xsd:simpleContent>
            </xsd:complexType>
          </xsd:element>
          ... more stuff...
    </xsd:element>
  </xsd:sequence>
  <xsd:attribute name="name" type="xsd:string" use="required" fixed="Prospects" />
  <xsd:attribute name="alias" type="xsd:string" use="required" fixed="Prospects" />
  <xsd:attribute name="keys" type="xsd:string" use="required" fixed="ProposalID" />
  <xsd:attribute name="codeTableColVal" type="xdv:codeTableColVal" use="optional" />
</xsd:complexType>

The other set of elements looks like this:

<xsd:element name="Employees" minOccurs="0" maxOccurs="1">
<xsd:complexType>
  <xsd:sequence>
    <xsd:element name="ROW">
      <xsd:complexType>
        <xsd:sequence>
          <xsd:element name="ID" type="xdv:guidKey" nillable="false" />
          <xsd:element name="Seq" type="xdv:guidKey" nillable="false" />
          <xsd:element name="CompanyName" minOccurs="0">
            <xsd:complexType>
              <xsd:simpleContent>
                <xsd:extension base="xdv:stringLen32">
                  <xsd:attribute name="origVal" type="xdv:stringLen32" use="optional" />
                </xsd:extension>
              </xsd:simpleContent>
            </xsd:complexType>
          </xsd:element>
          ... more stuff...
    </xsd:element>
  </xsd:sequence>
  <xsd:attribute name="name" type="xsd:string" use="required" fixed="Employees" />
  <xsd:attribute name="alias" type="xsd:string" use="required" fixed="Employees" />
  <xsd:attribute name="keys" type="xsd:string" use="required" fixed="OpportunityID,Seq" />
  <xsd:attribute name="codeTableColVal" type="xdv:codeTableColVal" use="optional" />
</xsd:complexType>

The primary difference being that the former specifies minOccurs="0" for Prospects and no max occurs, then for ROW it defins minOccurs=0 and maxOccurs=unbounded.

For the latter it defines minOccurs=0 and maxOccurs=1 for Employees and for the ROW it does not define a minOccurs or maxOccurs.

When I run the utility program, Xsd2Code, and it generates my C# code, for the Prospects, it creates a Prospects property with a ROWs collection (As a List()) but for the Employees it create an Employee property with a ROW property, not a collection.

My question: whats is the schema rule for this? Since there is no
maxOccurs defined on ROW for employee does the min and max for the
parent apply or should it be a collection?

I am trying to determine if the utility that is creating my code is wrong or if the .xsd file is wrong.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

套路撩心 2024-12-29 09:04:10

如果未指定 maxOccurs,则默认值与 maxOccurs = "1" 相同。

来自 XML 架构指示器

出现次数指示器用于定义元素出现的频率
发生。

注意:对于所有“订单”和“组”指标(任意、全部、选择、
序列、组名称和组引用)的默认值
maxOccurs 和 minOccurs 为 1。

The default if maxOccurs is not specified is the same as maxOccurs = "1".

From XML Schema Indicators.

Occurrence indicators are used to define how often an element can
occur.

Note: For all "Order" and "Group" indicators (any, all, choice,
sequence, group name, and group reference) the default value for
maxOccurs and minOccurs is 1.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文