为什么这个complexType定义正确
问题描述:
正如我一直认为的,xs:restriction
用于限制某个simpleType或complexType,因此名称restriction
。但下面的xsd代码片段是正确的。看看Norwegian_customer
,country
用complexType覆盖,所以它被扩展,不受限制。它被重命名。 xs:restriction
想要提供什么?是xs:restriction
的超集xs:extension
?该片段在WebStorm
中进行了验证。为什么这个complexType定义正确
<xs:complexType name="customer">
<xs:sequence>
<xs:element name="firstname" type="xs:string"/>
<xs:element name="lastname" type="xs:string"/>
<xs:element name="country" type="xs:string"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="Norwegian_customer">
<xs:complexContent>
<xs:restriction base="customer">
<xs:sequence>
<xs:element name="firstname" type="xs:string"/>
<xs:element name="lastname" type="xs:string"/>
<xs:element name="country1">
<xs:complexType>
<xs:sequence>
<xs:element name="firstname" type="xs:string"/>
<xs:element name="lastname" type="xs:string"/>
<xs:element name="country" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:restriction>
</xs:complexContent>
</xs:complexType>
答
但XSD片断下面是正确的。
不,您的XSD代码片段不正确。 Norwegian_customer
不是customer
的有效限制,因为它不允许country
,只有country1
。限制基类型的内容模型的所有部分必须在派生类型中明确允许。
该片段在WebStorm中进行了验证。
如果Webstorm验证了这个XSD,那么它是不符合的。
见W3C XML Schema Part 1: Structures Second Edition,具体如下:
- Schema Component Constraint: Particle Derivation OK (All:All,Sequence:Sequence -- Recurse) #2
- Schema Component Constraint: Derivation Valid (Restriction, Complex) #5.4.2
注意如下的Xerces基于验证会告诉你:
[错误] try.xsd:13:45:rcase-Recurse.2:粒子之间没有完整的功能映射。
[错误] try.xsd:13:45:derivation-ok-restriction.5.4.2:类型为 'Norwegian_customer'的错误。该类型的粒子不是限制基质粒子的有效限制。