Nillable Elements

Elements may be declared nillable by using the nillable="true" facet. When an element is declared nillable, an occurrence of that element in an XML document may have an xsi:type attribute with a value of "true", which requires its contents to then be empty.

XBinder models the nilled status of elements according to the following rules:

In the following example, a sequence "nilsInSequence" has four nillable elements: one_int is a non-repeating, simple type element; many_int is a repeating, simple type element; one_complex is a non-repeating, complex type element; and many_complex is a repeating, complex type element.

The generated C code would resemble the following:

    typedef struct nilsInSequence {
        struct {
            //Flag for one_complex's nilled state
            unsigned one_complexNil : 1;
            ...
        } m;
        
        /* String of flags for many_complex's nilled states */
        OSDynOctStr many_complexNilFlags;       /* if -x64 is not used */
        OSDynOctStr64 many_complexNilFlags;     /* if -x64 is used */
        
        OSRTDList many_complex;
        
        //null pointer represents a nilled one_int element
        OSINT32 *one_int;
        
        //null pointers represent a nilled many_int element
        struct {
            OSUINT32 n;                     /* if -x64 is not used */
            OSSIZE n;                       /* if -x64 is used */
            OSINT32 *elem[...];
        } many_int;
        ...
   } nilsInSequence;
        
        
   //Specify whether a given occurrence of many_complex is nilled or not.
   //(index is 0-based).
   int nilsInSequence_many_complex_setNil(
       OSCTXT* pctxt, nilsInSequence* pvalue, size_t index, OSBOOL value);
        
   //Check whether a given occurrence of many_complex is nilled or not.
   OSBOOL nilsInSequence_many_complex_isNilSet(nilsInSequence* pvalue,
       size_t index);                    
   

The generated C++ code would resemble the following:

    class nilsInSequence : public OSXSDComplexType {
        public:
        
        //null pointers represent a nilled many_int element
        struct many_int_array : public OSRTBaseType {
            OSINT32 *elem[...];
            ...
        } ;
        many_int_array many_int;
        
        struct {
            //Flag for one_complex's nilled state
            unsigned one_complexNil : 1;
            ...
        } m;
        ::MyComplex *one_complex;
        
        //String of flags for many_complex's nilled states
        OSDynOctStr many_complexNilFlags;
        many_complex_list many_complex;
        
        //null pointer represents a nilled one_int element
        OSINT32 *one_int;
        
        //Specify whether a given occurrence of many_complex is nilled or not.
        //(index is 0-based).
        int many_complex_setNil(size_t index, OSBOOL value);
        
        //Check whether a given occurrence of many_complex is nilled or not.
        OSBOOL many_complex_isNilSet(size_t index);
        
        ...
    };