Creating Types From XML

Last Updated: 12/03/2015 Introduced in Verision: 2.0

A data structure is a particular way of storing and organizing data in a computer so that it can be used efficiently. A data structure represents real or abstract objects through use of data members-basic units of information which can be thought of as variables belonging to the object you wish to represent. An example is a person data structure, and its attributes could be data like hair color, shoe size, and date of birth. Each data structure has unique properties that make it well suited to give a certain view of the data.

 

The Decisions portal can integrate with web services that return XML formatted data.

The steps for retrieving and using the XML data are as follows:

1) Integrate the service within the Portal

2) Create a flow to make the service call and handle the results

3) Generate a data type to deserialize the XML data so it is usable and introduce that type into the flow

In this example, a web service that retrieves weather is integrated with the Decisions Portal. An XML data type is generated against the web service’s return data structure, and a workflow is created to make the service call and handle the results.

Integrating the Web Service

Log in to the portal with a user having Administrator privileges, and navigate to System > Designers > Integrations > External Services.

createRestServiceIntegration

Click on Add REST Service Integration. In the Service Name field, enter the name of the web service , and in the Service URL field, paste in the URL. Most likely, the URL will contain variables to pass in; those will be moved to a new field after the following settings are established.

 

nameAndURLService

Change the Service Input Method field value to Post, since information will be passed in to the service. Upon selecting Post, the Service Content Type field appears; select  XML  from this list.

changeToPostAndXML

Next, populate the Data To Send field with the data to pass in. From the URL, cut the list of parameters, which starts after the question mark (?) in the URL. Paste that string into the Data to Send field and remove the question mark that starts the string.

dataToSend

To make the values dynamic, it is necessary to remove the values and replace them with tokens representing the data, enclosed within this type of bracket: {}.

Now that the data to send is formatted, the last step is to put that string into the service URL. Type a “q” at the end of the string in the Service URL field. Copy the formatted string in the Data to Send field and paste it at the end of the string in the Service URL field:

completeRequestURL

Click OK.

Using the Web Service Call in a Flow

Next, create a new flow that will make the call to the weather web service and ingest the return data. From the Designer Project folder, click Create Flow. Name the new flow and click OK.

createFlow

 

From the Flow Designer start-up window, expand the Integrations > All Integrations > Rest Service category, and select the Weather Service component. Click Add to add it into the workspace. 

flowStarts

 

Notice the three input fields; the values established here will populate the query string passed in to the service. For simplicity, hard-coded values will be used in this example (however, a more valid example is using a form to pass in values, giving a user the ability to provide input).

The output of this web service call will be a string of serialized XML data.

dataReceived

 

In order to use the data returned in a more meaningful way, it is necessary to create a data structure for the data.

Save and close the flow.

Create Data Structure From XML

From the Designer Projects folder, click on Create Datatypes > Create Types from XML.

createDataTypeXML

 

In this example, we have a file that contains the structure of the XML data returned. It is also possible to simply paste in that structure when creating the data type. Enter a name for the service in the  XML Structure Name field, and either upload a file for the structure or paste in the data structure. In the list of recognized data types from the structure, select the desired types.

XmlInformation

Click OK. The data structure is generated for the XML data, as well as components for deserializing and serializing that data. Next, is is necessary to introduce the Deserialization step into the flow to break down the XML string into meaningful, usable data.

From the Designer Projects folder, open the flow that contains the weather service step.

Deserialize XML Data

From the Toolbox, expand the Integrations > XML Structures category. Notice the category for the structure just created; expand this category.

deserializeCitiesDrag

 

Drag and drop the Deserialize Weather component following the Weather Service 1 component. Connect the Done path of the Weather Service 1 component to the Deserialize Weather component. Connect the Done path out of the Deserialize Weather component to the End component, and do the same with the Error path.

flowCompleted

Click on the Deserialize Weather component, and in the Properties panel, change the Input > String to Deserialize mapping type to Select Value. Click on the Path field browse button, and select the Done string and click OK. This is the output from the Weather Service 1 component.

Notice now that the deserialized output is available:

resultDeserialized

Additional Resources