How do I parse and validate an XML response?
Loadster is a pretty good tool for load testing XML web services (SOAP, XML-RPC, some RESTful services, etc).
When you’re testing an XML web service, you want to make sure the responses coming back are valid XML with the right structure and data.
You can do this in Loadster with the “Validate with JavaScript” feature. Expand the Add… menu on the step you want to validate, and select Validate with JavaScript from the menu.
This type of validator lets you write a custom JavaScript function to evaluate the response.
To parse the XML, use the XML.parse
function. Since XML parsing is not standard in JavaScript the way
JSON parsing is, Loadster uses the xmldoc parser.
Validation functions are expected to return a boolean value: true
if the response is valid, and false
if it’s
invalid. In the above example, we’re only considering the response valid if the response is a valid XML document
with a top-level collection cars
that contains at least one car
element in it.
You can read more about validation in Loadster, and other types of validators, in Validation Rules.
XML parsing also works in Capturing Rules.