Other Action Commands

There are some other action commands that are very useful and important, but have not yet been covered.

SYNTAX

fm:attach

<fm:attach to=”new attach point”/>

fm:call

<fm:call action=”action name”/>

fm:copy

<fm:copy from=”XPath” to=”XPath”/>

fm:do

<fm:do/>

fm:move

<fm:move from=”XPath” to=”XPath”/>

fm:rename

<fm:rename match=”XPath” rename-to=”string”/> 

CONCEPTS

These are all commands that are used with an action. When the action is called, these commands can be run:

EXAMPLES

Take the following XML Structure:

<PARENT>
  <NAME>Bob</NAME>
  <AGE>34</AGE>
  <SEX>M</SEX>
  <CHILDREN>
    <CHILD>
      <NAME>Lucy</NAME>
      <AGE>7</AGE>
      <SEX>F</SEX>
    </CHILD>
    <CHILD>
      <NAME>Daniel</NAME>
      <AGE>12</AGE>
      <SEX>M</SEX>
    </CHILD>
    <CHILD>
      <NAME>Nicholas</NAME>
      <AGE>10</AGE>
      <SEX>M</SEX>
    </CHILD>
  </CHILDREN>
</PARENT>

fm:attach

If you wanted to change the attach point so that it was attached to the CHILDREN element you could use the following code:

<fm:attach to=”/*/CHILDREN”/>

If you then did a set-out command, where the match attribute was simply “.”, FOX would set out the list of CHILD elements, because you are attached to the root of the list.

You could attach to one if the CHILD elements by using a predicate:

<fm:attach to=”/*/CHILDREN/CHILD[NAME='Lucy']”/>

This will attach to the CHILD element where the NAME is Lucy.

fm:call

Say you have 2 actions (Action 1 & Action 2) and you want Action 1 to call Action 2. You could use the following code within Action 1:

<fm:call action=”Action 2”/>

fm:copy

You could use the fm:copy command to copy the CHILDREN list above to another container elsewhere. The following code shows how you could copy the CHILDREN list to the Theme DOM:

<fm:copy from=”/*/CHILDREN” to=”:{theme}”/>

This would put the entire CHILDREN list and all the CHILD elements straight off the root in the THEME DOM.

fm:move

You could use the fm:move command to move the CHILDREN list above to another container elsewhere. The following code shows how you could move the CHILDREN list to the Theme DOM:

<fm:move from=”/*/CHILDREN” to=”:{theme}”/>

This would put the entire CHILDREN list and all the CHILD elements straight off the root in the Theme DOM and remove the CHILDREN list from the Data DOM.

fm:rename

If you wanted to rename an element, but still preserve the data within it, you could use the fm:rename command.

To rename the SEX element under the root PARENT to GENDER, you could use the following code:

<fm:rename match=”/*/SEX” rename-to=”GENDER”/>

You can also change the name of all the elements in a list by using the following command:

<fm:rename match=”/*/CHILDREN/CHILD/SEX” rename-to=”GENDER”/>

This will make the SEX element in all the CHILD nodes GENDER.

EXERCISES

For these exercises, you will need to use your XX_EMPLOYEEMODULE (where XX are your initials). All exercises should use a new namespace called “other”, while all actions should be set out as buttons in a menu-out displaying across the screen in exercise number order. All actions should be given relevant prompts.

Exercise 1

Create a new action named “action-attach” that attaches to the EMPLOYEE_LIST element. After clicking on the action, hovering over the Info item of the developer system menu will show you the current attach points.

Exercise 2

Create a new action named “action-call” that calls action-button.

Exercise 3

Create a new action named “action-copy” that copies the EMPLOYEE_LIST from the Theme DOM to the Data DOM. Look at the Data DOM and the Theme DOM, then run action-copy. Check the DOMs again. What changes can you see?

Exercise 4

Create a new action named “action-move” that moves the EMPLOYEE_LIST from the Theme DOM to the Data DOM. Look at the Data DOM and the Theme DOM, then run action-move. Check the DOMs again. What changes can you see?

Exercise 5

Create a new action named “action-rename” that renames all the FORENAME elements in the EMPLOYEE_LIST to FIRST_NAME. Look at the Data DOM and the Theme DOM, and then run action-rename. Check the DOMs again. What changes can you see?