Altova XMLSpy 2023 Professional Edition

Debugging the Expression

Home Prev Top Next

The Debug Mode of the XPath/XQuery Window (screenshot below) enables you to debug an XPath/XQuery expression in the context of the active file.


In Debug Mode, two additional panes are added to the Results pane (see screenshot below):


the Call Stack and Debug Points pane, each of which has a separate tab in the pane

the Variables and Watch Expressions pane; both watch expressions and variables are shown in the same pane.


The Expression and Result panes can adjoin each other horizontally or vertically. To switch between these layouts, click the Horizontal/Vertical Layout button (at top right of the window's toolbar).


Debugger Mode offers the following features:


Enables you to step into the XPath evaluation process, one step at a time to see how the XPath expression is being evaluated. Use the Step Into (F11) toolbar button for this. At each evaluation step, the part of the expression being currently evaluated is highlighted in yellow (see screenshot above), while the result of evaluating that step is shown in the Results pane. For example, in the screenshot above, all the section descendant elements of the book element have been selected.

Set breakpoints where you want to pause the evaluation and check results at these points. You can step through the evaluation by pausing only at breakpoints. Use the Start Debugging (F5) toolbar button for this. This is quicker than pausing at every step with Step Into (F11).

Set tracepoints to see a report of results at the steps marked as tracepoints. The evaluation will not pause (except at breakpoints), but the tracepoint results will be displayed in a list in the Results pane.

Watch expressions can be used to check information (such as document data or aspects of the evaluation). This is especially useful at breakpoints.

Variables that are in scope, including their values, are displayed in the Variables and Watch Expressions pane.

Processor calls of an evaluation step are shown in the Call Stack tab of the Call Stack and Debug Points pane.

If breakpoints and tracepoints have been set, then these are displayed in the Debug Points tab of the Call Stack and Debug Points pane.


For more information about these features, see their descriptions below.


Setting up Debug Mode

To switch to Debug Mode, click Start Debugging in the dropdown menu of the Start Evaluation/Debugging (F5) command (located at top left of the toolbar; see screenshot below). When in Debug Mode, the Watch Expressions pane and Call Stack and Debug Points pane will appear. To start debugging the current expression, click Start Debugging or F5.


Note that Debug Mode works only with the current file; it cannot be used with multiple files. As a result, the Where option will automatically be set to Current File when you switch to this mode.



Running the Debugger

The broad steps for debugging an XPath/XQuery expression are, typically, as follows:


1.Make the XML/JSON file on which you wish to run the expression the active file.

2.Enter the XPath/XQuery expression in the expression pane.

3.Set any breakpoints or tracepoints you want. A breakpoint is a point at which the evaluation is paused. A tracepoint is a point in the evaluation that is recorded; tracepoints thus provide a traceable path of evaluation results.

4.If you click Start Debugger, evaluation is carried out in one step to the end unless a breakpoint has been marked in the expression. Click Start Debugger repeatedly to progress through each breakpoint to the end of the evaluation.

5.Use the Step Into/Out/Over functionality to go step-by-step through the evaluation.



Stepping in, out, and over evaluation steps

The Step Into functionality enables you to go step-by-step through the evaluation. Each click of this command takes you through the next step of the evaluation; the current step is shown by the highlighting in the expression (see screenshot below). The Step Out functionality takes you to a step on a higher level as the current step, whereas the Step Over functionality steps over lower-level steps and takes you to the next step on the same level. You can try out the Stepping functionality by pasting the XQuery 3.1 expression given below into the Expression pane and clicking the three Step buttons to see how they work.




The screenshot below shows the evaluation when processing has been paused on reaching the addition step \$a + \$b during the first pass through the loop—that is, when \$i=1. At this addition step, the result shows 3 (as a consequence of 1+2).




Breakpoints are points where you want the Debugger to stop after it has been started with Start Debugger. They are useful if you wish to analyze a specific part of the expression. When the Debugger stops at the breakpoint, you can check the result and could then use the Step Into functionality to display the results of the next steps of the evaluation. To set a breakpoint, place the cursor in the expression at the point where you want the breakpoint, and click the Insert/Remove Breakpoint (F9) toolbar button. The breakpoint will be marked with a dashed red overline. To remove a breakpoint, select it and click Insert/Remove Breakpoint (F9).


Also see Debug Points below.



Tracepoints are points at which the results are recorded. These results are displayed in the Traces tree of the Result tab (see screenshot below). This enables you to see all the evaluation results of particular parts of the expression. For example, in the screenshot below, tracepoints have been set on \$a, \$b, and local:plus(\$i, \$i+1); the results at these tracepoints during the first iteration through the loop are shown in the Traces tree: \$a=1, \$b=2, and local:plus(\$i, \$i+1)=3.


To set a tracepoint, place the cursor at the point where you want the tracepoint, and click the toolbar button Insert/Remove Tracepoint (Shift+F9). The tracepoint will be marked with a dashed blue overline (see screenshot below). To remove a tracepoint, select it and click Insert/Remove Tracepoint (F9).

Note:If both a breakpoint and a tracepoint are set on a part of the expression, then the overline is composed of alternating red and blue dashes.


Also see Debug Points below.


Variables, Watch Expressions, and Call Stack

Variables and watch expressions are displayed in the Variables and Watch Expressions pane (bottom center pane in the screenshot below).

Click to expand/collapse


Variables that have been declared in the expression and that are in scope in the current evaluation step will be displayed together with their respective current values. For example, in the screenshot above, processing has just reached the call to the local:plus function. The \$i variable is in scope within the local:loop function and has just been incremented to 2. So \$i is displayed with its current value. The \$a and \$b variables are not in local:loop and are therefore not in scope; consequently, they are not displayed.


Watch expressions

Watch expressions are expressions that you can enter, either before evaluation starts or during a pause in evaluation. They can be used for the following purposes:


To test specific conditions. For example in the screenshot above, the watch expression \$i=1 to 5 is used to test whether the \$i variable has a value in the given range. The result true tells us that this condition has been met.

To find data within a certain context. For example, within the context of a Company element, we could enter a watch expression @id to look up that company's customer code in the target XML document.

To generate additional data. For example in the screenshot above, the watch expression if (\$i=1 to 5) then (concat("Iteration ", \$i)) else "Out of Loop" can generate a suitable string to indicate in which iteration of the loop the evaluation currently is.


To enter a watch expression, click Add Watch Entry in the pane's toolbar (encircled in red in the screenshot above), then enter the expression and click Enter when done. To remove a watch expression, select it and click Remove Selected Watch Entry in the toolbar. If, during debugging, the expression cannot be correctly evaluated for some reason (for example, if one of its variables is out of scope), then the watch expression turns red.


Call stack

The Call Stack tab of the Call Stack and Debug Points pane (bottom right pane in the screenshot above) displays the processor calls up to that point in the debugging. The current processor call is highlighted in yellow. Note that only the calls that directly led to the current evaluation step are displayed. For example, in the screenshot above, the current evaluation step is a function call to the local:plus function. Now, although this is the second iteration of local:loop, the processor calls of the first iteration are not displayed. This is because those calls are on a parallel level to the current function call and did not lead to it.


Debug points

The Debug Points tab of the Call Stack and Debug Points pane (bottom right pane in the screenshot below) shows the breakpoints (with red circles) and tracepoints (blue circles) that you have set on the expression. Each debug point is listed with its line and character number. For example, FunctionCall@7:13 means that there is a debug point on line 7, character 13.


Note the following features:


For breakpoints, you can enter a break condition by double-clicking Enter break condition, entering the expression for the condition, and pressing Enter. That breakpoint will be enabled only when the condition evaluates to true. For example, in the screenshot above, the break condition \$i=3 will enable the breakpoint on this function-call only when the value of \$i is 3. The screenshot shows the evaluation paused at this breakpoint.

You can enable/disable all debug points by clicking their respective toolbar buttons: Enable All Debug Points and Disable All Debug Points (buttons encircled in green in the screenshot above). When a debug point is disabled, it is deactivated for all evaluations till it is enabled again.

You can enable/disable individual breakpoints in their respective context menus.


Toolbar commands in panes

The panes of the XPath/XQuery window in Debug Mode (see screenshot above) contain buttons that provide navigation, search, and copy functionality. These buttons, starting from the left, are described in the table below. The corresponding commands are also available in the context menu of listed items.




What it does

Next, Previous

Selects, respectively, the next and previous item in the result list

Copy the selected text line to the clipboard

Copies the value column of the selected result item to the clipboard. To copy all columns, toggle on the Copying includes all columns command (see below)

Copy all messages to the clipboard

Copies the value column of all result items to the clipboard, including empty values. Each item is copied as a separate line

Copying includes all columns

Switches between copying (i) all columns, or (ii) only the value column. The column separator is a single space


Opens a Find dialog to search for any string, including special characters, in the result list

Find previous

Finds the previous occurrence of the term that was last entered in the Find dialog

Find next

Finds the next occurrence of the term that was last entered in the Find dialog


Clears the result list

Collapse multi-line results to a single line

If the value column of a result item contains multi-line text (text that includes newline character/s), you can toggle between a multi-line and single-line display

Show complete result

Shows the entire content of nodes as the value of the node

Show header in output

Shows the location of the XML file/s and the XPath expression


© 2016-2022 Altova GmbH