Table of Contents
XmlScript: Quick Start Guide
This small guide will try to learn you how to use XmlScript actions in Rocrail.
- How to Create Actions.
- How to Link Actions with Objects.
- Some XML basic knowledge.
- A Rocrail installation with revision 10289+.
2: Hello World
This chapter will show you in only a few steps how an XmlScript can be used as action.
Creating the script
- Create an action with the ID script1.
- Write in the command file field script1.xml.
- Click on the Edit button.
- Place the cursor in the XmlScript editor somewhere between <xmlscript> and </xmlscript>.
- Select in the Statement box text.
- Select in the ID box t1.
- Select in the Command box format.
- Write in the Parameter box Hello world!.
- Push the Insert button.
- The new line will show up.
- Push the Save button.
Link the action with the button
Now the link must be defined with the push button b1.
- Open the button b1 properties.
- Push the Actions… button.
- Select the action ID script1.
- Select the action State on.
- Push the Add button.
- Push the OK buttons.
Test the XmlScript
All is ready now to make the 'Hello world!' test.
- Click on button b1.
- Button b1 will turn to green color.
- The text field t1 will show: Hello world!.
- Congratulations! Your first XmlScript did work.
- 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 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.
- Open the Actions dialog, double click on the action script1 to open the XmlScript editor.
- 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.