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

Ballentine, Casey crballentine at essvote.com
Tue Nov 17 10:28:02 EST 2015


Hi Boris,

I see the same thing in our generated databinding code. 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?

Thanks,
Casey

-----Original Message-----
From: Boris Kolpackov [mailto:boris at codesynthesis.com] 
Sent: Monday, November 16, 2015 4:01 AM
To: Ballentine, Casey
Cc: xsd-users at codesynthesis.com
Subject: Re: [xsd-users] question on optional elements/attributes syntax

Hi Casey,

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

> So basically an optional element/attribute didn't have the
> ThisIsMyElement() direct access method.
> 
> Did this really change from XSD 3.1.0 [...]

No, I don't think that changed. Here is the mapping for the lang attribute (optional) from the 'library' example:

    // lang
    //
    typedef xml_schema::language lang_type;
    typedef xsd::cxx::tree::optional< lang_type > lang_optional;
    typedef xsd::cxx::tree::traits< lang_type, char > lang_traits;

    const lang_optional&
    lang () const;

    lang_optional&
    lang ();

    void
    lang (const lang_type&);

    void
    lang (const lang_optional&);

    void
    lang (std::auto_ptr< lang_type >);

While there are direct accessors (the first two), they don't return the element value but rather the optional container.

Boris



More information about the xsd-users mailing list