GML/XML Reading Options Overview
You can read GML and XML in FME using one of four approaches: predefined GML profiles for specific GML formats, FME's GML reader with or without an application schema, FME's XML reader with Feature Paths or XfMaps, or XML to XML translations using XMLUpdater, XQuery and other XML processing transformers. If you have just started using FME for reading XML/GML we recommend reviewing Reading XML - Simple Approach using Feature Paths first.
GML Profiles
In some cases, there are sets of application schemas that are grouped together and called a gml profile. This essentially constitutes another GML format, since it would be rather complex to read and write data to one of these GML profiles without some custom development. Thus Top10 GML, German NAS, OS MasterMap and CityGML are all examples of GML profiles that we have implemented as separate formats.
GML Reader
In many cases, you can simply use the GML reader out of the box. We have made many improvements to our GML reading in recent versions, so it is much more flexible than it was a few years ago. Even with the range of GML that FME supports, often people can forget that there are supporting files required to read a specific GML structure. In many cases there are objects that go beyond standard GML so you will need to supply an application schema file (.xsd). .Xsd files are critical for interpreting gml since often it is not enough to have access to the GML 3.2.1 schemas. Most user or custom defined GML objects require the presence of an xsd or xml schema definition file in order to read them. In fact, you can import the GML schema from an .xsd file without even having any .gml data.
Even with the schema document, the GML reader may have trouble reading your schema. If you are reading complex gml, you may get list structures or xml_buffers which you need to use list functions and XQueries to deconstruct in order to access the content.
XML Reader
The other option is to use the XML Reader, and then use a Feature Path, XQuery or Xfmap to map the xml into feature attributes and geometries. The recommended approach is to use Feature Paths to identify the element tags to use for feature extraction. This approach also includes an option to flatten nested elements into parent.child attribute names making them easier to use in relational structures. Other options include the use of XQueries, which are something like SQL for XML and constitute XML expressions used to query and modify XML data sets. Xfmaps can be used to define the attribute and geometry components of the data structure. You can also use the XML Reader in conjunction with a wide range of XML transformers we provide for XML processing such as XMLFlattener, XMLUpdater, XMLFeatureMapper, XMLFragmenter, and for XQueries. For more information, please start by reviewing the article on XML Reading with Feature Paths.
For those with more background in XML and scripting, there are also articles on XQuery, XfMaps, and XML Processing.
XML to XML with XQuery/XMLUpdater
You can also do GML to GML translations and use XQuery or XMLUpdater to modify existing xml structures without mapping them to relational ones. This may be the best approach when your source data is already in XML or GML, and you just want to update or modify some component of the data but not create a new dataset. XQuery requires knowledge of the XQuery scripting language which is something like SQL for XML. XQuery transformers include : XQueryExtractor, XQueryExploder, XQueryUpdater. XMLUpdater is a new FME transformer that allows you to do insert, delete, update operations on XML while preserving the overall structure and without having to do any scripting. See articles on XQuery or XMLUpdater for more information.
Version Support
FME supports reading from GML 2.1.2, 3.1.1 and 3.2.1.
The GML reader will scan the data, detect version, and call the correct reader version accordingly.
Now, just because we say we read a particular version of GML, it doesn't mean we can read from
a particular GML schema out of the box. It also does not mean we have implemented the entire schema of what is theoretically possible. Practically no one has done this. This is because the specification for what can be defined in GML is hundreds of pages long (500+), and so every software developer needs to decide what subset of this they want to implement and support. For example, ESRI only implemented simple feature profile level 0, which covers points, lines, polygons, but not arcs or ellipses, etc.
So are there GML datasets which are believed to comply with GML specs that we cannot read? This is entirely possible, but it may be that the user has not configured the reader correctly or is missing some of the .xsds required (xsds often have external or nested references). Or there may be complex structures that are interpreted as lists and need some involved list indexing and processing in order to extract the required information. In any case, the best thing to do would be to send some sample data to support@safe.com and we can take a look.
Reading Specific GML Schemas
When reading a GML dataset you may get the error message: "The XML Module halted on error - see logfile for details"
If you check the log file you'd likely also see the warning message...
WARNING - No explicit XML Schema specified (through the XSD_DOC keyword)
nor an xsi:schemaLocation was found in dataset <xxxx>
...the problem is that GML has a very flexible structure that varies from file to file and is determined by a "schema" document.
FME supports a few of the simpler GML structures, but for more complex or customized structures it can do nothing without the schema document.
Coordinate System Support
Reading GML
When reading GML, FME will try to convert the srsName URI strings into their FME equivalents. If the coordinate sys name is of the "EPSG:####" form then all should be well, but failing that there's a file that helps the GML reader carry out the match. The file is located at {
FME installed dir}\xml\gml\xfmaps\gml_keywords.xml.
The other function served by this gml_keywords.xml file is to specify the axis order for the coordinate system; for example is it X/Y or Y/X. Right now, only EPSG:4326 and EPSG:4329 are listed:
<group name="srsName-to-axisOrder">
<keyword name="EPSG:4326" value="2,1"/>
<keyword name="EPSG:4329" value="2,1,3"/>
</group>
Coordinate systems not listed default to x,y (1,2). Reading GML 2.1.2 is fine, because each axis is separated by a comma and each coordinate tuple is separated by whitespace, therefore we can at least calculate the dimension implicitly. However, this may cause trouble for GML 3.1.1 coordinates because coordinates axes and tuples are both whitespace separated so there's no implicit way to determine the dimension.
This could be a particular issue for custom coordinate systems (you can even have custom EPSG definitions) in which case change the axis order by updating the "srsName-to-axisOrder" portion in gml_keywords.xml. After adding the custom (EPSG) definition to FME, set axis order values to "1,2" for x,y, "2,1" for y,x, or use the equivalent 3Ds "1,2,3" for x,y,z or "2,1,3" for , y,x,z.
References:
Safe Docs: Readers and Writers - GML Readers and Writers - XML Blog - It's All About Data: Loving XML with FME 2012 The following links are provided for reference only and are not endorsed in whole or in part by Safe Software:
Wikipedia:
http://en.wikipedia.org/wiki/Geography_Markup_Language
From Legos to Varieties of GML Lite:
http://www.directionsmag.com/article.php?article_id=2408
Lost in Abstraction - What Went Wrong with GML
http://www.artima.com/forums/flat.jsp?forum=123&thread=204378
ESRI: "GML Profiling: Why It's Important for Interoperability"
http://www.esri.com/news/arcuser/0403/gml.html
Use Profiles to Overcome GML's Complexity
http://www.ogcnetwork.net/node/603
Example: Reading NATO GML Data
Follow these steps to read NATO GML data:
1) Edit the attached natoxrs.xml file. Specifically, change the line:
<xrs:keyword name="XSD_DOC"value="\\myComputer\NatoData\GMLApplicationSchemas\VMAP0\VMAP0.xsd"/>
...to point to the location of the VMAP0.xsd on your machine.
2) Read the data using the reader XML. Under Settings, select 'Use XRS file' and browse to the modified natoxrs.xml file.