This topic explains how to configure and apply the XML Sort tool, which sorts XML recursively or by selected sort target and sort key nodes.
Sections include:
Many services return lists of results that are in a different order each time that the service is invoked. Such random ordering of elements can make it challenging to define validations in test cases. The XML Sort tool is designed to address this challenge. For example, it could be used to take the book items returned by the Parasoft Book Store service, reorder them by price, and sort the authors list lexicographically under each book item. |
The XML Sort tool can be chained to the output of other XML tools
, such as the SOAP Response of the SOAP Client |
. After you add the tool and define the desired sorting, it will output the XML content sorted according to the specified configuration. The sorted content can then be validated with XML Assertor, Diff, or other validation tools.
The Recursive XML sort option will sort all nodes recursively (e.g., to remove ordering prior to diffing). First, it sorts nodes by type: text nodes come first, then processing instructions, then elements. Element attributes are sorted first by name, then by value. Elements are sorted first by element name, then by attribute name/value, then by text content, and finally by child nodes using the same criteria. The order of text nodes relative to each other is not changed. Processing instructions are sorted by their target and data values.
The Custom XML sort allows you to define one or more sort instructions in this tool. If multiple sort instructions are defined, then the XML document will first be sorted according to the first instruction, then sorted again according to the second instruction, and so on. Each sort instruction is intended to sort a group of elements labeled as the “Sort Target”, and these target elements are sorted using the sort key criteria defined within the instruction.
To configure XML Sort:
If you did not perform step 1, there will be no way of knowing what the XML is expected to look like. In this case, you need to provide the XPath manually.
By default, an entry for using the target element text content as the key will be added.