Skip to content

Latest commit

 

History

History
60 lines (44 loc) · 2.52 KB

README.md

File metadata and controls

60 lines (44 loc) · 2.52 KB

EO principles respected here Managed by Zerocracy DevOps By Rultor.com

mvn PDD status Javadoc Maven Central codecov

More details are here: matchers.jcabi.com. Also, read this blog post: XML/XPath Matchers for Hamcrest.

The library contains a collection of convenient Hamcrest matchers. For example:

import com.jcabi.matchers.XhtmlMatchers;
import org.hamcrest.MatcherAssert;

MatcherAssert.assertThat(
  "<test><name>Jeff</name></test>",
  XhtmlMatchers.hasXPath("/test/name[.='Jeff']")
);

To match XHTML documents you need to specify namespaces in your XPath expressions:

MatcherAssert.assertThat(
  "<!DOCTYPE html><html xmlns='http://www.w3.org/1999/xhtml'><body>Hello, world!</body></html>",
  XhtmlMatchers.hasXPath("/xhtml:html/xhtml:body[.='Hello, world!']")
);

Here, we use xhtml predefined namespace. There are also xsl, xs, xsi, and svg namespaces provided off-the-shelf. However, you can define your own too, for example:

MatcherAssert.assertThat(
  "<foo xmlns='my-own-namespace'><bar/></foo>",
  XhtmlMatchers.hasXPath("/ns1:foo/ns1:bar", "my-own-namespace")
);

Here, my-own-namespace is called ns1 inside the XPath expression.

How to contribute?

Fork the repository, make changes, submit a pull request. We promise to review your changes same day and apply to the master branch, if they look correct.

Please run Maven build before submitting a pull request:

$ mvn clean install -Pqulice