Altova MobileTogether Designer

The XML Page Source

Home Prev Top Next

We need one XML page source ($XML1) to hold and structure the data that is needed for the design. We will use the XML file CityTimes.xml, which is structured into the following parts (see listing below):

 

The UTC element, which is updated with the UTC time via a SOAP request when the user presses a button (see listing below). This node is used to display the UTC time to the user.

The RefreshTime element (see listing below), which is designed to hold the time, in seconds, between automatic page refreshes. The user can select the value of this node.

The SelectCity element, which contains the details (Name, TimeZone, and Time) of the city that the user selects (see listing below). When the user selects a city from the dropdown list of a combo box, the SelectCity element's Name child element is updated with the name of the selected city. The SelectCity/TimeZone element is updated from the Cities database when the combo box selection is made, and SelectCity/TimeZone element is updated by the web service's response to the SOAP request that is sent when the user selects a city.

The Cities element is a database containing the details (Name, TimeZone, and Time) of selected cities (see listing below). (You can add more cities if you like.) The web service that we will be accessing requires a city's timezone in order to calculate and return the current time in the selected city. The database therefore must contain the timezone information. The Time child element of these City elements are used to hold a city's current time, which is obtained from the web service in response to a SOAP request. As with the UTC time above, the SOAP request is sent when the user presses a button (or selects a city in the combo box).

 

Short version of the XML page source CityTimes.xml, showing the document's structure

 

<CityTime xmlns="http://www.Nanonull.com/TimeService/">

 <UTC>12:00 AM</UTC>

 <RefreshTime>60</RefreshTime>

 <SelectCity>

         <City>

                 <Name>UTC Time</Name>

                 <TimeZone>GMT</TimeZone>

                 <Time>12:00 AM</Time>

         </City>

 </SelectCity>

 <Cities>

         <City>

                 <Name>Beijing</Name>

                 <TimeZone>UTC+8</TimeZone>

                 <Time>12:00 AM</Time>

         </City>

         ...

 </Cities>

 

 

 

 

Adding the XML page source

An XML page source ($XML1) that uses CityTimes.xml as its page source has been added to the design's page sources. The page sources was added as follows:

 

1.Click the Add Page Source icon in the Page Sources Pane (see screenshot above). Select New XML, HTML or JSON structure imported from file. Confirm the page source settings in the next screen (without changing the defaults) by clicking Finish.

MTDSOAPTutPageSources02XML

2.An Open dialog appears. Browse for the CityTimes.xml file (see location), and click Open. The $XML1 tree is created. It has the CityTimes.xml file set as its default file, and its XML tree has the structure of the default file.

 

Namespaces of nodes in the SOAP response and the XML tree

Nodes in the SOAP response from this particular web service are unprefixed and belong to the namespace: http://www.Nanonull.com/TimeService/. Therefore, one way to correctly target SOAP response nodes that are entered in the design's XPath expressions is to set the XPath default namespace to this namespace (screenshot below).

MTDSOAPTutPageSources03NS

Setting this namespace as the XPath default namespace means that all unprefixed nodes in the design's XPath expressions will be considered to be in this namespace. Now, if the nodes of the XML tree are also unprefixed (as is the case with our XML tree), and if these tree nodes are entered without prefixes in XPath expressions, then, in XPath expressions, these nodes will also be considered to be in the XPath default namespace: http://www.Nanonull.com/TimeService/.

 

Because of this we assign the namespace http://www.Nanonull.com/TimeService/ also to the nodes XML tree. If you look at the XML listing above, you will notice that the document's root element has been assigned to the namespace: .

 

<CityTime xmlns="http://www.Nanonull.com/TimeService/">

 

Since this namespace is in scope throughout the XML document and is not overridden by any namespace mapping on a descendant element, the namespace applies across the document.

Since the document's namespace declaration has no prefix, this namespace will be the default namespace of the XML document. As a result, nodes with unprefixed local names are in this namespace.

 

Note:If your XML document is in some namespace other than the namespace of SOAP response nodes, then it is best, in the XML document, to declare the document's namespace with a prefix. Then, in the design, make sure that this same prefix:namespace value has been correctly entered in the design's collection of namespaces. In the design's XPath expressions, you should use the declared prefix when referencing XML tree nodes. Alternatively, in XPath expressions, you could address a node with the star prefix, like this *:NodeName. This would match all nodes that have the local name NodeName, no matter in what namespace the node is.

 

© 2018-2024 Altova GmbH