Xml XSD:限制complexType中空元素的simpleContent

Xml XSD:限制complexType中空元素的simpleContent,xml,xsd,xsd-validation,Xml,Xsd,Xsd Validation,以下是空元素的定义: 那么,为什么它不能处理空元素呢?如果我尝试此模式: <?xml version="1.0" encoding="utf-8"?> <xs:schema elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xs:complexType name="processingHook"> <xs:simp

以下是空元素的定义:

那么,为什么它不能处理空元素呢?

如果我尝试此模式:

<?xml version="1.0" encoding="utf-8"?>
<xs:schema elementFormDefault="qualified"
    xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <xs:complexType name="processingHook">
        <xs:simpleContent>
            <xs:restriction base="xs:anyType">
            </xs:restriction>
        </xs:simpleContent>
    </xs:complexType>

    <xs:element name="callMyApp" type="processingHook" />
</xs:schema>

我从oXygen(可能直接来自Xerces)那里得到这个错误消息:

类型“processingHook”的复杂类型定义表示错误。当具有simpleContent的complexType限制具有混合内容和可空粒子的complexType时,则在
的子级中必须存在

来自Saxon 9.9的(更简单)错误消息:

test.xsd#6中简单类型的基类型不是简单类型

这里的Saxon错误消息可能过于简化了;但让我们看看规则是怎么说的:

在XML模式1.0第1部分的§343中,我们有:

模式表示约束:复杂类型定义表示OK

    ...all of the following must be true:

    2 If the <simpleContent> alternative is chosen, all of the following must be true:
    2.1 The type definition ·resolved· to by the ·actual value· of the base
 [attribute] must be one of the following:
    2.1.1 ...
    2.1.2 only if the <restriction> alternative is also chosen, a 
complex type definition whose {content type} is mixed and a particle 
which is ·emptiable·, as defined in Particle Emptiable (§3.9.6);
    2.1.3 ...
    2.2 If clause 2.1.2 above is satisfied, then there must be a 
<simpleType> among the [children] of <restriction>.
…以下所有条件都必须为真:
2如果选择了备选方案,则必须满足以下所有条件:
2.1类型定义由基础的实际值决定
[属性]必须是以下内容之一:
2.1.1 ...
2.1.2仅当选择了替代方案时
{content type}混合的复杂类型定义和粒子
可排空,如颗粒可排空(§3.9.6)中所定义;
2.1.3 ...
2.2如果满足上述第2.1.2条,则必须有
在…的[子女]中。
因此,Xerces错误消息(通常情况下)直接从规范中删除,并引用包含相关规则的条款编号(§2.2)

§2.1.2的意思是,可空且具有variety=“mixed”的复杂类型允许类似于
12.3

,因此具有
xs:decimal
的简单内容(CTSC)的复杂类型应视为有效限制,因为CTSC的每个实例也是它所限制的复杂类型的有效实例。但§2.2本质上是说,定义CTSC时,必须定义简单内容的类型。即使您想让简单内容成为任何字符串,也必须这样说

我怀疑其中一个原因是
xs:restriction
通常会定义一个或多个约束方面(例如
minInclusive
pattern
),约束方面的含义取决于您限制的简单类型。

如果我尝试此模式:

<?xml version="1.0" encoding="utf-8"?>
<xs:schema elementFormDefault="qualified"
    xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <xs:complexType name="processingHook">
        <xs:simpleContent>
            <xs:restriction base="xs:anyType">
            </xs:restriction>
        </xs:simpleContent>
    </xs:complexType>

    <xs:element name="callMyApp" type="processingHook" />
</xs:schema>

我从oXygen(可能直接来自Xerces)那里得到这个错误消息:

类型“processingHook”的复杂类型定义表示错误。当具有simpleContent的complexType限制具有混合内容和可空粒子的complexType时,则在
的子级中必须存在

来自Saxon 9.9的(更简单)错误消息:

test.xsd#6中简单类型的基类型不是简单类型

这里的Saxon错误消息可能过于简化了;但让我们看看规则是怎么说的:

在XML模式1.0第1部分的§343中,我们有:

模式表示约束:复杂类型定义表示OK

    ...all of the following must be true:

    2 If the <simpleContent> alternative is chosen, all of the following must be true:
    2.1 The type definition ·resolved· to by the ·actual value· of the base
 [attribute] must be one of the following:
    2.1.1 ...
    2.1.2 only if the <restriction> alternative is also chosen, a 
complex type definition whose {content type} is mixed and a particle 
which is ·emptiable·, as defined in Particle Emptiable (§3.9.6);
    2.1.3 ...
    2.2 If clause 2.1.2 above is satisfied, then there must be a 
<simpleType> among the [children] of <restriction>.
…以下所有条件都必须为真:
2如果选择了备选方案,则必须满足以下所有条件:
2.1类型定义由基础的实际值决定
[属性]必须是以下内容之一:
2.1.1 ...
2.1.2仅当选择了替代方案时
{content type}混合的复杂类型定义和粒子
可排空,如颗粒可排空(§3.9.6)中所定义;
2.1.3 ...
2.2如果满足上述第2.1.2条,则必须有
在…的[子女]中。
因此,Xerces错误消息(通常情况下)直接从规范中删除,并引用包含相关规则的条款编号(§2.2)

§2.1.2的意思是,可空且具有variety=“mixed”的复杂类型允许类似于
12.3

,因此具有
xs:decimal
的简单内容(CTSC)的复杂类型应视为有效限制,因为CTSC的每个实例也是它所限制的复杂类型的有效实例。但§2.2本质上是说,定义CTSC时,必须定义简单内容的类型。即使您想让简单内容成为任何字符串,也必须这样说


我怀疑其中一个原因是
xs:restriction
通常会定义一个或多个约束方面(例如
minInclusive
pattern
),约束方面的含义取决于您所限制的简单类型。

,我是否正确地理解了您:当使用
限制时,具有简单内容的复杂类型需要数据内容定义(即,一些简单类型),而具有复杂内容的复杂类型不需要内容模型的定义(如我在文章中的第一个代码片段所示)?对于简单类型和复杂类型,定义限制的方式完全不同。对于简单类型,您定义了面,这些面定义了基础类型之外的其他约束;对于复杂类型,您定义新的内容模型,它必须是旧内容模型的有效限制(子集)。空内容模型是允许空内容的任何内容模型的有效限制。换句话说,复杂类型的限制确实需要内容模型的定义,但如果你什么也不说,那么这就是空内容模型的有效定义。因此,我是否正确理解您的意思:当使用
限制时,复杂类型
    ...all of the following must be true:

    2 If the <simpleContent> alternative is chosen, all of the following must be true:
    2.1 The type definition ·resolved· to by the ·actual value· of the base
 [attribute] must be one of the following:
    2.1.1 ...
    2.1.2 only if the <restriction> alternative is also chosen, a 
complex type definition whose {content type} is mixed and a particle 
which is ·emptiable·, as defined in Particle Emptiable (§3.9.6);
    2.1.3 ...
    2.2 If clause 2.1.2 above is satisfied, then there must be a 
<simpleType> among the [children] of <restriction>.