[xsd-users] XSD : How to set attributes values in children
element type?
Boris Kolpackov
boris at codesynthesis.com
Tue Nov 23 14:51:47 EST 2010
Hi Klaim,
Klaim <mjklaim at gmail.com> writes:
> In an xsd file I have this element base type :
>
> <xs:complexType name="event" abstract="true" >
> <xs:attribute name="move" type="aos:move_ref" use="required" />
> <xs:attribute name="type" type="aos:event_type" use="required" />
> </xs:complexType>
>
> And I want to define the value of the type attribute in the children types,
> so I tried this :
>
> <xs:complexType name="signal" >
> <xs:complexContent>
> <xs:extension base="aos:event">
> <xs:attribute name="type" type="aos:event_type" fixed="signal" />
> <xs:attribute name="source" type="aos:signal_source" use="required" />
> </xs:extension>
> </xs:complexContent>
> </xs:complexType>
>
> Visual Studio don't seem to bother but CodeSynthesis C++ code
> generatordon't seem to agree :
>
> error: attribute 'type' is already defined in base
I am pretty sure CodeSynthesis XSD is correct here -- you cannot "extend"
a type to have the same attribute as is already defined in the base.
> How should I write this? I just want the value of the type attribute to be
> specific to each different child type.
What you will need is a restriction step:
<xs:complexType name="signal_base" abstract="true">
<xs:complexContent>
<xs:restriction base="aos:event">
<xs:attribute name="move" type="aos:move_ref" use="required" />
<xs:attribute name="type" type="aos:event_type" fixed="signal" />
</xs:restriction>
</xs:complexContent>
</xs:complexType>
<xs:complexType name="signal">
<xs:complexContent>
<xs:extension base="aos:signal_base">
<xs:attribute name="source" type="aos:signal_source" use="required" />
</xs:extension>
</xs:complexContent>
</xs:complexType>
Boris
More information about the xsd-users
mailing list