[xsd-users] Enums

Boris Kolpackov boris at codesynthesis.com
Tue Jan 26 13:26:16 EST 2010


Hi Joel,

Joel Stein <jstein at fiveringscapital.com> writes:

> If I have:
> 
>  <xs:simpleType name="Gender">
>    <xs:restriction base="xs:string">
>      <xs:enumeration value="MALE"/>
>      <xs:enumeration value="FEMALE"/>
>    </xs:restriction>
> </xs:simpleType>
> 
> Is there any way to get the string values for "MALE" and "FEMALE"
> without typing them as a string. Would it possible to reference 
> these as constants or convert a Gender object to a string?

The resulting Gender C++ class will have a dual interface. One of
a type similar to C++ enum and the other of xml_schema::string which 
in turn derives from std::string. So you can initialize a Gender
object using the enum interface and then get the value as a string,
for example:

Gender male (Gender::MALE);
const std::string& male_str = male;
const char* male_c_str = male.c_str ();

Boris



More information about the xsd-users mailing list