[xsd-users] Polymorphism, am I doing something wrong?
Rob Ursem
Rob.Ursem at cmgl.ca
Fri May 2 01:35:14 EDT 2014
I've been looking at the polymorphism example and see how that works , but I can't seem to make my example work.
Consider the following schema:
<?xml version="1.0" encoding <xsd:schema xmlns:xsd="http://www xmlns:xs="http://www.w3.org/2001/XMLSch <xs:complexType name="cs_abstractArrayOfPoin abstract="true">
<xs:sequence/>
</xs:complexType>
<xs:complexType name="cs_pointGeometryPatch& <xs:sequence>
<xs:element name="points" type=" minOccurs="1" maxOccurs=&quo </xs:sequence>
</xs:complexType>
<xs:complexType name="cs_arrayOfExplicitPoin <xs:complexContent>
<xs:extension base="cs_abstractArrayOfPoints <xs:sequence>
<xs:element name="coordinates" type=& minOccurs="1" maxOccurs="1" / </xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>
<xsd:element name="PointGeometryP type="cs_pointGeometryPatch"/>
</xsd:s In this schema we define a "cs_pointGeometryPatch" type that element named "points" of type "cs_abstractArrayOfPo type is an abstract type and for the sake of the example only one 'implementation' of this abstract class in the schema.
An example xml for this schema is:
<?xml version="1.0"?>
<PointGeometryPatch xmlns:xsi="ht tp://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="points.xsd" <points xsi:type="cs_arrayOfExplicitPoints3d <coordinates>3</coordinates>
</points>
</PointGeometryPatch>
In this case a non-abstract class is used for the points element.
This wel The generated code (only hxx shown) is:
class cs_pointGeometryPatch: public ::xml_s {
public:
// points
//
typedef ::cs_abstractArrayOfPoints3d typedef ::xsd::cxx::tree::traits< points_traits;
const points_type&
points () const;
points_type&
points ();
void
points (const points_type& x);
void
points (::std::auto_ptr< points_t // Constructors.
//
cs_pointGeometryPatch (const points_ cs_pointGeometryPatch (const ::xerce & & cs_pointGeometryPatch (const cs_poin & & virtual cs_pointGeometryPatch*
_clone (::xml_schema::flags f = 0, ::xml_sc virtual
~cs_pointGeometryPatch ();
// Implementation.
//
protected:
void
parse (::xsd::cxx::xml::dom::parser& ::xml_sch protected:
::xsd::cxx::tree::one< points_typ };
We can see that when we request "points()" from a cs_pointGe ometryPatch class, we get a reference to points_type, which is the
abstract schema, the parse ayOfExplicitPoints3d" but due to the fact that the accessor for points
is a reference and not a the abstract type to a derived programmatically get to the value 3 (for coordin shown xml.
Am I missing something?
More information about the xsd-users
mailing list