【问题标题】:XSD Choice with optional element带有可选元素的 XSD 选择
【发布时间】:2017-04-21 05:04:07
【问题描述】:

我有以下 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

如何归档预期结果?请给我建议。

请注意,在这种情况下, 和 都是可选的。

【问题讨论】:

    标签: xsd infopath


    【解决方案1】:

    目前,您可以在 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>
    

    【讨论】:

    • 嗨@ophychius,非常感谢您的回答。如果不创建包含元素,我们真的没有其他方法可以存档吗?
    • 这取决于您想要实现的目标,如果您想要一个可以包含 NilReport 或 PoolReport 和/或 AccountReport 元素组合的元素,而不是您当前的 xsd 是可以的。它不允许 NilReport 和其他 2 中的任何一个组合,同时允许 0-n AccountReports 后跟 0-n PoolReports 如果您希望将 Account- 和 PoolReport 组合在上述元素中,您需要在NilReport 和包含 Account- 和 PoolReport 元素的“NotNilReport”。也许试着解释一下你想要达到的目标?
    • 你上面的例子是完美的,但它不遵循它的默认模式。所以它正确的 xml 应该是:&lt;ftc:NotNilReport&gt;&lt;ftc:PoolReport&gt;&lt;ftc:DocSpec&gt;&lt;ftc:DocTypeIndic&gt;FATCA1&lt;/ftc:DocTypeIndic&gt;&lt;ftc:DocRefId&gt;XXXX&lt;/ftc:DocRefId&gt; &lt;ftc:CorrMessageRefId&gt;XXXX&lt;/ftc:CorrMessageRefId&gt; &lt;ftc:CorrDocRefId&gt;XXX&lt;/ftc:CorrDocRefId&gt;&lt;/ftc:DocSpec&gt;&lt;ftc:AccountCount&gt;3&lt;/ftc:AccountCount&gt;ftc:AccountPoolReportType&gt;FATCA201&lt;/ftc:AccountPoolReportType&gt; &lt;ftc:PoolBalance currCode="AED"&gt;33&lt;/ftc:PoolBalance&gt;&lt;/ftc:PoolReport&gt;&lt;/ftc:NotNilReport&gt; **without tag **
    • 你有没有这样做?
    • 您描述的内容根据您自己的架构是有效的。您能否尝试(作为您问题的一部分,而不是评论)描述您在使用 xml/xsd 时遇到的实际问题?您想描述或验证什么 xml 结构以及出了什么问题?
    猜你喜欢
    • 2019-05-29
    • 2019-07-15
    • 2013-02-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-08-10
    • 1970-01-01
    • 2021-05-19
    相关资源
    最近更新 更多