FME Version
Easier approaches to reading XML are now available in FME. See XML Reader Configuration or Reading Complex XML or GML using the XMLFlattener
Introduction
The FME XML Reader reads an input document and processes it according to instructions, called mapping rules, that can be specified in a file called an xfMap document. The xfMap can either be defined by the user or generated automatically by the reader using the XML reader's Feature Path parameters, which requires no scripts from the user.
The basic problem is that XML documents are normally very nested or object oriented structures, whereas GIS formats and tools such as FME are normally geared to working with flat or relational oriented structures. So reading a typical xml file is not as simple as pointing FME at an xsd. You need to define how you want to interpret the xml. Specifically, you need to define exactly what node level becomes a feature type, and what elements under that node are to become fields or geometries of that feature type. In FME, xfMaps are one way to do feature mapping from xml to FME. Reading for many of the custom GML/XML formats you see in FME are mostly done using xfMaps.
However, before you proceed further with learning xfMaps, it is recommended that you explore the XML reader's new feature path capabilities, which are a lot easier to use.
NB: xfmaps are used for reading data, not writing, as it is a one way xml to FME feature mapping. Writing for the custom GML/XML formats you see in the FME are mostly done with the XMLTemplater transformer.
Users may create their own xfmap - if so they can be used with the "XML" reader by specifying the xfmap through the "Settings..." button. The xfmap typically has two main sections, the feature map and the feature content map. The feature map defines the feature types you want to extract and the feature content map defines the attributes and geometries you want those features to contain. Matching expressions drive these mappings. The matching expression defines what xml nodes to read. Anything that is not matched is ignored. Also With xfmaps you can extract as much or as little as you want from a given xml source. If there is no match it will just skip that element. The only limitation is that you can only match a node once. So if you have to mapping match = "LineString" expressions, only the first one will get used. This is why it is necessary to define exceptions, especially for matching expressions that use wildcards.
The FME Readers and Writers document, has a section on xfMap syntax and use.
Examples
There is a little XfMap tutorial/case study that walks through making a simple xfMap to parse a relatively simple XML file (and then goes on to wrap the whole thing up into a custom format to make it very nice to use).
Here is another simple example to help you get started XfMap_Example_Basic. This latter one includes geometry and geometry trait definition as well as attributes.
This example called XfMap_Example_Flatten works with the same source data as the XFMap_Example_Basic but uses a shortcut called a structure command to automatically flatten all the elements under the <Feature> node into the form parent_child etc. This effectively gives you a quick way to 'slice' your xml at a particular node without having to write a detailed xfmap.
Then there is XfMap_Example_Dynamic which will show you how to read xml that has no predefined schema but rather has the schema embedded within the xml data itself.
Comments
0 comments
Please sign in to leave a comment.