Altova MobileTogether Designer

Update Node(s)

Home Prev Top Next

The Update Node(s) action updates one or more specified nodes with the specified value. Both the update node and update value are specified with XPath expressions. In the screenshot below, the @Updated attribute node of the XPath context element is updated with the current date (the result of evaluating the XPath function current-date-no-TZ()).

MTDUpdateNode01

There are a few points to note when specifying the update node/s and update value/s:

 

Importance of context node for relative paths. (See below for details).

The target node for the update can be referenced with the $MT_TargetNode variable. (See below for details).

If the source node is an element with mixed content (text and elements), then only the text content of the mixed-content element is used for the update. The text content of descendant elements is ignored. (See below for details).

Multiple target nodes can be specified via an array. (See below for details).

 

Importance of context node for relative paths

If the node to be updated is specified as a relative path, then only those nodes are updated that are descendants of the context node. To update a descendant node of sibling elements, an absolute locator path will need to be used. This is explained in more detail below.

 

In the screenshot below, notice that the context node (indicated in the Context field) is the Row element of the DB. The context node is the node within which the control (for which the action is being defined) is located (or with which the control is associated).

The @Updated attribute that will be updated is therefore the @Updated attribute of that particular Row element. What this means is that when a Row element's control event is triggered, then the @Updated attribute of only that Row element is updated, in this case with the current date.

Click to expand/collapse

If the XPath expression were changed so that it addressed the @Updated node starting from the root node (like this, and as in the screenshot below: $DB2/DB/RowSet/Row/@Updated), then the @Updated node of all Row elements would be updated.

Click to expand/collapse

Notice from the screenshot above, that you have access via XPath expressions to all the nodes of all page sources.

 

Referencing the specified target node with $MT_TargetNode

After a target node for the update is defined, you can reference this node with the variable $MT_TargetNode. For example:
 
Update Node : @Updated
Update Value: concat(current-date-no-TZ(), '-ID-', $MT_TargetNode/../@id)

 

would give an update value that would have the @id attribute value of the current Row element suffixed to the current date, as in the screenshot below.

MTDUpdateNodeXP03

Now, if the update nodes were the @Updated attributes of all Row elements, and the XPath expression for the update value were the same as in the previous example:
 
Update Node : $DB2/DB/RowSet/Row/@Updated
Update Value: concat(current-date-no-TZ(), '-ID-', $MT_TargetNode/../@id)

 

then the @Updated attribute of each Row element would have a value that would have the @id attribute value of its own Row element suffixed to the current date.

 

Modifying and updating nodes with $MT_TargetNode

The $MT_TargetNode variable can be very useful if you want to modify and update nodes in one joint action. An example is shown in the screenshot below.

MTDUpdateNodeMTTargetNode

The action in the screenshot works as follows:

 

The nodes to update are all the attributes of the current element. These nodes are specified by the XPath expression of Update Node(s): @*

As each attribute is processed it becomes the subject of $MT_TargetNode

The Result setting specifies the updated value of the node, which, in the example above, is the original value of the attribute (obtained via $MT_TargetNode)—modified in that its leading and trailing spaces are removed by the trim-string XPath function.

The overall result is that each attribute will have any leading or trailing spaces removed

 

Source elements with mixed content

If an element with mixed content (text and element/s) is located with an XPath locator expression, then the text content of the mixed-content element only is returned. The text content of descendant elements is ignored.

 

This is best explained with an example of the Update Node(s) action. Consider the Update Node(s) action defined in the screenshot below.

XPathMixedElementNonCompliance

If the XML tree had the following structure and content:

 

<Element1>

   <source>AAA

      <subsource>BBB</subsource>

  </source>

  <target></target>

</Element1>

 

Then the target element would be updated with the text content of the mixed-content element source, while ignoring the content of its child element subsource. The node named target will be updated to <target>AAA</target>.

 

Note:If you wish to include the text content of descendant node/s, use a string function. Using the XML example above, for instance, the expression string($XML1/Element1/source, '') will return "AAABBB".

 

Note:Charts use the XPath compliant method of serializing: When a mixed-content element is located using an XPath locator expression, then the text content of descendant elements is also serialized.

 

Updating multiple nodes via XPath arrays

You can update multiple nodes (the target nodes) by locating these nodes via an XPath array. The update values must then also be submitted as an array, one which has the same size as the target-node array. The update happens 1:1 and member-wise: the first member of the value array updates the first member of the target array, and so on. For example:

 

Update Node : $XML1/User/Message/[@subject, @date, @senderID]
Update Value: ['Monthly Meeting June', '2018-05-31', 3485]

 

Note the following points:

 

The $MT_TargetNode variable is set to the array that identifies the target nodes. You can check whether the variable contains an array as follows: if($MT_TargetNode instance of array(*)) then...  

The evaluation and mapping of the arrays are carried out first; the assignments are executed as a group subsequently. This means that the value of a target node can be used as an input.

Each member of the target array is handled separately. As a result, even if one member of the target array produces an error (either itself or while its value was evaluated), the updates of other target nodes will continue. Appropriate error messages, however, are generated.

 

MobileTogether extension functions

MobileTogether provides a range of XPath extension functions that have been specifically created for use in MobileTogether designs. Some functions can be particularly useful with specific actions. For example, mt-available-languages() returns the languages in which the solution is available and could, for example, be used with the Message Box action. If a function is especially relevant to this action, it is listed below. For a full list of extension functions and their descriptions, see the topic MobileTogether Extension Functions.

 

© 2018-2024 Altova GmbH