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

Klaim mjklaim at gmail.com
Wed Nov 24 11:19:43 EST 2010


If I understand correctly, if I use the restriction+extension pattern AND
use fixed="the_value_I_want" in the restriction AND uses the xsd file for
validation when parsing using the xsd-tree code generated by this tool, then
"the_value_I_want" will be taken from the xsd (instead of the code) and set
in the instantiated object?

It that works, then my problem is solved because I need validation. I'll
check this once home.

On Wed, Nov 24, 2010 at 16:05, Boris Kolpackov <boris at codesynthesis.com>wrote:

> 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