Skip to content
CodeKruPro

Extract values from an XML response

Automation taskMediumJava onlyAsked in: Accenture

"Have you tested SOAP or XML services?" This lesson shows that REST Assured reads XML with paths, much as it reads JSON.

Extract from XML with XmlPath

Extract from XML with XmlPath

REST Assured provides XmlPath for XML extraction, similar to JsonPath for JSON:

XmlPath xmlPath = response.xmlPath();
String title = xmlPath.getString("library.book[2].title");  // third book's title

The path follows GPath syntax where elements are separated by dots and arrays use index notation.

Task: Extract the first user's name and email from the XML response.

Expected output:

Name: John Doe
Email: john@example.com