不确定性内容模型

适用于:SQL Server Azure SQL 数据库 Azure SQL 托管实例

如果匹配项约束为 0、1 或不受限制,则 SQL Server 中会接受非确定性内容模型。

在 SQL Server 2005 (9.x) Service Pack 1 (SP1) 之前,SQL Server 会拒绝包含非确定性内容模型的 XML 架构。

示例:拒绝的不确定性内容模型

下面的示例尝试创建具有不确定的内容模型的 XML 架构。 此代码会运行失败,因为不清楚 <root> 元素应有一个包含两个 <a> 元素的序列,还是 <root> 元素应有两个序列,其中每个序列有一个 <a> 元素。

CREATE XML SCHEMA COLLECTION MyCollection AS '
<schema xmlns="http://www.w3.org/2001/XMLSchema">
    <element name="root">
        <complexType>
            <sequence minOccurs="1" maxOccurs="2">
                <element name="a" type="string" minOccurs="1" maxOccurs="2"/>
            </sequence>
        </complexType>
    </element>
</schema>
';
GO

可以通过将匹配项约束移动到一个唯一的位置来修复此架构。 例如,可以将此约束移动到包含序列粒子:

<sequence minOccurs="1" maxOccurs="4">
    <element name="a" type="string" minOccurs="1" maxOccurs="1"/>
</sequence>

也可以将此约束移动到被包含元素:

<sequence minOccurs="1" maxOccurs="1">
     <element name="a" type="string" minOccurs="1" maxOccurs="4"/>
</sequence>

示例:接受的不确定性内容模型

SQL Server 2005 (9.x) SP1 之前的 SQL Server 版本会拒绝以下架构。

CREATE XML SCHEMA COLLECTION MyCollection AS '
<schema xmlns="http://www.w3.org/2001/XMLSchema">
    <element name="root">
        <complexType>
            <sequence minOccurs="0" maxOccurs="unbounded">
                <element name="a" type="string" minOccurs="0" maxOccurs="1"/>
                <element name="b" type="string" minOccurs="1" maxOccurs="unbounded"/>
            </sequence>
        </complexType>
    </element>
</schema>
';
GO

另请参阅