【问题标题】:XSD - restrict/redefine complexType with occurs 0XSD - 使用发生 0 限制/重新定义 complexType
【发布时间】:2011-03-18 11:23:51
【问题描述】:

我有一个 complexType 用户:

<xs:complexType name="User">
    <xs:all>
        <xs:element name="id" type="xs:positiveInteger" minOccurs="1" maxOccurs="1" />
        <xs:element name="email" type="email" minOccurs="1" maxOccurs="1" />
        <xs:element name="password" type="xs:string" minOccurs="1" maxOccurs="1" />
        <xs:element name="name" type="xs:string" minOccurs="1" maxOccurs="1" />
    </xs:all>
</xs:complexType>

我必须在元素 minOccurs 和 maxOccurs 上使用它。

例如,通过登录,我只需要包含电子邮件和密码元素的用户,因此我需要 maxOccurs=0 和 minOccurs=0 的任何其他元素(id、name)。

<Auth:login>
    <User>
        <email>my@email.net</email>
        <password>mypass</password>
    </User>
</Auth:login>

是否可以使用受限的复杂类型用户验证上述 XML?

【问题讨论】:

    标签: xml schema


    【解决方案1】:

    否:如果 R 的所有实例都是 B 的有效实例,则类型 R 只能限制类型 B。由于 B 要求 id 和 name 存在,因此要求它们(甚至允许它们不存在)的类型不是B的有效限制。

    【讨论】:

    • 好的,我明白了,有没有简单的方法来解决这个问题,或者我应该手动编写受限类(complexType)的每个字段(元素)? (我不需要冗余:S,它总是错误的来源。)
    【解决方案2】:

    可以使用断言(在 xsd 1.1 中),但我认为 php 只有 xsd 1.0 支持:S

    我找到了here 一些帮助。我可以将我的子元素分组,并连接实际需要的组。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-10-10
      • 1970-01-01
      • 2013-10-10
      • 2019-07-28
      • 2021-12-26
      • 1970-01-01
      相关资源
      最近更新 更多