[xsd-users] error: cannot convert to ?int? in assignment
shubhgd at cs.vt.edu
shubhgd at cs.vt.edu
Sun Feb 20 20:11:38 EST 2011
Hi,
I am trying to use the XSD generated C++ classes for mapping an XML
schema union type data. The XSD definition looks like:
<xs:element name="scalar">
<xs:complexType>
<xs:complexContent>
<xs:extension base="nd">
<xs:sequence>
<xs:element name="sval" type="scalartype" minOccurs="1"/>
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>
</xs:element>
<xs:simpleType name="scalartype">
<xs:union memberTypes="xs:int xs:double xs:string xs:boolean"/>
</xs:simpleType>
and in the driver.cxx I want to use the value of a scalar variable
from the corresponding XML. I tried to achieve this with the following
piece of code:
auto_ptr<aircraft_t> a (aircraft (xml_file_path));
for (data::scalar_const_iterator s (d->scalar().begin ()); s !=
d->scalar ().end ();++s)
{
string nm = s->name().get();
if(nm == "npts_top")
{
int npts_top = s->sval();
}
}
Here, aircraft is the root element. And the hierarchy is
aircraft->data->scalar.
However, with this piece of code, I get the following error:
error: cannot convert ?const scalartype? to ?int? in assignment
which sounds right because sval is of type scalartype and not int. But
scalartype can be a type of int (as it's a union of int, string, and
so on). So, I am not able to convert sval to an int type which I was
guessing would be taken care of by the underlying scalartype, but
apparently not. Could any one let me know how to handle this? Thank
you very much.
Thanks and Regards,
Shubhangi
More information about the xsd-users
mailing list