[xsd-users] Default values for optional elements.

Boris Kolpackov boris at codesynthesis.com
Wed Feb 15 06:47:01 EST 2006


Hi David,

Moss, David R (SELEX Comms) (UK Christchurch) <david.r.moss at selex-comm.com> writes:

> Yes, that sounds good - catching problems caused by changes at compile
> time is definitely a good idea!

I think I came up with an even better and more generic solution: a
static default_value function in element/attributes infoscope. With
this approach you would write your code like this:

return foo.bar ().present ? foo.bar ().get () : foo::bar::default_value ();

or, using pointer notation:

return foo.bar () ? *foo.bar () : foo::bar::default_value ();

A bit more verbose but more universal and works for all containers,
not just optional. It also has the compile-time error catching feature
(the default_value function will disappear if you remove the default=
attribute). I have this implemented in my workspace and can build you
a pre-release. Just let me know which platform/package you would like.


> I did think there may be an issue with a scenario where the in-memory
> value is set to that of the default (i.e. what should be serialised) but
> that should just be treated as if it was any other non-default value I
> guess.

A smart implementation can always check if the user-provided value is
the same as the default and treat it as such. Right now xsd serializes
without checking. This optimization can be implemented shout there be
strong interest.


hth,
-boris
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 652 bytes
Desc: Digital signature
Url : http://codesynthesis.com/pipermail/xsd-users/attachments/20060215/7a142237/attachment.pgp


More information about the xsd-users mailing list