1

我想在我的 XSD 文件中定义两个元素,它们可以多次“无限”出现,但它们必须总是一个接一个地出现。例子:

XML 文件:

<company/>
<address/>
<customer/>
<customerContact/>
<customer/>
<customerContact/>
<customer/>
<customerContact/>

现在的问题是,下面的 XSD 定义

<xs:element name="company" type="companyType"/>
<xs:element name="address" type="addressType"/>
<xs:element name="customer" type="customerType" maxOccurs="unbounded"/>
<xs:element name="customerContact" type="customerContactType" maxOccurs="unbounded"/>

仅使用 XML 文件,例如

<company/>
<address/>
<customer/>
<customer/>
<customer/>
<customerContact/>
<customerContact/>
<customerContact/>

customercustomerContact不交替。我有定义一个元素的想法,该元素表示customer customerContact并允许重复该元素。这将解决我的问题,但它也将允许其他不应被接受为有效的解决方案。

我认为干净的解决方案是让 XML 像

<company/>
<address/>
<customerEnvelope>
    <customer/>
    <customerContact/>
<customerEnvelope>
<customerEnvelope>
    <customer/>
    <customerContact/>
</customerEnvelope>

并重复customerEnvelope。不幸的是,我的客户已经提供了 XML 结构,因此我无法在此处进行更改。

是否可以使用 XSD 定义这种结构,还是需要使用上述解决方法?

4

1 回答 1

3
<xs:element name="company" type="companyType"/>
<xs:element name="address" type="addressType"/>
<xs:sequence maxOccurs="unbounded">
  <xs:element name="customer" type="customerType"/>
  <xs:element name="customerContact" type="customerContactType"/>
</xs:sequence>
于 2013-01-23T01:25:31.457 回答