XML Wildcard Data Mapping and Transformation in MapForce
MapForce 2014 now supports mapping of XML wildcards that create a designed-in extension mechanism for XML Schemas, implemented as <xs:any> or <xs:anyAttribute>.
Consider this XML fragment viewed in XMLSpy:
This small portion of a very long file shows two track points recorded during a road trip by a Garmin GPS device. The XML data follows the GPX XML Schema, with Garmin extensions to add speed and course heading values. XML wildcard mapping lets you map these extensions in MapForce just like any other elements explicitly defined in the XML Schema.
Let’s assume we want to read the .gpx file and extract the highest speed recorded for a trip:
We can begin a new MapForce mapping design by dropping in a .gpx file as the input component. MapForce presents a view of all the elements defined in the corresponding XML Schema and available for mapping. The screenshot below shows the portion of the XML Schema for track points:
Latitude, longitude, elevation, and time appear immediately after the <trkpt> element and define to the data seen in the XML fragment. The following items — from magnetic variation <magvar> through ID of DGPS station <dgpsid> — are all optional and do not appear in the Garmin data file.
The <speed> and <course> elements are not defined in this XML Schema at all. Instead, speed and course are permitted based on xs:any at the bottom of the image. Clicking the icon beside xs:any opens a dialog that allows us to import another XML Schema defining the extensions and create a wrapper to combine the original XML Schema and extensions. After import, the new elements are displayed in the source component and can be mapped:
Sorting Data in the Mapping
The example files installed with MapForce include a mapping called FindHighestTemperatures.mfd that we can use as an example to extract the highest speed from our file, using a sort function:
This function sorts all the speed values from high to low, then sends only the first value through for output. The sort key shown as Z->A automatically sorts numeric data from highest to lowest values.
Converting Values in the Mapping
Lastly, we need to convert the speed from meters per second to miles per hour, round the result to two decimal places, and add some descriptive text:
The result of the string concat function shown above is written to the text file for output:
Note that we did not have to explicitly transform speed from a numeric datatype to a string as we moved between functions. MapForce handles the datatype conversion automatically.Here is a reduced size view of the complete mapping with annotations of major operations:
Click the image or click here for a full-size view.
The Altova Web site includes free online product training for MapForce. You can even download a free trial of MapForce and start upgrading your own data mapping and transformation skills today!