XPath Function


$XPath function in WAPT supports all features of XML Path Language. In particular, you can use it to select nodes or node-sets in the XML document by specifying some path expression. The node is selected by following the specified path through the document.

Follow the steps below to add a new variable calculated as a result of $XPath function.

Click the Add button in the list of variables displayed on the Response processing tab of request properties.



This button opens the Add Variable dialog where you can create a new variable and select a function for its calculation. Enter the name of new variable and click the Add button to add a function.



You will see the Add Function dialog where you should enter function properties.

Type: Select XPath as function type.

XPath: Here you should enter the sequence of opening tags that stand before a desired node or node-set in the XML document. This sequence can contain variables. Use $Var(var-name) function to insert the necessary variables in the path expression. Enter the $ sign in the XPath field and you will see a prompt with the list of available variables (defined on the previous pages). Select a desired variable in the list to insert it in the path expression.

Only value: Leave this option unchecked if you wish to select the desired node together with the opening and closing tags. If you need to receive only value (without the opening and closing tags), you should check this option.

Click OK. Now you can insert the newly created variable in the XML code of subsequent requests.

The Syntax of XPath Function


$XPath function has the following syntax:

$XPath({path})

Here path is the sequence of opening tags that stand before the desired node or node-set.
In this case the desired node will be selected together with the opening and closing tags.

$XPath({path},1)

In this case the same node will be selected without the opening and closing tags.

Example of Usage


Example 1.

Suppose that the body of server response to some request is the following XML document:



And you define a variable xp equal to

$XPath(/AMF/Messages/Message/Value/MessageHeaders/Properties/Property[2]/Value)

to get the content of Value node from this XML document.



In this example, there are 2 properties inside the <properties> node. If you want to select the first property, you should specify Property[1] in path expression. To select the second property, specify Property[2].

As a result, the xp variable will be equal to

<Value type="String" version="3">85F63E4E-131F-0730-446F-44C56419B2C4</Value>

Example 2.

In the previous example you can define $XPath function in the following way:

$XPath(/AMF/Messages/Message/Value/MessageHeaders/Properties/Property[2]/Value,1)

In this case the option Only value is turned on in function properties:



As a result, the xp variable will be equal to

85F63E4E-131F-0730-446F-44C56419B2C4

You can test the work of $XPath function by clicking the Test button. You will see the result of function work on the basis of recorded server response (received during the recording process).

Next page