[xsd-users] Writing CityGML ADE

Olivier Tournaire olitour at gmail.com
Thu Nov 12 05:15:49 EST 2015


Hi,

I use xsd cxx-tree to generate C++ code from CityGML 2.0.0 XSD schema. I
have also defined some ADEs, and I am having trouble when I try to write
attributes of, let's say a Building, when they are defined as
_GenericApplicationPropertyOfAbstractBuilding.

Here is an extract of the XSD defining the ADE:

<element name="value_property"
substitutionGroup="bldg:_GenericApplicationPropertyOfAbstractBuilding"
type="gml:MeasureType">
<element name="area_property"
substitutionGroup="bldg:_GenericApplicationPropertyOfAbstractBuilding"
type="gml:MeasureType">
...
<element name="custom_property"
substitutionGroup="bldg:_GenericApplicationPropertyOfAbstractBuilding"
type="gml:MeasureType">

The code is properly genereated, and, when I try to read a sample ADE file
I do not have any problem: element name is properly recognized and mapped
to the correct namespace.

My problem arises when I try to write a file with the following code:

int main(int argc, char** argv)
{
    try
    {
        CityModelType cityModel;

        // Write the input file
        ofstream output( string(EXAMPLES_PATH + "ade_output.gml").c_str() );
        xml_schema::namespace_infomap ns_map;
        ns_map["xsi"].name   = "http://www.w3.org/2001/XMLSchema-instance";
        ns_map[""].name      = "http://www.opengis.net/citygml/2.0";
        ns_map[""].schema = "../../CityGML.xsd";
        ns_map["xAL"].name   = "urn:oasis:names:tc:ciq:xsdschema:xAL:2.0";
        ns_map["xAL"].schema = "../../xAL/xAL.xsd";
        ns_map["xlink"].name = "http://www.w3.org/1999/xlink";
        ns_map["xlink"].schema = "../../3.1.1/xlink/xlinks.xsd";
        ns_map["dem"].name   = "http://www.opengis.net/citygml/relief/2.0";
        ns_map["dem"].schema = "../../CityGML/relief.xsd";
        ns_map["bldg"].name  = "http://www.opengis.net/citygml/building/2.0
";
        ns_map["bldg"].schema = "../../CityGML/building.xsd";
        ns_map["gml"].name   = "http://www.opengis.net/gml";
        ns_map["gml"].schema = "../../3.1.1/base/gml.xsd";
        ns_map["sample_ade"].name   = www.sample_ade.com";
        ns_map["sample_ade"].schema = "sample_ade.xsd";

        bldg::BuildingType bldg;


bldg::BuildingType::_GenericApplicationPropertyOfAbstractBuilding_sequence
gapSequence;

        gml::MeasureType vp(1.3, "unit of measure");
        vp._name("value_property");
        vp._namespace("sample_ade");

        gml::MeasureType ap(56.3, "unit sure");
        ap._name("area_property");
        ap._namespace("sample_ade");
        // No success with ap._namespace("www.sample_ade.com");

        gapSequence.push_back(vp);
        gapSequence.push_back(ap);

        bldg._GenericApplicationPropertyOfAbstractBuilding(gapSequence);

        gml::FeaturePropertyType cityGMLBuildingFeatureProperty;
        cityGMLBuildingFeatureProperty._name ("cityObjectMember");
        cityGMLBuildingFeatureProperty._namespace ("
http://www.opengis.net/citygml/2.0");
        cityGMLBuildingFeatureProperty._Feature(bldg);

        cityModel.featureMember().push_back(cityGMLBuildingFeatureProperty);

        CityModel(output, cityModel, ns_map);
        //CityModel(output, cityModel, ns_map, "UTF-8",
xsd::cxx::tree::flags::dont_validate);
    }
    catch (const xml_schema::exception& e)
    {
        cerr << "Exception caught: " << e.what() << " --> " << e << endl;
    }

    return 0;
}

The output is:
 ...
  <cityObjectMember xlink:type="simple">
    <bldg:Building>
      <sample_ade:custom_property uom="unit of
measure">1.3</sample_ade:custom_property>
      <sample_ade:custom_property uom="unit
sure">56.3</sample_ade:custom_property>
    </bldg:Building>
  </cityObjectMember>

As you can see, the namespace is correct, but the name of the property is
always the same. It seems that it is always the last one defined in the
ADE. I have no clue why this error happen. Note that I use a custom type,
the one which is defined on the wiki:
http://wiki.codesynthesis.com/Schemas/CityGML. I howver use CityGML 2.0.0
XSD schemas.

Note also that with this code:

        gml::MeasureType dummy(56.3, "unit sure");
        dummy._name("dummy_name");
        dummy._namespace("dummy_sample");

I have as output in my gml file:

...
<sample_ade:custom_property uom="unit
sure">56.3</cstb_ade_dimosim:custom_property>

Hope you could help.

Best regards,

Olivier


More information about the xsd-users mailing list