[xsd-users] XSD : How to set attributes values in children element type?

Klaim mjklaim at gmail.com
Tue Nov 23 16:34:47 EST 2010


Hi, and thanks for your reply!

The solution you suggest is the same than the unique answer I got there ?
http://stackoverflow.com/questions/4199180/xsd-how-to-set-attributes-values-in-children-element-type

If it's that one, then the problem is that both VS and CodeSynthesis agree
that the type attribute isn't available in the final type (the one that
inherit from the restriction) when you do a restriction step before an
extension.

Worse : some experiments show be that CodeSynthesis will not generate (in
C++) the assignation of the value of the attribute that is defined for
exemple in your example in the restriction.

Do you know any other way to achieve a similar code than the C++ example I
provided to explain what I'm trying to get?

The problem I have - to give more context - is that I want to work with an
interface in C++ for several subtypes that are defined in the xsd.
The xsd inheritance mechanism seems to generate the correct code in C++ but
I can't find any way to assign values in xsd code to force properties values
depending on the type and still have those values exposed in the base type.

If I can't find a solution for this, generating the code will not be as
helpful as the generated code don't seem to assign values in properties,
only provide accessors. Only the default value in attribute seems to work,
but not in the case of restriction. Or maybe I'm doing something wrong?


On Tue, Nov 23, 2010 at 20:51, Boris Kolpackov <boris at codesynthesis.com>wrote:

> 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