Skip navigation

XPath Reference

Databinding lets you associate dynamic content stored in an XML source object with a graphical element. Databinding uses the expression language XPath. An XPath expression uses a syntax based on the XPointer specification:

'xpath(' ( _xml-object_ | _node_ ) '#' _xpath-expression_ ')'

Xml Objects are created as the result of an XmlService or SoapService call. The following <httprequest> tag gets the ATOM feed from the site www.mobuser.com and stores it in an Xml Ojbect called "news"

<httprequest id="getNews" url="http://www.mobuser.com/atom.xml" onLoaded="news = new Xml(this.response)"/>

You can then use databinding to bind the news object to a graphical item, such as a banner title:

<textbox>bind{xpath(news#/feed/title/text())}</textbox>

You can use XPath to produce a node list, and then iterate over that node list to create a dynamic list of graphical elements. In the previous example, where an ATOM feed is returned from an XML service call, you can construct a <box> with <textbox> tags for each headline in the feed. To do this, use two XPath expressions. The first XPath expression (e.g., xpath(news#/rss/channel/item)) selects all the items from the feed and returns the results as an array of Node objects. Use the array of Node objects in a <box> tag to iterate over each Node object and assign the Node object in each iteration to the variable item:

<box layout="vertical">
<foreach var="item" items="xpath(news#/rss/channel/item)">
  <textbox>once{xpath(item#@title)}</textbox>
</foreach>
</box>

A second expression (e.g., xpath(item#@title)) selects the title attribute relative to the Node object assigned to the variable item in each iteration of the loop.

MIL supports the major features of the XPath 1.0 Specification. Exceptions are noted here. 

AbbreviatedStep and AbbreviatedLocationPath

MIL does not support AbbreviatedStep or AbbreviatedLocationPath (also known as the
"//" syntax) because of caching issues on the mobile device platform.

AxisNames

Name Abbrev Supported
ancestor   No
ancestor-or-self   No
attribute @ Yes
child / Yes
descendant   No
descendant-or-self   No
following   No
following-sibling   No
namespace   No
parent .. No
preceding   No
preceding-sibling   No
self . Yes

Expressions

Name Example Supported
AdditiveExpr $x + 1 Yes
AndExpr $x > 3 and $x < 8 Yes
OrExpr @name or @address Yes
MultiplicativeExpr $x * 2, $x mod 2, $x div 3 Yes
EqualityExpr $x = 'foo', $x != 3 Yes

Digits

MIL does not support float (e.g. decimal) digits, due to the nature of mobile devices.

Functions

MIL supports a subset of the functions available within the XPath specification because many duplicate functions are available via MILScript. Only XPath functions that are not otherwise achievable via MILScript are supported.

TODO Determine which functions from the official XPath Specification to support.

Adaptavist Theme Builder Powered by Atlassian Confluence