2013-06-05 94 views
0

我試圖創建一個模式和所遇到的這個問題,但我發現在我的案件的解決方案應該工作(XSD - how to allow elements in any order any number of times?)不。XML方案:使用任意數量的元素複雜類型任意次數

<xsd:element name="foo"> 
<xsd:complexType> 
    <xsd:choice> 
      <xsd:element ref="p" maxOccurs="unbounded"/> *--element p is complex--* 
      <xsd:element ref="f" maxOccurs="unbounded"/> *--element f is complex--* 
      <xsd:element ref="summary"/> 
    </xsd:choice> 
     <xsd:attribute ref="type"/> 
</xsd:complexType> 
</xsd:element> 

以此來驗證下面的XML帶回錯誤「意外的子元素」:

<foo type="###"> 
    <p type="###"> 
     <pr date="##/##/##" amount="###"/> 
     <pr date="##/##/##" amount="###"/> 
    </p> 
    <f type="###"> 
     <fr date="##/##/##" factor="###"/> 
     <fr date="##/##/##" factor="###"/> 
    </f> 
    <p type="###"> 
     <pr date="##/##/##" amount="###"/> 
     <pr date="##/##/##" amount="###"/> 
    </p> 
    <f type="###"> 
     <fr date="##/##/##" factor="###"/> 
     <fr date="##/##/##" factor="###"/> 
    </f> 
    <summary> 
     <p_summary date="##/##/##" p="####" dis="###" ......./> 
     <p_summary date="##/##/##" p="####" dis="###" ......./> 
     <p_summary date="##/##/##" p="####" dis="###" ......./> 
    </summary> 
</foo> 

我還沒有列出的定義爲PF和總結,但它們都包含的maxOccurs =「無界「對它們各自的元件(FR,PR,p_summary)。

回答

1

這是< XSD:選擇>那一定是無界這裏。您正確的模式應該是這樣的:

<xsd:element name="foo"> 
<xsd:complexType> 
    <xsd:choice maxOccurs="unbounded"> 
     <xsd:element ref="p"/> 
     <xsd:element ref="f"/> 
     <xsd:element ref="summary"/> 
    </xsd:choice> 
    <xsd:attribute ref="type"/> 
</xsd:complexType> 
</xsd:element> 

每個元素(pfsummary)設置maxOccurs="unbounded"不會在這裏做任何區別。它只是讓你重複相同的元素很多次,但不與他人混用。

+0

謝謝ColdFusion的,那正是我想要的! – skipstar