Reputation: 141
I'm kind of confuse about the restriction tag. I understand it is usually use to limit/restrict the elements from the base. But I seems to be able to just add new elements to the base type also. Is this ok? It feels weird to do this or even allow this. Its like you can do extension and restriction using the restriction tag.
<xs:complexType name="Foo">
<xs:complexContent >
<xs:sequence>
<xs:element name="a" type="xs:string" />
<xs:element name="b" type="xs:integer" />
</xs:sequence>
</xs:complexContent>
</xs:complexType>
<xs:complexType name="Blah">
<xs:complexContent >
<xs:restriction base="Foo">
<xs:sequence>
<xs:element name="a" type="xs:string" />
<xs:element name="b" type="xs:integer" />
<xs:element name="c" type="xs:string" />
</xs:sequence>
</xs:restriction>
</xs:complexContent>
</xs:complexType>
my validation says its ok but still feels wrong.
Upvotes: 1
Views: 41
Reputation: 163385
Well for starters, your Foo type is incorrect because xs:sequence
isn't allowed as a child of xs:complexContent
. When I correct that (by removing the xs:complexContent
element), I get "The content model of the complex type Q{}Blah is not a valid restriction of the content model of the type Q{}Foo. The restricted type allows element c where the base type does not"
This is from Saxon running within Oxygen. You haven't said what validator you're using, but it's not doing a very good job.
A restriction is a valid restriction if any element that's valid under the restricted type is also a valid instance of the base type; if the restricted type would allow things that the base type doesn't allow, then it's invalid.
Upvotes: 1