XSD all 和 XSD 序列之间的中间方式 [英] Middle way between XSD all and XSD sequence

查看:32
本文介绍了XSD all 和 XSD 序列之间的中间方式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在用 XSD 定义一个用户元素.对于此示例,用户具有姓名、电子邮件和一个或多个国籍.我试过了:

I'm defining a user element with XSD. For this example, a user has a name, email and one or more nationalities. I've tried:

<xs:all>
  <xs:element name="name" blabla />
  <xs:element name="email" blabla />
  <xs:element name="nationality" minOccurs="1" maxOccurs="unbounded" />
</xs:all>

但是,这是非法的.显然,全部"中的元素只能出现一次(或根本不出现).我可以通过将 All 更改为 Sequence 来解决这个问题,但是人们必须按照确切的顺序输入属性,而我实际上并不关心.

However, that is illegal. Apparently elements inside an "All" can only occur one time (or not at all). I could fix this by changing the All to a Sequence, but then people would have to enter the properties in the exact order, which I actually don't care about.

有这两者的组合吗?不是根据 http://www.w3schools.com/Schema/schema_complex_indicators.asp,但也许它是隐藏的(或者我没有经验的眼睛看不到它).

Is there a combination of these two available? Not according to http://www.w3schools.com/Schema/schema_complex_indicators.asp, but maybe it's hidden (or my inexperienced eyes don't see it).

凭直觉,我也试过:

<xs:all>
  <xs:element name="name" blabla />
  <xs:element name="email" blabla />
  <xs:sequence>
    <xs:element name="nationality" minOccurs="1" maxOccurs="unbounded" />
  </xs:sequence>
</xs:all>

但不幸的是,这是无效的.

But that's unfortunately invalid.

这是当前真实的 XSD 片段:

Here is the current, real, piece of XSD:

  <!-- user -->
  <xs:complexType name="user">
    <xs:sequence>
      <xs:element name="firstname" type="xs:string" minOccurs="1" maxOccurs="1" />
      <xs:element name="appendix" type="xs:string" minOccurs="0" maxOccurs="1" />
      <xs:element name="lastname" type="xs:string" minOccurs="1" maxOccurs="1" />
      <xs:element name="address" type="xs:string" minOccurs="1" maxOccurs="1" />
      <xs:element name="zipcode" type="xs:string" minOccurs="1" maxOccurs="1" />
      <xs:element name="city" type="xs:string" minOccurs="1" maxOccurs="1"/>
      <xs:element name="username" type="xs:string" minOccurs="1" maxOccurs="1"/>
      <xs:element name="email" type="xs:string" minOccurs="1" maxOccurs="1"/>
      <xs:element name="country" type="country" minOccurs="1" maxOccurs="1"/>
      <xs:element name="nationality" type="xs:string" minOccurs="1" maxOccurs="unbounded"/>
    </xs:sequence>
  </xs:complexType>

推荐答案

您的代码应该在 XSD 1.1 中有效.对于 XSD 1.0,您必须找到解决方法.

Your code should be valid in XSD 1.1. For XSD 1.0 you have to find a workaround.

这篇关于XSD all 和 XSD 序列之间的中间方式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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