Friday, December 14, 2012

XML Data

You can use the XML data to create your application. The XModel part allows declaring the XML data that will be used in your application.
Using XML data you can:
  • structure the data using in application: XML is the ideal tool to organize the using data in the project; well organizing the data makes the creation, the evolution and the management of the project easier.
  • separate the data from the application, the data can be then updated and or modified easily. The separated XML data can be packaged within application or can be put on a web server as an external resource of application. In the case that XML data is used as the external resource, it could be updated/modified freely or event could be daily changed or generated dynamically from a data server that doesn’t request to recompile or to redeploy the application. See the NewYorkTimes sample enclosed in the JM-Mobile Editor (File->Open sample project ->NYTimes.eman).
  • apply the AJAX-like model: the application can make the request to the web services which can return the dynamic XML flux to the application.
List of JM-Mobile projects below are the good examples of the project using the XML data.
Dynamic menu Contact list 2 Contact list 2 CNN Podcast Mobile content search Contact list
To declare a XML data, you insert into the XModel part a XInstance element.
To specify a XML data source for the XInstance element using its FileName attribute: the XML data source can be a local or online XML file or an URL of a web service that can provide a XML data stream.
Each XInstance element has an identity Name, which will be used to access into the XML data. The formula to access into a XML data represented by a XInstance element is following: {$XPath:document( XInstance Name )/XPath}, in some particular case such as in an expression, you can use a simpler formula document( XInstance Name )/XPath
To access into the XML data you must use the XPath, there are only a common part of XPath supported.
The XPath functions supported are:
  • count(NodeSet): to get the total number of the nodes in a nodeset.
  • substring(string, start index, count): the substring function such as document(data)//item[substring(@title,1,1) = 'A'] get a nodeset containing the item elements of which the title attribute is begun with ‘A’. See Bosnalijek contact list sample enclosed with the JM-Mobile Editor for more detail.
  • boolean contains( string, string): the contains function returns true if the first argument string contains the second argument string, and otherwise returns false. By example you can use the template by XPath following document(nytimesItem)//item/title[contains(.,'$Var_content')]/.. to search the interested content from a Newyork time RSS category info. See the newyorktimes.eman sample enclosed with the JM-Mobile Editor for more detail.
Attention! The XML data source provided to the XInstance element must be the well-form XML data.
memoryManager attribute
The XInstance element has the memoryManager attribute that can tell the system free or keep the XML data in the heap memory each time the application is changed to another scene.
If the XML data is only used in a scene or some few scenes, it is recommended to use the free value. Otherwise if the XML data is the principal data for entire application then use keep value for the memoryManager attribute, the XML data will be always on the heap memory, the translation between the screens could be more fluid. However be really attention when using the keep value.
The free is default value.
Using XML Data
By example: The NewYorkTimes sample has a XInstance element named nytimesData representing the XML file following:

You can get the set of item nodes in this XmlInstance by using the following specification:
Where: nytimesData is the name of the XInstance element.
To get the total number of this node set of item, you can use the count function as following: count(document(nytimesData)//item)
A dynamic menu can be created by using a XMenuTemplate or DMenuTemplate with this node set of item.

In the newyorktime sample:
  • to represent all items of the RSS flux of the New York Time, it uses the XMenuTemplate named DynamicMenu_6659 of which the Content nodeSet attribute is specified to this node set of item as following document(nytimesData)//item (see the image on the right).
  • Then to show the title of the each item of the New York Time RSS flux on each the item menu, the Content cellTextValue attribute is set to {$XPath:title} that allow to access to the content of the title element of each item element.

Hint: the index number of the selected menu item of a XMenuTemplate or DMenuTemplate dynamic menu can be gotten by using the function index( menu name ). This function is used in the item detail scene to specify the selected item of the DynamicMenu_6659 dynamic menu. See the XMenuTemplate part of the user's guide for more information about this object.
On the item detail scene, see the image on the right, the content of the text title is specified as following:
Where: index(DynamicMenu_6659) is the index function to determine the number of the current selected item of the XML menu template (XMenuTemplate) identified as DynamicMenu_6659.
The selected item is the 5th item, the text title content is so World
Just under the text title there is another dynamic menu represents all articles of the World theme of the New York Time. This dynamic menu uses a XmlInstance of which the FileName attribute is variable following the selected item on the DynamicMenu_6659 dynamic menu, the FileName attribute is specified as following:
That means if the selected item of the DynamicMenu_6659 dynamic menu is the 5th item, the nytimesItem XmlInstance is then connected to:
The dynamic menu in this detail item scene is also a XMenuTemplate named DynamicMenu_15479 of which the nodeSet attribute is specified as following:

This specification will return all article of the selected theme. In fact on the New York Time there are many themes of which the number of the current articles could be great. So it will be great if in this scene there were a search content function. To do that the nodeSet attribute of the DynamicMenu_15479 menu could be specified as following:
where $searchContentVar is the variable containing the text content which we want to search for. The specification above will return a list of the item of which the title contains the value of the $searchContentVar variable. By example if the value of the$searchContentVar variable is Obama the dynamic menu could be found the articles as showing on the image on the right.

No comments:

Post a Comment