[xsd-users] Restricted NMTOKENS (enumeration) with default value
Andre Vautour
andre.vautour at caris.com
Thu Jan 8 09:37:00 EST 2015
I ran into a problem with a schema that has an enumeration (xsd:NMTOKENS
with restrictions) that has a default value. The generated enum does not
seem to have a default constructor, yet the generated default
initialization method tries to use the default constructor. I am using
xsd 4.0.0 on Windows.
Here is a simplified schema that shows the problem:
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:attribute name="colour" default="red">
<xsd:simpleType>
<xsd:restriction base="xsd:NMTOKENS">
<xsd:enumeration value="red"/>
<xsd:enumeration value="green"/>
<xsd:enumeration value="blue"/>
</xsd:restriction>
</xsd:simpleType>
</xsd:attribute>
<xsd:complexType name="ValueType">
<xsd:sequence/>
<xsd:attribute ref="colour" use="optional"/>
</xsd:complexType>
<xsd:element name="Value" type="ValueType"></xsd:element>
</xsd:schema>
The command-line:
xsd cxx-tree schema.xsd
Generated code has the following method:
static ValueType::colour_type
_xsd_ValueTypecolour_default_value_init ()
{
ValueType::colour_type r;//< This uses the default constructor and
results in a compilation error.
{
::xml_schema::nmtoken tmp ("red");
r.push_back (tmp);
}
return r;
};
Yet, the generated colour_type does not have a default constructor:
colour (const ::xml_schema::nmtokens& v);
I ran into this particular problem when trying to generate OGC's OWS
1.1.0 schema, see the rangeClosure attribute of RangeType:
http://schemas.opengis.net/ows/1.1.0/owsDomainType.xsd
Thoughts?
André
More information about the xsd-users
mailing list