Calculator variant with XML file
The aim is to build a calculator, as in the previous example, with input and output of an XML file.
Here you will find an example XML with a division of two values:
<?
xml
version
=
"1.0"
encoding
=
"utf-8"
?>
<
Calculate
>
<
OP1
>10</
OP1
>
<
OP2
>3</
OP2
>
<
OPR
>/</
OPR
>
</
Calculate
>
<
RESULT
>3.333333</
RESULT
>
In this example, the division is to be output with 6 decimal places.
The calculation is almost identical to example 2, only the type of the variable var_result must be selected as Float, Double or BigDecimal.
Step 1 - Create profile
You are welcome to clone the existing calculator profile from example 2 and save it under a new name, e.g. Lobster_Tutorial_HTTP_calculator_xml.
Adjust the following settings in the Main settings:
Document type: XML
Encoding: UTF-8
Mapping is activated.
Step 2 - Adjust input and format settings
In phase 1, adjust the following settings for HTTP:
URL address suffix: calculator_xml
Mime type of response: application/xml
In phase 2, the parser is told where the root node of the input is located.
Step 3 - Mapping
In phase 3, the source structure can be created via menu option 'structure generated from file analysis'. To do this, save the sample XML from the input as a file and upload it via 'File analysis...'. Please make sure that you tick the checkbox "no complex fields". An initial node RESULT is required within the target structure.
Below this, the value of OP1 is first written into the variable var_result and then the calculation is initiated via the OP2 and the OPR source field. The number of decimal places can be defined via the parameter e of function calculate and save variable. Use the val syntax for naming the fields so no extra node is created for the field in the XML output.
The XMLNoTemplateUnit in phase 5 generates the output format. The root node name must be specified here.
The data is sent back to the client via the Response "Custom class" with class "PassBackDataResponse" and the content setting "Output of IU".
You can test the request again via Postman by adjusting the URL and the body of the request accordingly.