XQuery Match

Applies to ReadyAPI 3.51, last modified on March 04, 2024

The XQuery Match assertion uses an XQuery expression to select content from the target property and compare the result with the value you expect.

This assertion works like the XPath Match assertion, except that it uses an XQuery expression to select the XML node to be checked instead of XPath. This leads to the following advantages:

  • You can select and merge nodes you need into one XML result.

  • You can put results in any order, creating assertions independent of the XML message item order.

This assertion applies only to requests and responses, bodies of which contain XML data.

Availability

This assertion is available in multiple ReadyAPI applications. Depending on the application, it validates the following data:

In... Checks... To learn more...
Functional tests The request or response body. See Working With Assertions in Functional Tests.
Security tests The response body. See Security Assertions.
Virtual services The request body. See Assertions in Virtual Services.

Create an assertion

Follow these steps:

Functional test: The Assertions panel

Click the image to enlarge it.

  1. Open a test step.

  2. Click Add assertion.

In the New Assertions dialog, search for the XQuery Match assertion or select it manually in the Property Content category.

Follow these steps:

Security tests: The Assertions panel

Click the image to enlarge it.

  1. Open a security test.

  2. Click Response Assertion next to any scan.

  3. Click in the Assertions panel

In the New Assertions dialog, search for the XQuery Match assertion or select it manually in the Property Content category.

Follow these steps:

Virtual service: The Assertions panel

Click the image to enlarge it.

  1. Open a virtual service.

  2. Open the Assertions drop-down panel.

  3. Click in the Assertions panel

In the New Assertions dialog, search for the XQuery Match assertion or select it manually in the Property Content category.

Setting up properties

  1. In the XQuery Expression edit box, specify the XPath expression you want to use for this search, or use the toolbar controls to create the expression automatically.

    To use the toolbar controls, run the request you are planning to use for the assertion at least once.
    ReadyAPI: Configuring the XQuery Match assertion

    Click the image to enlarge it.

    Click Namespace to get the last request or response namespace and declare it.

  2. In the Expected Result edit box, specify the value you are expecting to get. You can use the property expansion to point at a specific node.

    To get a value from the last response you have received (or the last request the virtual service has received), click Select From Current.

  3. If needed, use additional options to enhance the results you will get:

    Option Description
    Allow Wildcards Command the assertion to use an asterisk wildcard (*) for varying parts of the value.
    Note: If you do not select this option, the assertion will fail on dynamic values.
    Ignore Namespace Prefixes

    To avoid name conflicts, XML elements use prefixes. A prefix points to a namespace that is associated with an element. Typically, the namespaces are represented by URIs. When this option is disabled, the assertion compares both prefixes and corresponding URIs. If this option is enabled, the assertion compares actual URIs that are declared for each prefix, but ignores the prefix names.

    Example

    Ignore XML comments Skips XML comments during the comparison.
  4. To test your assertion on the last response you have received (or the last request the virtual service has received), click Test.

  • The following XQuery expression sorts the price subelements of the Result element in the ascending order:

    for $z in //item
    order by $z/id
    return <price>(data($z/price/text())}</price>
  • The following XQuery expression lists all users from the marketing department:

    //user[contains(LINE, "marketing")]
  • The following XQuery expression lists IDs and last names of all users:

    for $b in //user
    return <user> { $b/id } { $b/name/last } </user>

Add more assertions that validate the XML content:

See Also

Property Content Assertions
XPath Match Assertion

Highlight search results