XQuery Constructors in Mobile App Development
Developers are always looking for simpler and more efficient ways to create mobile apps and launch them into the world even faster. The recently-introduced Altova XQuery 3.1 Online Training covers XQuery constructors that developers can use like power tools for quicker mobile app development.
We recently used XQuery constructors to simplify one of our own mobile apps — the small app we created to demonstrate MobileTogether signature capture functionality. In that app, signatures of multiple users are saved in a single XML file, along with metadata about each mobile device used for capture. Later, the signatures and metadata can be reviewed on other devices.
The original app uses an Action Group to save each new signature in the file. The screenshot below shows the Save Signature Action Group in the MobileTogether Action Groups dialog:
The original action group first appended a new, empty signature data structure as the last node, then applied a series of Update Node actions to record the most recent captured signature.
This entire set of actions can be replaced by a single XQuery constructor expression to build the complete signature data structure, as seen below:
The XQuery constructor replaces eight actions with one. It is also much more efficient by building the entire signature data structure on the fly, eliminating any need to create and save an original empty data structure in the first place.
Inspecting Constructor Results
The Page Sources window in the MobileTogether Simulator lets us see what the XQuery constructor builds as the app executes:
The XQuery constructor expression uses a combination of direct and computed XQuery element constructors. (For a quick refresher on direct and computed XQuery constructors, refer to Chapter 3 of the Altova Online XQuery Tutorial and Training Course.)
Implement Enhancements Efficiently
XQuery constructors can also make it easier to revise or enhance a mobile app. For example, our signature collection app might be improved by recording the date each signature is captured.
We can open the XQuery constructor expression in the XPath/XQuery Expression Editor by clicking it in the Action Groups dialog, then insert a new constructor to record the date:
Since there is no separate model of the signature data structure anywhere in the app, nothing else needs to be revised.
Returning to the Page Sources window in the MobileTogether Simulator, we can see the new XQuery constructor result. For a deeper look, the right-click context menu even opens the XML structure in XMLSpy:
Download the free MobileTogether Designer to start building your own cross-platform mobile apps with XQuery constructors in record time. An updated version of the signature demo app described in this post is available on GitHub with more Altova examples at: https://github.com/altova