[xsd-users] Help on parsing GML
Olivier Tournaire
olitour at gmail.com
Tue Jan 22 19:20:09 EST 2008
Thank you Boris for your answer.
Finally, I choose to parse a CityGML file instead of a GML one. I
generate the C++ code from the CityGML 0.4.0 schema with this command line :
xsd cxx-tree --generate-polymorphic --generate-doxygen --namespace-map
http://www.citygml.org/citygml/1/0/0=CityGML --namespace-map
urn:oasis:names:tc:ciq:xsdschema:xAL:2.0=urn_oasis_names_tc_ciq_xsdschema_xAL_2_0
CityGML.xsd
Then, thanks to your tips, I wrote this small piece of code :
#include <iostream>
#include <fstream>
#include <string>
#include <memory>
#include "CityGML.hxx"
int main(int argc , char** argv )
{
std::string filename("C:\\Documents and
Settings\\Olivier\\Bureau\\FZK-House_LOD1\\FZK_Haus_LOD1.gml");
std::ofstream log("log.txt");
try
{
log << "Parsing file " << filename << std::endl;
std::auto_ptr<CityGML::CityModelType> r (
CityGML::CityModel(filename) );
log << "File parsed with success !" << std::endl;
CityGML::CityModelType::_GenericApplicationPropertyOfCityModel_iterator
iterator_begin, iterator_end;
CityGML::CityModelType::_GenericApplicationPropertyOfCityModel_sequence
seqCity = r->_GenericApplicationPropertyOfCityModel();
iterator_begin = seqCity.begin();
iterator_end = seqCity.end();
}
catch (const xml_schema::exception& e)
{
log << "Error parsing file !" << std::endl;
log << e << std::endl;
log.close();
return EXIT_FAILURE;
}
log.close();
return EXIT_SUCCESS;
}
Here are the first lines of the CityGML file :
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated by: -->
<!-- IFC -> CityGML Converter -->
<!-- (C) - Institute for Applied Computer Science -->
<!-- Forschungszentrum Karlsruhe -->
<!-- Not for commercial use -->
<!-- Generated by: IfcExplorer-->
<!-- Level of Detail 1-->
<!-- Creation Date: Friday, 10 November 2006 - 13:20:59-->
<CityModel xmlns="http://www.citygml.org/citygml/1/0/0"
xmlns:gml="http://www.opengis.net/gml"
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.citygml.org/citygml/1/0/0
http://www.citygml.org/citygml/1/0/0/CityGML.xsd">
<gml:name>AC90-FZK-Haus-2x3-63020_</gml:name>
<gml:boundedBy>
<gml:Envelope>
<gml:pos srsDimension="3">3458643.83172578 5440407.10899672
-1</gml:pos>
<gml:pos srsDimension="3">3458665.08225378 5440425.41250692
6.3176914694611</gml:pos>
</gml:Envelope>
</gml:boundedBy>
...
...
...
I use VC 2003, so, I turn RTTI. Then, everything compiles fine, with
only 4 warnings related to the maximum number of lines the compiler can
support (CityGML.hxx and CityGML.cxx are very very very long). Then, I
run the program, and everything went well.
No, I would like to know how can I access for example the tag
<gml:name>AC90-FZK-Haus-2x3-63020_</gml:name> ? I am able to obtain a
const iterator to a sequence of _GenericApplicationPropertyOfCityModel.
Then, back to CityGML schema, I found these line :
<xs:element name="_GenericApplicationPropertyOfCityModel"
type="xs:anyType" abstract="true"/>
So, dereferencing iterator_begin, I obtain a xml_schema::type which is a
typedef for ::xsd::cxx::tree::type. However, I do not know what to do
with that stuff ...
Here is an other line I found in the CityGML schema :
<!-- =======================================CityModel Members
================================== -->
<!--
=========================================================================================
-->
<xs:element name="cityObjectMember" type="gml:FeaturePropertyType"
substitutionGroup="gml:featureMember"/>
I tried this, but it does not compile :
for (;iterator_begin!=iterator_end;iterator_begin++)
{
if ( dynamic_cast<gml::FeaturePropertyType *>(
(*iterator_begin).pointer ) == true )
; // ...
}
error C2039: 'pointer' : n'est pas membre de 'xsd::cxx::tree::_type'
Please could you help me ?
Best regards
Olivier Tournaire
Boris Kolpackov a écrit :
> Hi Olivier,
>
> Olivier Tournaire <olivier.tournaire at gmail.com> writes:
>
>
>> First, as I am not familiar with GML, I would like to have a small
>> sample with, for example, only points. Could you help me ?
>>
>
> A better place to look for GML document samples would be on the GML
> publisher's website:
>
> http://www.opengeospatial.org/
>
> They also have a forum dedicated to GML where you can ask GML-related
> questions.
>
>
>
>> Then, xsd cxx-tree generated a lot of C++ classes, and I do not know
>> where to begin. What object do I have to declare in order to parse a GML
>> file?
>>
>
> First, I strongly recommend that you read through the C++/Tree Mapping
> Getting Started Guide:
>
> http://www.codesynthesis.com/projects/xsd/documentation/cxx/tree/guide/
>
> This should give you an idea on how to parser and access GML documents.
> Generally, you would first identify the document's root element by
> looking at your sample documents (let's say it is called 'root'). Then
> you would look for a declaration of this element in the schema and
> determine its type (let's say it is 'type'). Based on this information
> you can then write:
>
> auto_ptr<type> r = root ("sample.xml");
>
> Boris
>
>
--
Le temps des cerises reviendra. Dans l'immédiat, c'est le temps des noyaux. Courage.
More information about the xsd-users
mailing list