Please enable JavaScript to view this site.

Altova MapForce 2020 Enterprise Edition

Calling Web Services

Example: Mapping Data from an RSS Feed

Scroll Home Prev Top Next More

This example shows you how to call a generic HTTP Web service from MapForce in order to map data from an RSS (Rich Site Summary) feed to Microsoft Excel. The example is accompanied by a mapping design file, which is available at the following path: <Documents>\Altova\MapForce2020\MapForceExamples\RssReader.mfd .

 

In this example, the response of the Web service is mapped from the RSS feed of the Altova blog ( https://blog.altova.com/feed ). The schema of the Web service response structure will be required, so that MapForce can create the structure of the data returned by the feed. For convenience, the required schema is available at the following path relative to your "(My) Documents" folder:<Documents>\Altova\MapForce2020\MapForceExamples\rss-2-0.xsd.

 

Calling the RSS feed does not require any request parameter, so the request part of the Web service call will be empty. As for the response, it will be mapped to a Microsoft Excel file. Thirdly, in order to make the publication date of each RSS entry easily readable, it will be formatted as YYYY-MM-DD in the Excel file. To achieve this goal, date processing functions will be used.

 

Therefore, the mapping will consist of three main parts: the Web service call, the target Excel component, and the date processing functions.

 

Step 1: Add the Web service component

1.Make sure the transformation language of the mapping is BUILT-IN (see Selecting a Transformation Language).

2.On the Insert menu, click Web Service Function.

3.Under Service Definition, click Manual.

4.Set the request method to GET and the URL to https://blog.altova.com/feed.

5.Under Response, click the Edit button and browse for the schema of the Web service response. The schema can be found at the following path: <Documents>\Altova\MapForce2020\MapForceExamples\rss-2-0.xsd.

mf_rss_example_01

6.Click OK.

 

At this stage, the Web service is available on the mapping area and you are ready to map data from the response part.

mf_rss_example_02

 

Step 2: Add the target Excel component

1.On the Insert menu, click Excel 2007+ File.

2.When prompted to supply a sample file, click Skip. The Excel component is now available on the mapping area.

3.Click the AddRemove_Selections button next to Sheet 1, and click to clear the Show Worksheets by name option.

4.Click the AddRemove_Selections button next to Row 1, and change the options as shown below.

mf_rss_example_03

5.Connect the following items of the response body to the following items of the Excel component:

 

Response body

Excel file

channel

Worksheets

title

Worksheet Name

item

Rows

item/title

Row B (Title)

item/link

Row C (Link)

 

At this stage, the Row A (Date) is still missing an input value. This value will be added in the next step.

 

Step 3: Add the date processing functions

The date in the response of the RSS feed appears formatted in RFC-822 format, for example: Wed, 20 Jan 2016 14:49:35 +0000. The goal is, however, to see the date formatted in the Excel file as YYYY-MM-DD. To achieve this, add the substring-after and parse-date functions of the MapForce core library to the mapping (for instructions about adding functions to the mapping, see Working with Functions ).

ex_ws_rss_04

As shown above, the substring-after function takes the value from the pubDate node and returns only the text after ,  . The resulting value is then passed to another MapForce core function, parse-date, which parses it using the mask [D] [Mn] [Y] , and returns the value as xs:date.  The format mask means "numeric day of the month, followed by a space, followed by the month name in title case, followed by a space, followed by the four-digit year" (for more information, see the format-dateTime function).

 

Finally, the parsed value is supplied to the Date row of the Excel component.

 

Step 4: Executing the mapping

You are now ready to call the Web service. Click the Output button to execute the mapping and preview the generated output. If the Web service call is executed successfully, the Output tab displays the returned data structure. If the call was not successful, MapForce returns the error accordingly.

 

If you have MapForce Server (https://www.altova.com/mapforce-server), you can also compile the mapping to a mapping execution file (*.mfx) and execute it from the command-line or from the MapForce Server API on the server machine where MapForce Server runs (see Compiling Mappings to MapForce Server Execution Files ).

 

You have now finished creating a generic HTTP Web service call that uses a GET method to read data from an RSS feed. For general information about working with generic Web services, see also Adding a Web Service Call (REST-Style).

© 2019 Altova GmbH