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

Boris Kolpackov boris at codesynthesis.com
Wed Nov 24 10:05:59 EST 2010


Hi Klaim,

Klaim <mjklaim at gmail.com> writes:

> The solution you suggest is the same than the unique answer I got there ?

Yes, the same as the "restriction then extension" solution.

> 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.

What do you mean by "not available"? The attribute is there, it is just
restricted to a specific value.


> 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.

Yes, that's partly true. Since there is no equivalent to "inheritance by
restriction" in C++, the generated code simply makes the derived type
pretty much the same as the base, leaving it for the underlying parser
to enforce the restriction. As a result, if you get the object model
from parsing an XML document and validation is enabled, you will get
the correct attribute value set. However, if you construct the object
model programmatically in your application, then you will need to
set the attribute value manually.


> 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?

You could customize the generated classes slightly to set the "fixed"
values automatically. I.e., derive from the generated version and
in the constructors, set the values corresponding to the kind of
instance. For more information on type customization see the C++/Tree
Mapping Customization Guide:

http://wiki.codesynthesis.com/Tree/Customization_guide

As well as the examples in the examples/cxx/tree/custom/ directory.

Boris



More information about the xsd-users mailing list