[xsd-users] Customize sequence and optionals

WEBER Stefan stefan.weber at efgfp.com
Thu Jan 29 03:40:51 EST 2009


Hi Boris,
 
> > In my schema, the reason to make some elements optional is 
> mostly for 
> > convenience of the user writing the XML, such that the user 
> does not 
> > have to explicitly specify the element in case he wants to use the 
> > default value anyway. (e.g. for configuration data)
> 
> [...]
> 
> So am not sure how convenient elements with default values 
> will be in your situation.

Because the element defaults are not very useful in XML schema, I
implement this separately. I'm doing something like this:

template<class NonOptional, class Optional>
void createIfNotPresent(Optional& optionalType) {
    if(!optionalType) {
        optionalType.set( std::auto_ptr<NonOptional>(new
NonOptional()));
    }
}

The call to this is a bit ugly because I don't know how to derive the
NonOptional type from the Optional, e.g.:

MyOptionalType myOptional;
createIfNotPresent<MyNonOptionalType>(myOptional);

Isn't there a way to access the optionals containing type given the
optional one? Such that I could do something like:

template<class Optional>
void createIfNotPresent(Optional& optionalType) {
    if(!optionalType) {
        optionalType.set( std::auto_ptr<Optional::type>(new
Optional::type()));
    }
}

This would be much more convenient but I could not find a typedef in the
declaration of optional that seems to allow this.

Is there still a way to derive the non optional type from the optional
container?

Thanks,

Stefan

==== The EFG Mail Gateway made the following annotation =====
This message is for the addressee only and may contain confidential or
privileged information. You must delete and not use it if you are not
the intended recipient. It may not be secure or error-free. All e-mail
communications to and from the EFG Financial Products Group may be monitored.
Processing of incoming e-mails cannot be guaranteed. Any views expressed
in this message are those of the individual sender. This message is for
information purposes only. All liability of the EFG Financial Products Group
and its entities for any damages resulting from e-mail use is excluded.
US persons are kindly requested to read the important legal information
presented at following URL: http://www.efgfp.com. If you suspect that the
message may have been intercepted or amended, please call the sender.
Should you require any further information, please contact the Compliance
Manager on compliance at efgfp.com.
=============================================================





More information about the xsd-users mailing list