Enum Class EqualToXmlPattern.NamespaceAwareness

java.lang.Object
java.lang.Enum<EqualToXmlPattern.NamespaceAwareness>
com.github.tomakehurst.wiremock.matching.EqualToXmlPattern.NamespaceAwareness
All Implemented Interfaces:
Serializable, Comparable<EqualToXmlPattern.NamespaceAwareness>, Constable
Enclosing class:
EqualToXmlPattern

public static enum EqualToXmlPattern.NamespaceAwareness extends Enum<EqualToXmlPattern.NamespaceAwareness>
This enum represents how the pattern will treat XML namespaces when matching.

LEGACY represents the old way that namespaces were treated. This had a lot of unpredictability and some behaviours were more of a side effect of other implementation details, rather than intentional. A key detail is that the original DocumentBuilderFactory was not namespace aware, but the XSLT transform performed by DiffBuilder.ignoreComments() seems to return a document that is semi-namespace aware, so some namespace aware functionality was available. Now DiffBuilder.ignoreComments() has been replaced by setting the DocumentBuilderFactory to ignore comment on read (much more performant and predictable), so is only used to produce the legacy namespace aware behaviour.

STRICT and NONE represent firmer, more intentional behaviour around how namespaces are handled. The details of how each option behaves are documented below:

LEGACY behaviour:

  • Namespace prefixes do not need to be bound to a namespace URI.
  • Element namespace prefixes (and their corresponding namespace URIs) are ignored (e.g. `<th:thing>Match this</th:thing>` == `<st:thing>Match this</st:thing>`)
    • Element prefixes seem to effectively be totally removed from the document by the XSLT transform performed by DiffBuilder.ignoreComments() (and no namespace URI is assigned to the element).
  • Attributes are compared by their full name (i.e. namespace prefixes are NOT ignored) (e.g. `<thing th:attr="abc">Match this</thing>` != `<thing st:attr="abc">Match this</thing>`)
    • The XSLT transform performed by DiffBuilder.ignoreComments() does not assign a namespace URI to attributes, so XMLUnit uses the attribute's full name.
  • xmlns namespaced attributes are ignored (e.g. `<thing xmlns:th="https://thing.com">Match this</thing>` == `<thing xmlns:st="https://stuff.com">Match this</thing>`)
    • XMLUnit ignores all attributes namespaced to http://www.w3.org/2000/xmlns/, which all xmlns prefixed attributes are assigned to by the XSLT transform performed by DiffBuilder.ignoreComments().
  • Element default namespace attributes (i.e. `xmlns` attributes) are NOT ignored unless NAMESPACE_URI comparison type is explicitly excluded (e.g. `<thing xmlns="https://thing.com">Match this</thing>` != `<thing xmlns="https://stuff.com">Match this</thing>`)
    • Like xmlns namespaced attributes, XMLUnit ignores all attributes namespaced to http://www.w3.org/2000/xmlns/, which all xmlns attributes are assigned to by the XSLT transform performed by DiffBuilder.ignoreComments().
    • The difference between default xmlns attributes and xmlns prefixed attributes is that the XSLT transform performed by DiffBuilder.ignoreComments() assigns the namespace URI of default xmlns attributes to the attributed element, which is why matching will fail (unless NAMESPACE_URI comparison type is explicitly excluded).

STRICT behaviour:

  • Namespace prefixes need to be bound to a namespace URI.
  • Element and attribute namespace URIs are compared, but their prefixes are ignored.
    • Namespace URIs can be explicitly excluded. Although, due to how XMLUnit's engine is implemented, excluding NAMESPACE_URI does not work with attributes (see XMLUnit issue).
  • The namespaces defined by xmlns namespaced attributes are compared, but the attributes themselves are ignored (e.g. `<thing xmlns:th="https://thing.com">Match this</thing>` == `<thing xmlns:st="https://stuff.com">Match this</thing>`)
    • XMLUnit ignores all attributes namespaced to http://www.w3.org/2000/xmlns/, which all default and prefixed xmlns attributes are assigned to by when the document builder factory is namespace aware.

NONE behaviour:

  • Namespace prefixes do not need to be bound to a namespace URI.
  • Element and attribute are compared by their full name and all namespace URIs are ignored.
  • xmlns attributes are not ignored and are treated like any other attribute.