[xsd-users] Sample code for GML creation?

Boris Kolpackov boris at codesynthesis.com
Tue Jul 27 10:45:24 EDT 2010


Hi Pavel,

Pavel Pohanka <pavelpgt at gmail.com> writes:

> But I am not able to put anything else to it. I can create building
> 
> building::BuildingType b;
> b.id("Building#1");
> b._name("Embassy");
> But I don't know, how to incorporate it to XML. I would like to get such
> citygml xml file.
> 
> 
> <CityModel xmlns="http://www.opengis.net/citygml/1.0">
>  <cityObjectMember>
>     <bldg:Building gml:id="bldg61003062">
>       <gml:name>Embassy</gml:name>
>       <gml:boundedBy>

As I mentioned in my previous email, the best way is to start from
the root element and to study the generated code (or, better yet,
the generated doxygen documentation). As a general rule, if you see
a nested element, say cityObjectMember, directly inside an outer
element, say CityModel, then there should be a set of functions
in the outer element's type (CityModelType in our case) for this
inner element. If I look through the generated CityModelType
class, I see accessors/modifiers for a sequence of
_GenericApplicationPropertyOfCityModel elements. The reason
why cityObjectMember can appear in place of that element is
because cityObjectMember is in the substitution group rooted
at _GenericApplicationPropertyOfCityModel (this is one of the
flavors of polymorphism in XML Schema). cityObjectMember is
of the FeaturePropertyType type. So we create an instance
of that type and add it to the sequence:

CityModelType city_model (...);
FeaturePropertyType city_object_member;
city_model._GenericApplicationPropertyOfCityModel ().push_back (
  city_object_member);

We can apply the same reasoning to the cityObjectMember and
Building elements:

CityModelType city_model (...);
FeaturePropertyType city_object_member;

building::BuildingType b;
b.id("Building#1");
b._name("Embassy");

city_object_member._Feature (b);

city_model._GenericApplicationPropertyOfCityModel ().push_back (
  city_object_member);

And so on. Also, if you are not familiar with substitution groups 
in XML Schema, I suggest that you familiarize yourself with this
mechanism since it is used extensively in GML/CityGML.

Boris



More information about the xsd-users mailing list