[xsd-users] Sample code for GML creation?
Boris Kolpackov
boris at codesynthesis.com
Thu Jul 22 09:52:12 EDT 2010
Hi Pavel,
Pavel Pohanka <pavelpgt at gmail.com> writes:
> I put all created files and all gml schemas into a project, but I do not
> know how to start creating an XML file.
I am not an expert in this matter but as I understand GML is not used
directly as an XML vocabulary but rather as a platform for building
other schemas (e.g., CityGML).
However, I don't think there is anything that prevents you from
creating a GML document. Simply pick a root element of the document
that you want to create, for example gml:Point. Add the
'--root-element Point' option to the gml.options file and recompile
the schema. This way you get parsing/serialization functions generated
for this element.
Then create and populate a variable of this element's type in your
application (PointType in out case; to see its interface, check the
PointType.hxx file):
#include "gml.hxx"
using namespace gml32;
gml32::PointType p ("p1");
p.coordinates (CoordinatesType ("100,200"));
For a complex schema like GML it may also make sense to generate
the Doxygen documentation (--generate-doxygen) so that you get
browsable documentation for the generated classes.
The final step is to serialize the point to XML:
xml_schema::namespace_infomap map;
map["gml"].name = "http://www.opengis.net/gml/3.2";
map["gml"].schema = "gml.xsd";
std::ofstream ofs (argv[1]);
gml32::Point (ofs, p, map);
This should result in a GML document like this:
<gml:Point gml:id="p1" xmlns:gml="http://www.opengis.net/gml/3.2">
<gml:coordinates>100,200</gml:coordinates>
</gml:Point>
Boris
More information about the xsd-users
mailing list