Section - 3 : Using the XML Path Locator


The XMLFind function is called the DAL XML path locator or DAL XPath. It is a limited version of the XML path and does not cover all aspects defined in the W3C literature.

Refer to W3C recommendations for the description of XPointer and XPath syntax. You can use the XPATHW32 testing tool to verify the applicable specifications of Skywire Software’s DAL XPath. Run the XPATHW32 program to get the syntax.

Below is a summary of XML path specifications for DAL XPath:

Axes

These axes apply:

ancestor    |    ancestor-or-self     |   attribute

child            |    descendant            |    descendant-or-self

following    |    following-sibling    |    parent

preceding  |    preceding-sibling  |   self

Function calls

You can use these function calls:

last()        |      position()             |      node()

text()        |   name(node-set)   |      string(object)

concat(string, string, string…)

Operators or signs

You can use these operators or signs:

=    !    =     <     >     +     -     /     //     *     ::     [ ]

Expressions

You can use abbreviated syntax, as this table shows:

For... Use this abbreviation:
child::* *
child::para para
child::chapter/child::para chapter/para
child::para[position()=1] para[1]
/child::chapter/child::para[position()=last()] /chapter/para[last()]
child::text() text()
child::node() node()
child::para[attribute::type] para[@type]
child::para[attribute::type="warning"] para[@type="warning"]
child::para[attribute::type="warning"][position()=2] para[@type="warning"][2]
child::chapter[child::title] chapter[title]
child::chapter[child::title="Introduction"] chapter[title="Introduction"]
child::doc/descendant-or-self::node()/child::para doc//para
attribute::* @*
attribute::type @type
/descendant-or-self::node()/child::para //para
self::node() .
self::node/descendant-or-self::node()/child::para .//para
parent::node() ..
parent::node()/child::chapter ../chapter
parent::node()/attribute::type ../@type

XMLFind locates the XML path from the extract XML tree and returns a valid DAL variable result. It requires three input parameters, a list type DAL variable and two string type variables. They in turn pass in an XML tree, a node name from which the search starts, and XML path location for searching.

If you omit the second parameter, the search starts from the root. The return DAL variable Result can be either list type or string type, depending on XML path.

Here are some examples that result in different return values:

Element list

%elemListH=XMLFind(%extract, , “descendant::Form[@ID=Agent]”);

In this example, DAL XPath selects the Form element descendants that have an attribute with name ID and value Agent from the extract XML tree (root), and returns an element list.

Attribute list

%attrListH=XMLFind(%extract, “Forms”, “Form/@type=’warning’”);

In this example, DAL XPath returns an attribute list that collects type attributes with value warning for Form children of current context node Forms.

Text list

%TextListH= XMLFind(%extract, “Forms”, “Form/text()”);

In this example, DAL XPath returns a text list that contains all text nodes of Form children of current context node Forms.

Text string

aStr=XMLFind(%extract, Forms, “string(Form[2])”);

It returns the text of second child Form of the current context node Forms.

aStr=XMLFind(%extract, “Forms”, “concat(“Get form 2 text: ”, “Form[2])”);

It returns the concatenation of the text string Get form 2 text: , and the text of the second child Form of current context node Forms.

aStr=XMLFind(%extract, “Forms”, “name()”);

It returns the name of current context node.