【问题标题】:Is it possible to have an element in XSD Schema only in case of specific value for another element in schema?只有在模式中的另一个元素具有特定值的情况下,是否可以在 XSD 模式中拥有一个元素?
【发布时间】:2017-05-26 03:43:40
【问题描述】:

我的 XML Schema 看起来像 -

<element name="PurchaseOrderInformation">
    <complexType>
        <sequence>
            <element ref="pidx:PurchaseOrderNumber"/>
            <element ref="pidx:PurchaseOrderIssuedDate" minOccurs="0"/>
            <element ref="pidx:PurchaseOrderTypeCode" minOccurs="0"/>
            <element ref="pidx:ReleaseNumber" minOccurs="0"/>
            <element ref="pidx:SalesOrderNumber" minOccurs="0"/>
            <element ref="pidx:RevisionNumber" minOccurs="0"/>
        </sequence>
    </complexType>
</element>
<element name="PurchaseOrderIssuedDate" type="date"/>
<element name="PurchaseOrderLineItemNumber" type="string"/>

每当客户名称为“ABC”时,我需要在 PurchaseOrderInformation 复杂类型下有 PurchaseOrderLineItemNumber 元素。

有什么办法可以做到吗?

【问题讨论】:

    标签: xml xsd schema restrictions


    【解决方案1】:

    XSD 1.0

    在 XSD 1.0 中无法基于其他元素来约束元素的值。

    XSD 1.1

    XSD 1.1 具有允许约束根据每个文档的值而变化的断言。如果 XSD 1.1 不是一个选项(因为它不适用于 libxml、.NET 等),则必须在 XSD 之外执行此类检查。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-03-09
      • 2013-01-23
      • 1970-01-01
      • 2015-03-10
      • 1970-01-01
      相关资源
      最近更新 更多