[xsd-users] question on optional elements/attributes syntax

Boris Kolpackov boris at codesynthesis.com
Tue Nov 17 11:34:17 EST 2015


Hi Casey,

Ballentine, Casey <crballentine at essvote.com> writes:

> The returned values for optional elements are ThisIsMyElement_optional
> types. One thing I did discover is that complex elements that have
> sub-elements do require the .present() and .get() calls, but simple elements
> like Booleans can be accessed using the direct method. Does that make sense?

I don't think it is "like Booleans" but rather "only Booleans". optional<>
has a smart pointer-like interface which allows you to write:

if (x.member ())
{
  cerr << *x.member () << endl;
}

To achieve this, optional<> provides conversion to bool, which is why
boolean optional members appear to be directly accessible (though the
returned value is of course wrong).

Boris



More information about the xsd-users mailing list