span8
span4
span8
span4
Many users have problems reading complex xml or gml. The way to do this is with FME’s XML reader, either withFeature Paths, which queries the XML at a given node with the option of flattening, or with anxfMapwhich gives you a wide range of options for both querying the XML and building features. The basic idea with xfMaps is that you specify the which node within the xml structure you want to make into a feature type in the feature mapping section. Then you specify what each of these features contains in the feature content map section.,
However, sometimes this can be difficult because your source xml might not have any schema. Rather, in some cases the schema is embedded within the data itself.
Consider the following xml:
John Vancouver 11-22-99 12-11-09
我们可能会一致格fy the Feature node as the element we want to capture as our feature type. However, simply having one attribute called property would not be very useful as we might get repeating columns or a list such as:
property1 = John property2 = Vancouver etc
A better approach would be to dynamically build the schema from the name-value pairs, so that the name becomes the attribute name and the value becomes the attribute's value. We can do this with the following 'sequenced' xfmap:
The 'mapping match="property"' just selects each property element. 'name extract @typeName' creates an attribute whose name is stored in the @typeName within the property tag, and assigns the value associated with the same property element.
So for
John
the xfmap creates a field called attribute1 and stores the value of property in it which is 'John'.
This xfmap can then read the above xml and generate the following feature from it:
attribute1 = John attribute2 = Vancouver activeDate_from = 11-22-99 activeDate_to = 12-11-09
If you do have optional or multiple geometry, then you will need to enable aggregates. I will explain how to do this in a separate example soon.
Suppose we want to read the source xml below. The dynamic schema approach above would allow us to read all the attributes below the
-123.1,49.25 -122.9,49.15 John Vancouver 11-22-99 12-11-09 -122.8,49.12 -122.5,49.0 June Surrey 02-25-05 9-15-10
如何添加几何?在大多数的动态模式cases I have seen, the geometry itself is not completely dynamic. There are usually known set of geometries for that type of xml. Each feature may or may not contain each geometry, but there has to be some predefined way that the geometries are stored, or it would be too difficult to work with. Of course if each feature just had coordinate values embedded in the attributes, FME could always convert those to points from within Workbench using a 2dPointReplacer.
For the example here we just have a bounding box similar to what we had in the basic example. Note that we do not need to define an exception since the first mapping match only matches with property and not with Coordinate_BOX, so all we have to do is explicitly match on Coordinate_BOX and then build the geometry the same way as we did in the 'Basic' example:
Before we wrap up, how about adding some geometry traits? We can see from the source data above that the geometries have unique identifiers associated with them:
This can become particularly important to preserve when you have more than one geometry per feature and you need to be able to identify them individually as is the case in GML 3.2.1.
We can capture this value using a reference map to the feature map as follows:
This just tells FME to create a reference called identifier and store the value of identifier in it whenever the reader encounters one as it traverses the source xml. Then, whenever we want to retrieve the value of identifier, we will get the last one stored (LIFO). This allows a child element to retrieve a value set while scanning a parent element.
So then, we can modify the geometry section to include traits as follows:
Instead of defining an attribute, we define a trait, and instead of an extract expression, we use a refexpr or reference expression to retrieve the value we set earlier in the reference creation above. Note that we could have defined a new reference map section instead of placing it in the feature map, but this would only be needed if we wanted to be able to capture identifiers from elements that were not Feature elements or within them.
Putting it all together, we now have an xfmap which will create a new feature type for
http://www.w3.org/1999/xlink">
Reading Complex XML or GML using XfMap
Integration example for OGC CSW Data Catalog And Repository with FME Server
INSPIRE Natural Risk Zones Demo (Annex III)
AIXM 4.5 and 5.1 Reading, Writing and Validation - EU Airports Demo
AIXM Airports to INSPIRE Air Transport Networks
© 2020 Safe Software Inc |Legal