Frequently Asked Questions

How it is different from XML Unit? 

XMLUnit provides programmatic assertions, whereas this library uses XML as one big assertion. XML Matcher also allows annotating XML with Javascript-based assertions.

Why can't we simply use DTD for XML validator?

DTD is very limited in a way one can define context-specific constraints. Imagine we have XML that captures directions.  We want to ensure that our template validates that we make exactly two left turns and then one right turn.
All we can constraint via DTD is the fact that turn can be either left or right.
<!ELEMENT turn ( left | right )>

Why can't we simply use XML Schema/XSD for XML validator?

XML Schema doesn't have convenient ways of constraining instances of XML types. For example, imagine that we have XML describing geographic location:
<xsd:complexType name="location">
      <xsd:element name="x" type="xsd:double"/>
      <xsd:element name="y" type="xsd:double"/>
XSD verifying that one particular occurence of location contains values close to given above could be written but will be too bulky.

How it is different from text file comparators?

Text-based comparison tools compare XML documents as plain text files, ignoring  XML specific things like:

What happens when two elements do not match?

It depends on context and current strategy. Matcher may skip elements that do not have vis-a-vis in template, and try matching with next template sibling. Matching fails when all possibilities become rejected.

Back to Main Page