Search code examples
xsdinfopath

XSD Choice with optional element


I have the following XSD template for the following:

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

But the result so far doesn't go as it supposes to be. Unexpected result

Here is my wanted result: Expected result

How could i archive the expected result ? Please advice me.

Please note that both and are optional in this case.


Solution

  • Currently your choice lets you pick between the NilReport element and the sequence with the other two elements.

    If you want to have the two other elements as children of the "sequence" you will have to create a containing element, and you need to define them as children of that element as follows.

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