2017-04-21 146 views
0

我有以下以下XSD模板:XSD選擇可選元素

<xsd:choice>        
<xsd:element name="NilReport" type="ftc:CorrectableNilReport_Type"> 
    <xsd:annotation> 
     <xsd:documentation xml:lang="en">Nil Report indicates that financial institution does not have accounts to report</xsd:documentation> 
    </xsd:annotation> 
</xsd:element>       
<xsd:sequence >   
    <xsd:element name="AccountReport" type="ftc:CorrectableAccountReport_Type" minOccurs="0" maxOccurs="unbounded"> 
     <xsd:annotation> 
      <xsd:documentation>Detailed information for account report, such as account number and account balance</xsd:documentation> 
     </xsd:annotation> 
    </xsd:element> 
    <xsd:element name="PoolReport" type="ftc:CorrectablePoolReport_Type" minOccurs="0" maxOccurs="unbounded"> 
     <xsd:annotation> 
      <xsd:documentation>Information about the pool of account holders with similar characteristics</xsd:documentation> 
     </xsd:annotation> 
    </xsd:element>   
</xsd:sequence>    

但結果至今沒有去,因爲它假設是。 Unexpected result

這是我想要的結果: Expected result

我怎麼能存檔預期的結果?請指教我。

請注意,在這種情況下,兩者都是可選的。

回答

0

當前,您可以選擇使用其他兩個元素在NilReport元素和序列之間進行選擇。

如果您希望將其他兩個元素作爲「序列」的子元素,則必須創建一個包含元素,並且您需要將它們定義爲該元素的子元素,如下所示。

<xsd:choice> 
     <xsd:element name="NilReport" type="ftc:CorrectableNilReport_Type"> 
      <xsd:annotation> 
       <xsd:documentation xml:lang="en">Nil Report indicates 
        that financial institution does not have accounts to report</xsd:documentation> 
      </xsd:annotation> 
     </xsd:element> 
     <xsd:element name="NotNilReport"> 
      <xsd:complexType> 
       <xsd:sequence> 
        <xsd:element name="AccountReport" type="ftc:CorrectableAccountReport_Type" 
         minOccurs="0" maxOccurs="unbounded"> 
         <xsd:annotation> 
          <xsd:documentation>Detailed information for account report, such 
           as account number and account balance</xsd:documentation> 
         </xsd:annotation> 
        </xsd:element> 
        <xsd:element name="PoolReport" type="ftc:CorrectablePoolReport_Type" 
         minOccurs="0" maxOccurs="unbounded"> 
         <xsd:annotation> 
          <xsd:documentation>Information about the pool of account holders 
           with similar characteristics</xsd:documentation> 
         </xsd:annotation> 
        </xsd:element> 
       </xsd:sequence> 
      </xsd:complexType> 
     </xsd:element> 
    </xsd:choice> 
+0

嗨@ophychius,我會很感激你的答案。如果不創建包含元素,我們是否真的沒有其他方法來存檔? –

+0

這取決於你想要達到什麼目標,如果你想要一個可以包含NilReport或者PoolReport和/或AccountReport元素組合的元素,而不是你當前的xsd是可以的。它不允許組合NilReport和其他2個組合,同時允許0-n AccountReports和0-n PoolReports 如果您希望Account-和PoolReport在上述元素中組合在一起,您需要一個在NilReport和包含Account-和PoolReport元素的'NotNilReport'之間進行選擇。 也許試着解釋你想要達到的目標? – ophychius

+0

你上面的例子是完美的,但它不遵循其默認模式。所以它正確的xml應該是: FATCA1 XXXX \t XXXX \t \t \t XXX 3 ftc:AccountPoolReportType> FATCA201 33 **沒有標記** –