[xsde-users] SimpleType with restriction creates object with empty constructor

Boris Kolpackov boris at codesynthesis.com
Fri Mar 29 11:01:22 EDT 2019

Andrea Tessadri <tessadriandrea at gmail.com> writes:

> <xs:simpleType name="CountryCodeISO">
>       <xs:restriction base="xs:string">
>           <xs:pattern value="[A-Z][A-Z]"/>
>       </xs:restriction>
> </xs:simpleType>
> class CountryCodeISO: public ::std::string
> {
>   public:
>   CountryCodeISO ();
> };
> In such case there is no way to create an object of type CountryCodeISO
> containing a string, since the only constructor available is the empty one.

In an effort to be minimal and to support usage without exceptions,
XSD/e employs the "default-construct then assign" approach for
initializing  the object model. So you can do this:

CountryCodeISO x;
x = "ZA";


x.assign ("ZA");

If you would like to use a more modern approach with proper constructors,
then you may want to consider using XSD.

More information about the xsde-users mailing list