[xsd-users] retrieving data from gml:featureMember

Boris Kolpackov boris at codesynthesis.com
Fri Nov 16 10:16:51 EST 2007


Hi Jan,

Jan Pauwels <Jan.Pauwels at graphicomp.com> writes:

>   <gml:featureMember>
>     <BP_Plan gml:id="obj_0">
>    </BP_Plan>
>  </gml:featureMember>
>
> I use the following code : (copied from example polymorphism)
>
> [...]
>
>     xplangml::XPlanAuszugType copy (*Auszug); // Dynamic types are
> preserved in copies.

You don't really need this: it makes a copy of the object model for
illustration.

>     for
> (gml::AbstractFeatureCollectionType::featureMember_const_iterator i
> (copy.featureMember().begin());
>          i != copy.featureMember ().end ();
>          ++i)
>     {
>       if (const xplangml::BP_PlanType* s = dynamic_cast<const
> xplangml::BP_PlanType*> (&*i))
>         cout << "BP_Plan" << endl;
>       else
>         cout << "no BP_Plan" << endl;

You are iterating over the sequence of the featureMember elements
and trying to cast them to BP_PlanType. But featureMember is not
a BP_PlanType, rather it contains an element of BP_PlanType. So
you need to go one level deeper:

const gml::FeaturePropertyType& fp = *i;

if (fp._Feature_present ())
{
  const gml::AbstractFeatureType& f = fp._Feature ();

  if (const xplangml::BP_PlanType* s = dynamic_cast<const
    xplangml::BP_PlanType*> (&f))
  {
    cout << "BP_Plan" << endl;
  }
  else
    cout << "no BP_Plan" << endl;
}

See the FeaturePropertyType type in GML's feature.xsd for more
information.

Boris




More information about the xsd-users mailing list