Keywords: clear search

## Welcome to the Futurama Support Site

The Futurama Support Site is the website where you can find Futurama and Futurama Vision documentation. If you have any questions about the support pages or if you want to provide us feedback please send us an e-mail.

Index Exercise 1: Shares (Medium)

451 documents found.

# Exercise 1: Shares (Medium)

Developer
Tutorial

Module: Editor

Version: 4.2.1 +

User: Developer

Difficulty: Medium

Introduction

In this exercise we will read XML data into Futurama, out of two different external XML-files.

Prerequisites

- The Futurama Editor must be installed.
- Completing the tutorial Reading and processing XML-data in Futurama first, is recommended.

## Description

In this exercises we will read the data out of two different XML-files into Futurama, and use the data to perform calculations.

Download the two XML-files by clicking here. Unzip and place these files in the same directory where you will create your Futurama Document.

The exercise regards a number of shareholders for three different companies. Frank, Sara and John each have a different set of shares of the three companies Futurama, McKing and MicroFruit.
In the first file (participants.xml) you will find the amount of shares per company, for each of the participants. In the second file you will find the value of one share per company.
The goal of this assignment is to create a function in Futurama that determines the total worth of the set of shares for each participant. With this function we can determine which participant holds the set with the heighest total value.

## Assignment

Read and process both files in Futurama and calculate in the Futurama Editor who has the best total value of shares. Take the following steps to do so:

1. Create a Node 'Shares' in your Futurama document, in which you will read and process the 'shares.xml'-file:
- Create a formula 'Read' of type String, and use the formula 'ReadFile' to read the 'shares.xml'-file.
- Create an XMLNode 'Shares' that returns the XML-data of the file read.
- Create XMLFields within the XMLNode that display the value of one share of each of the companies.
(For help with this construction, see the Tips-section)
2. Create a Node 'Participants' in your Futurama document, in which you will read and process the 'participants.xml'-file:
- Create a formula 'Read' of type String, and use the formula 'ReadFile' to read the 'participants.xml'-file.
- Create an XMLNode 'Participants' that returns the XML-data of the file read.
- Create a Fixed 'Name' of type String in which you enter one of the names of the participants.
- Create an XMLNode 'Participant' within the XMLNode 'Participants' that only displays the XML-data of one participant, by referring to the Fixed 'Name'.
- Create XMLNodes for each of the companies within the XMLNode 'Participant'.
- Create an XMLField 'Amount' within each of the company-XMLNodes, which returns the amount of shares that the participant holds for each company.
(For help with this construction, see the Tips-section)
3. Create a Node 'Calculation', in which you create a formula that calculates the total value of the set of shares.
4. Calculate the total value for each participant by changing the name of your Fixed 'Name', and determine who has the heighest total value.

## Tips

• To create the formula to read the XML-files, you have to enter the FileName into the formula 'ReadFile'. The FileName can be constructed by using the formula 'Concatenate', and then first enter the formula 'GetPathToDataFiles' (which returns the path to where you are creating your Futurama-document), and after that add the filename, eg. 'Shares.xml'.
Verify that the file is read correctly by evaluating the formula.
• You have to configure the XMLNodes 'Shares' and 'Participants' to display the XML-data that is in the external XML-files:
- In the Source-property, refer to the corresponding XML-file formula 'Read'
- The XML-data both contain a namespace. Therefore you should add a Namespace in the NameSpaces-property. Choose a Prefix, f.i. 'a' and enter the URI given in the XML-file.
- In the XPath-property, make sure you use the Prefix to retrieve the data wanted. Enter 'a:Shares' resp. 'a:Participants' to retrieve the complete data-file. Remember to use the Prefix when retrieving data on a lower level, f.i. the XMLFields.
• In the XMLNode 'Participant', you should create a formula for the XPath-property to display the data of one single participant. This formula should be constructed as follows:
Concatenate(
- "a:Participant[id="
- Reference to the Fixed 'Name'
- "]"
• To calculate the total amount, multiply the amount of shares with the value per share. Do this for every share and add them all together.

## Solutions

• The total value is the heighest for Sara: 24,000.