User Tools

Site Tools


xmlscripting:course-en

XmlScript: Quick Start Guide

1: Introduction

This small guide will try to learn you how to use XmlScript actions in Rocrail.

Requirements


2: Hello World

This chapter will show you in only a few steps how an XmlScript can be used as action.

The Layout


The layout is very simple and contains only a button, b1, and a text field t1
Goal is to trigger with the button a XmlScript which will display "Hello world!" in the text field.

Creating the script

  1. Create an action with the ID script1.
  2. Write in the command file field script1.xml.
  3. Click on the Edit button.


After clicking on the Edit button the XmlScript editor will show up with a XmlScript skeleton:

  1. Place the cursor in the XmlScript editor somewhere between <xmlscript> and </xmlscript>.
  2. Select in the Statement box text.
  3. Select in the ID box t1.
  4. Select in the Command box format.
  5. Write in the Parameter box Hello world!.
  6. Push the Insert button.
  7. The new line will show up.
  8. Push the Save button.


Now the link must be defined with the push button b1.

  1. Open the button b1 properties.
  2. Push the Actions… button.
  3. Select the action ID script1.
  4. Select the action State on.
  5. Push the Add button.
  6. Push the OK buttons.


Test the XmlScript

All is ready now to make the 'Hello world!' test.

  1. Click on button b1.
  2. Button b1 will turn to green color.
  3. The text field t1 will show: Hello world!.
  4. Congratulations! Your first XmlScript did work.
  5. To run it again you can reset the text from t1 by clicking on it and delete the text in the popup.



3: Make a decision

In this chapter a decision will be made which depends on the text field t2 contents.

The layout


The layout is extended with an extra text field t2.
The contents of this new text field will be used for a XmlScript decision.
Text field t2 has became the Input option to make it easy to change the containing text.

Extending the script

The goal is to make the new text for text field t1 dependant of the contents of text field t2.

  1. Open the Actions dialog, double click on the action script1 to open the XmlScript editor.
  2. Extend the existing XmlScript as follows:
<?xml version="1.0" encoding="UTF-8"?>
<xmlscript>
  <if condition="$t2 # 4711">
    <then>
      <tx id="t1" format="t2 is 4711 :)"/>
    </then>
    <else>
      <tx id="t1" format="t2 is not 4711 but $t2 :("/>
    </else>
  </if>
</xmlscript>

With the <if> statement a decision can be made. This decision must be defined in the condition attribute of the <if> line.
In this example the condition is defined as follows:

The contents of text field t2, $t2 , is textually compared, #, with the value 4711.

If the condition is true all commands between <then> and </then> are executed.
If its not true, and there is an <else> node, all commands between <else> and </else> are executed.

Because text field t2 is defined as an input field you can play around changing the t2 contents and push button b1.


4: Next steps

  • Check the XmlScript page which statements and commands are available.
  • Use Trace lines to see what is happening in your script.
xmlscripting/course-en.txt · Last modified: 2018/11/12 08:56 by 127.0.0.1