簡體   English   中英

如何使用XSD在XML中定義交替元素

[英]How to define alternating elements in XML with XSD

我想在我的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/>

客戶客戶聯系不交替的地方。 我有想法定義一個說客戶 客戶聯系的元素,並允許重復該元素。 這樣可以解決我的問題,但它也會允許其他不應被視為有效的解決方案。

我認為干凈的解決方案就是擁有XML

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

並重復customerEnvelope 不幸的是,我的客戶已經提供了XML結構,因此我無法在此處進行更改。

是否可以使用XSD定義這種結構,還是需要使用上述解決方法?

<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>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM