[xsde-users] Generated enums for simple types with string enumeration facets

Boris Kolpackov boris at codesynthesis.com
Mon Oct 5 04:25:18 EDT 2009


Hi Thomas,

Thomas Frenzel (TomSun) <tftomsun at streamteam.de> writes:

> I am excited how the generated code will look like. 

We have already done such XML Schema enum to C++ enum mapping for
C++/Tree in XSD, so it will be similar. Just to give you an example,
for the following definition:

<simpleType name="color">
  <restriction base="string">
    <enumeration value="red"/>
    <enumeration value="green"/>
    <enumeration value="blue"/>
  </restriction>
</simpleType>

We will generate the following class:

class color
{
public:
  enum value
  {
    red,
    green,
    blue
  };

  color ();
  color (value);
  operator value () const;

  const char*
  string () const; // String representation.

private:
  value v_;
};


> Will you provide a possibility to convert between the enum value name 
> and the enum value? This would be very useful, because an enumeration 
> simple type in xsd schema must be based on string, but the enumeration 
> in c++ are based on numeric values.

There will be a way to convert from C++ enum value to a string value
(the string() function above). I am not yet sure about the other way
around (i.e., from string to C++ enum). It will be done in the parser
but I am not sure we should also allow this in the interface since it
will need error detection, etc. Do you need this functionality?

Boris



More information about the xsde-users mailing list