In this tutorial we will read a live RSS feed of traffic incidents in XML format, create
points of each incident location, set a coordinate system and write them out to KML format.
We will demonstrate how to use feature paths when reading the XML data.
Our source data of traffic incidents is assessed via a URL.
With the Internet Explorer option feed reading view turned on, we see a nicely structured
page with the incidents. With the feed reading view checked off, we see the nested XML and
we can clearly see that the item element contains the incident details.
Let's view this data using the FME data inspector.
Type in XML for the format. A list of XML-based formats appears. Frequently used XML profiles
are often implemented as their own FME format reader and writer, so it's best to first check
if there is a specific reader writer for the XML file you are trying to read. In this case,
there is not, so we will select XML for the format.
For the dataset enter the following URL.
When selecting this format it's important to tell FME how to map the XML elements to
feature types and attributes. Open the parameters and set the configuration type to feature
paths.
Next, identify the element tags to map for feature extraction.
Click next to elements to match. In this tree view we can check which nodes we want to become
feature types. Let's open RSS, then channel, and select item. Click OK to close the dialog's.
FME will scan your data and create feature types based on the flattening of your XML
at the node specified in your feature path. We have 10 features in the item feature type.
It is non-spatial but we do have latitude and longitude values which we can use to create
points in FME workbench - let's do that now.
In FME workbench we will add the XML reader and read the data set again with the same
parameters we just used in FME data inspector.
To create points add a vertex creator transformer and connect its input to the item source feature type.
Set the XY values to long, lat respectively. Then add a coordinatesystemsetter to set the
coordinate system two a lat/long WGS 84 coordinate system.
Connect an inspector.
Go ahead and run the workspace to confirm that we have points.
We will make them red and increase the point size to see them more clearly.
Let's set up the workspace to write to KML. We will add a KML writer and add a location
to write the dataset to.
The copy from reader schema option will copy the schema from the source XML feature type
to the destination KML feature type.
Before we connect things up let's set some KML properties and styling. Add a KML property
setter to the workspace. Open its properties and set category for the name and description
for the summary. These will appear in the Google Earth navigation tree.
We'll use the description also for the KML balloon content.
Next we will add a KML Styler to change the point icon style. Open its properties, expand
the icon section and select the E5 icon.
Now connect the KML Styler to the destination feature type.
Let's also clean up the attributes. Open the properties of the KML feature type. Click
on the user attributes tab and remove the attributes prefixed with XML copied from the source.
Go ahead and run the workspace.
Double-click on the output KML file to see the results in Google Earth.