Design Components
The design components are numbered in the screenshots below and are described in callouts further below. The screenshot at left shows the simulation, the screenshot at right shows the design. Click a callout to see a description of the corresponding design component.
When the Update UTC Time button is clicked at runtime, the OnButtonClicked event triggers two actions (see screenshot below). First, an Execute SOAP Request action sends a SOAP request for the UTC time to the web service. The SOAP response from the web service is stored in the $MT_HTTPExecute_Result variable (circled in blue in the screenshot below). Next, an Update Node action updates the $XML1/CityTime/UTC node with the UTC time. The content of this node is immediately displayed in a label (see Callout 2 below). The web service provides an operation (getUTCTime) that gets the current UTC time. To see how the SOAP request has been defined, click the Edit button of the Execute SOAP Request action (circled in red in the screenshot above). In the SOAP Request dialog that appears, the text of the SOAP request is shown in the Preview pane.
|
This label is associated with the page source node $XML1/CityTime/UTC (the label's page source link). Data from this node will be displayed in the label. Since the node $XML1/CityTime/UTC is updated when the Update UTC Time button is clicked (see Callout 1 above), the updated UTC time is immediately displayed in this label.
|
The purpose of the combo box is the following:
1.To display the names of the cities that are listed in the Cities element of the XML page source 2.When the user selects a city, to send a SOAP request for the current time in that city 3.To update all //Time and //Timezone nodes that are affected by the user selection (see the 'Update actions' in the screenshot below)
Selecting items in the dropdown list of the combo boxIn the design, double-click the combo box control to display the Edit Combo Box dialog. The items of the combo box dropdown list are the names of the cities in the Cities element of the XML page source. These city names are selected with the XPath expression $XML1/CityTime/Cities/City/Name. The XML value of these city names has been set to be the same as the text of the city name (the visible entry in the dropdown list of the combo box).
When the user selects a city in the combo box, the XML value of the selection (which is the same as combo box entry) is passed to the node $XML1/CityTime/SelectCity/City/Name. This is achieved by creating a page source link between the combo box and this XML tree node (and done by dragging-and-dropping the tree node from the Page Sources Pane onto the control).
Defining the SOAP request to get the current time of a cityDouble-click the Control Actions symbol at the top left of the combo box to open the Actions dialog of the combo box (screenshot below). An Execute SOAP Request action is defined for the OnFinishEditing event. The web service provides an operation (getTimeZoneTimeResult) that gets the current time of a specified timezone. The timezone for which the time is required is sent as a parameter of the SOAP request. To see how the SOAP request has been defined, click the Edit button of the Execute SOAP Request action (circled in red in the screenshot below). The SOAP Request dialog appears. In the SOAP Request dialog, the text of the SOAP request is shown in the Preview pane, the timezone parameter is shown in the Parameters pane. Click the parameter's XPath button to see the XPath expression that selects the value of the m:timezone parameter:
for $i in $XML1/CityTime/SelectCity/City/Name return $XML1//Cities/City/TimeZone[../Name=$i]
The XPath expression first selects the name of the city that the user has selected in the combo box, and stores this value in the expression's $i variable. The expression then goes on to select (from the Cities element of the XML page source) the Timezone element of the city that has a Name element that matches the value in $i. In this way, the timezone of the user-selected city is set as the m:timezone parameter of the SOAP request. On receiving this request, the web service will return the current time of the requested timezone.
Storing the SOAP response in a variable The SOAP response from the web service is stored in the $MT_HTTPExecute_Result variable (circled in blue in the screenshot above). Note that the entire SOAP response, which is an XML document, is stored in the variable. You will need to know the structure of the SOAP response in order to select the node containing the timezone time. In our case, the following XPath expression locates the timezone time in the stored SOAP response:
$MT_HTTPExecute_Result//getTimeZoneTimeResult
Note: The getTimeZoneTimeResult node is unprefixed in the SOAP response and it is in the http://www.Nanonull.com/TimeService/ namespace. The design's XPath default namespace was therefore changed to this namespace. If this is not done, the timezone time in the SOAP response can alternatively be accessed with the following XPath expression: $MT_HTTPExecute_Result//*:getTimeZoneTimeResult, which looks for the element node getTimeZoneTimeResult in any namespace. See also: Namespaces of Nodes in the SOAP Response and the XML Tree.
Updating nodes with the timezone time The Update Node action is used to update two XML tree nodes with the received timezone time: (i) $XML1/CityTime/SelectCity/City/Time, and (ii) $XML1/CityTime/Cities/City[Name=$XML1/CityTime/SelectCity/City/Name]/Time. The highlighted part in the second expression specifies that only that city in the Cities database should be updated that has a name that matches the name of the user-selected city. The content of these updated nodes are immediately displayed in labels via page source links (see Callouts 5 and 9 below). The value of the timezone time is obtained from the SOAP response via the $MT_HTTPExecute_Result variable.
Displaying the timezone of the selected city The Update Node action is used to update the $XML1/CityTime/SelectCity/City/TimeZone node. The value with which the node is updated is the content of the node selected with the expression: $XML1/CityTime/Cities/City[Name=$XML1/CityTime/SelectCity/City/Name]/Timezone. This expression selects the TimeZone element of that city in the Cities database that has a name that matches the name of the user-selected city. The content of the updated node is immediately displayed in an edit field via a page source link (see Callout 4 below).
|
This edit field is associated with the page source node $XML1/CityTime/SelectCity/City/TimeZone (the edit field's page source link). So, as soon as the user selects a city in the combo box, that city's timezone is displayed in the edit field. The chain of actions is as follows: When the user selects a city, the SelectCity//TimeZone node is updated (because of the Update action of the combo box; see Callout 3 above). Then, because the SelectCity//TimeZone node is the page source link of the edit field, the edit field automatically displays the updated value of the SelectCity//TimeZone node.
|
This label is associated with the page source node $XML1/CityTime/SelectCity/City/Time (the label's page source link). When the user selects a city in the combo box, (i) a SOAP request is sent for the current time in the timezone of that city, and (ii) the SelectCity//Time node is updated with the current time in that timezone (because of the Update action of the combo box; see Callout 3 above). The label then automatically displays the updated time because of the page source link to the updated SelectCity//Time node.
|
The cities in the Cities element of the XML page source are each defined in a City element. The City element has therefore been created as the repeating row in a table with three columns and dynamic rows. Each city is displayed in a row. The columns display, respectively, each city's name, timezone, and time. The controls used in the columns are, respectively, a button (with the city's Name element as its page source link), an edit field (with the city's Timezone element as its page source link), and a label (with the city's Time element as its page source link). See Callouts 7,8 and 9 below.
|
The button displays the name of the city by way of a page source link to the $XML1/CityTime/Cities/City/Name. At runtime, when the button of a city is clicked, then a SOAP request is sent to get that city's (timezone) time (see screenshot below). The value of the m:timezone parameter of the request is obtained from the city's TimeZone element. Since the context node is City, the XPath expression to fetch the city's timezone will be: TimeZone. The SOAP response is stored in the $MT_HTTPExecute_Result variable. Next, an Update Node action updates the $XML1/CityTime/Cities/City/Name node with the timezone time. The content of this updated node is immediately displayed in a label (see Callout 9 below). |
The edit field is associated with the XML node $XML1/CityTime/Cities/City/TimeZone (the edit field's page source link). The content of this node does not change.
|
The label is associated with the XML node $XML1/CityTime/Cities/City/Time (the label's page source link). Data from this node is displayed in the label as soon as the user clicks the corresponding City button (Callout 7 above). This is because (i) the button has an action to update this node (see Callout 7 above), and (ii) this node is the label's page source link.
|
Page actions
To view the page actions, right-click inside the page and select Page Actions. In the dialog that appears, three actions have been defined for the OnPageLoad event. These actions will be executed when the page loads. They provide data for the initial page display.
The following actions have been defined:
•Execute SOAP Request: The action requests the UTC time from the web service and stores the response in the $MT_HTTPExecute_Result variable. The request is defined in the same way as for the UTC Time button (Callout 1).
•Update Node: Updates the node $XML1/CityTime/UTC with the UTC time. Since this node is the page source link of the UTC Time label (Callout 2), the label will be initialized with the current UTC time.
•Update Node: Updates the node $XML1/CityTime/SelectCity/City/Time with the UTC time. Since the initial value of the selected city (SelectCity//Name) is UTC Time (see the XML file), we initialize the SelectCity//Time node with the current UTC time.