XML Data Source

Applies to ReadyAPI 3.56, last modified on November 25, 2024

The XML data source fetches data from a property containing XML using the XPath expression. The data source parses the input XML content with XPath and populates the specified properties with the parsed values.

ReadyAPI cannot parse XML documents that contain the byte order mark (BOM) character.

You can use data sources of the XML type in the Data Source test step in functional tests. They are not available in virtual services.

In this topic, we focus on how to configure the XML data source. We assume you are already familiar with data-driven testing and how to configure a data-driven loop. Otherwise, please read Basic Concepts of Data-Driven Testing, or complete some of our tutorials before you continue.

Configuration

The XML data source

Click the image to enlarge it.

Source Step

Specifies a test step that contains the XML property to read from. For example, another data source or a SOAP Request test step.

Source Property

Specifies the name of the desired property that contains XML data.

Row XPath

The XPath expression that selects a set of elements for iteration. You can specify the path manually or click Declare icon and select the desired element from the Select Row XPath dialog. See the example below.

Make sure the XPath expression does not contain a predicate with the index of a particular element, otherwise, the XPath expression will return only one element. For example, the following XPath expression returns only the first book element in a set:
//store[1]/books[1]/book[1]

To select all the books, remove the predicate:

//store[1]/books[1]/book

Column XPaths

XPath expressions that return the desired property values. ReadyAPI applies these expressions to each element returned by the XPath expression specified in the Row Path.

The data source assigns data to the properties in the order they are listed in the Properties panel.

Make sure the number of properties is the same as the number of XPath expressions.

To add a new expression, click Add.

To change the selected expression manually, click Edit. Also, you can click declare icon and select the desired element from the Select Column XPath dialog.

To remove the selected expression, click Remove.

To learn how to specify Column XPaths, see the example below.

The following example demonstrates how to configure an XML data source:

1. Specify the source property

In the Source Step drop-down list, specify a test step whose property contains XML data. Specify this property in the Source Property drop down list.

For example, you can specify a SOAP Request test step, the response to which contains XML data:

2. Select data to iterate through

In Row XPath, specify an XPath expression that returns a set of elements for iteration.

Assume you have the following XML data:

XML

<store>
   <books>
      <book>
         <category>reference</category>
         <author>Nigel Rees</author>
         <title>Sayings of the Century</title>
         <price>
            <usd>8.95</usd>
            <euro>8.95</euro>
             <pound>7.95</pound>
         </price>
      </book>
      <book>
         <category>fiction</category>
         <author>Evelyn Waugh</author>
         <title>Sword of Honour</title>
         <price>
            <usd>12.99</usd>
            <euro>12.99</euro>
             <pound>11.99</pound>
         </price>
      </book>
      <book>
         <category>fiction</category>
         <author>Herman Melville</author>
         <title>Moby Dick</title>
         <isbn>0-553-21311-3</isbn>
         <price>
            <usd>8.99</usd>
            <euro>8.99</euro>
             <pound>7.99</pound>
         </price>
      </book>
      <book>
         <category>fiction</category>
         <author>J. R. R. Tolkien</author>
         <title>The Lord of the Rings</title>
         <isbn>0-395-19395-8</isbn>
         <price>
            <usd>22.99</usd>
            <euro>22.99</euro>
             <pound>20.99</pound>
         </price>
      </book>
   </books>
   <bicycle>
      <color>red</color>
      <price>
         <usd>19.95</usd>
         <euro>19.95</euro>
          <pound>17.95</pound>
      </price>
   </bicycle>
</store>

To get a list of books, specify the following XPath expression:

//store[1]/books[1]/book

You can specify the expression manually, or click Declare icon and select the needed element by using the Select Row Path dialog.

The Select Row Path dialog adds a predicate to the XPath. Remove it to select all the sibling elements.

Configuring XML data source: Specify Row XPath

Click the image to enlarge it.

3. Specify properties to obtain

  1. Click to add a new property.

    ReadyAPI will add a new column path to the list.

  2. If the name of the added property is the same as the name of the desired child element, most likely, there is no need to customize the added XPath. Otherwise, perform the following steps to modify the XPath:

    • Select the added column path in the list.

    • Specify the XPath expression that returns the desired element. Note that ReadyAPI will apply this expression to the set of elements returned by the Row XPath expression. For example, to get the price/usd element from the XPath data above, specify the following XPath expression:

      price[1]/usd[1]

      To specify the XPath expression, click Declare icon to use the Select Column XPath dialog:

      Configuring XML data source: Specify Column XPath

      Click the image to enlarge it.

      You can also click Edit and specify the expression manually.

  3. Repeat the first two steps to add other properties.

  4. Click to test the data source:

    Configuring XML data source: Run data source

    Click the image to enlarge it.

See Also

Data Source Test Step
Data Source Loop Test Step
Data Source Types

Highlight search results