• 2.0.0

Managing XML Responses

When your HTTP Response contains an XML document, it is convenient to use XmlResponse decorator to manipulate it, for example:

String name = new JdkRequest("http://my.example.com")
  .fetch()
  .as(XmlResponse.class)
  .assertXPath("/data/name") // AssertionError if this XPath is absent
  .xml() // convert HTTP body to com.jcabi.xml.XML
  .xpath("/data/name/text()").get(0);

Method XmlResponse#xml() converts HTTP body to an instance of class XML from jcabi-xml project.

Don't forget to add this dependency to your classpath:

<dependency>
  <groupId>com.jcabi</groupId>
  <artifactId>jcabi-xml</artifactId>
  <version>0.6</version>
</dependency>

Read also about RestResponse, which helps you to manage default HTTP response concepts.