Package org.springframework.test.web.servlet.result

# Class XpathResultMatchers

java.lang.Object
org.springframework.test.web.servlet.result.XpathResultMatchers

public class XpathResultMatchers extends Object
Factory for assertions on the response content using XPath expressions.

An instance of this class is typically accessed via `MockMvcResultMatchers.xpath(java.lang.String, java.lang.Object...)`.

Since:
  3.2
Author:
  Rossen Stoyanchev

## Constructor Summary

Constructors
Modifier
Constructor
Description
`protected`
`XpathResultMatchers(String expression, Map<String,String> namespaces, Object... args)`
Protected constructor, not for direct instantiation.

## Method Summary

Modifier and Type
Method
Description
`ResultMatcher`
`booleanValue(Boolean value)`
Evaluate the XPath and assert the `Boolean` value found.
`ResultMatcher`
`doesNotExist()`
Evaluate the XPath and assert that content doesn't exist.
`ResultMatcher`
`exists()`
Evaluate the XPath and assert that content exists.
`ResultMatcher`
`node(Matcher<? super Node> matcher)`
Evaluate the XPath and assert the `Node` content found with the given Hamcrest `Matcher`.
`ResultMatcher`
`nodeCount(int expectedCount)`
Evaluate the XPath and assert the number of nodes found.
`ResultMatcher`
`nodeCount(Matcher<? super Integer> matcher)`
Evaluate the XPath and assert the number of nodes found with the given Hamcrest `Matcher`.
`ResultMatcher`
`nodeList(Matcher<? super NodeList> matcher)`
Evaluate the XPath and assert the `NodeList` content found with the given Hamcrest `Matcher`.
`ResultMatcher`
`number(Double expectedValue)`
Evaluate the XPath and assert the `Double` value found.
`ResultMatcher`
`number(Matcher<? super Double> matcher)`
Evaluate the XPath and assert the `Double` value found with the given Hamcrest `Matcher`.
`ResultMatcher`
`string(String expectedValue)`
Apply the XPath and assert the `String` value found.
`ResultMatcher`
`string(Matcher<? super String> matcher)`
Apply the XPath and assert the `String` value found with the given Hamcrest `Matcher`.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Constructor Details

### XpathResultMatchers

protected XpathResultMatchers(String expression, @Nullable Map<String,String> namespaces, Object... args) throws XPathExpressionException
Protected constructor, not for direct instantiation. Use `MockMvcResultMatchers.xpath(String, Object...)` or `MockMvcResultMatchers.xpath(String, Map, Object...)`.

Parameters:
  `expression` - the XPath expression
  `namespaces` - the XML namespaces referenced in the XPath expression, or `null`
  `args` - arguments to parameterize the XPath expression with using the formatting specifiers defined in `String.format(String, Object...)`
Throws:
  `XPathExpressionException`

## Method Details

### node

public ResultMatcher node(Matcher<? super Node> matcher)
Evaluate the XPath and assert the `Node` content found with the given Hamcrest `Matcher`.

### nodeList

public ResultMatcher nodeList(Matcher<? super NodeList> matcher)
Evaluate the XPath and assert the `NodeList` content found with the given Hamcrest `Matcher`.

Since:
  5.2.2

### exists

public ResultMatcher exists()
Evaluate the XPath and assert that content exists.

### doesNotExist

public ResultMatcher doesNotExist()
Evaluate the XPath and assert that content doesn't exist.

### nodeCount

public ResultMatcher nodeCount(Matcher<? super Integer> matcher)
Evaluate the XPath and assert the number of nodes found with the given Hamcrest `Matcher`.

### nodeCount

public ResultMatcher nodeCount(int expectedCount)
Evaluate the XPath and assert the number of nodes found.

### string

public ResultMatcher string(Matcher<? super String> matcher)
Apply the XPath and assert the `String` value found with the given Hamcrest `Matcher`.

### string

public ResultMatcher string(String expectedValue)
Apply the XPath and assert the `String` value found.

### number

public ResultMatcher number(Matcher<? super Double> matcher)
Evaluate the XPath and assert the `Double` value found with the given Hamcrest `Matcher`.

### number

public ResultMatcher number(Double expectedValue)
Evaluate the XPath and assert the `Double` value found.

### booleanValue

public ResultMatcher booleanValue(Boolean value)
Evaluate the XPath and assert the `Boolean` value found.