Enum EqualToXmlPattern.NamespaceAwareness

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Comparable<EqualToXmlPattern.NamespaceAwareness>
    Enclosing class:
    EqualToXmlPattern

    public static enum EqualToXmlPattern.NamespaceAwareness
    extends java.lang.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.
    • Enum Constant Summary

      Enum Constants 
      Enum Constant Description
      LEGACY  
      NONE  
      STRICT  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static EqualToXmlPattern.NamespaceAwareness valueOf​(java.lang.String name)
      Returns the enum constant of this type with the specified name.
      static EqualToXmlPattern.NamespaceAwareness[] values()
      Returns an array containing the constants of this enum type, in the order they are declared.
      • Methods inherited from class java.lang.Enum

        clone, compareTo, equals, finalize, getDeclaringClass, hashCode, name, ordinal, toString, valueOf
      • Methods inherited from class java.lang.Object

        getClass, notify, notifyAll, wait, wait, wait
    • Method Detail

      • values

        public static EqualToXmlPattern.NamespaceAwareness[] values()
        Returns an array containing the constants of this enum type, in the order they are declared. This method may be used to iterate over the constants as follows:
        for (EqualToXmlPattern.NamespaceAwareness c : EqualToXmlPattern.NamespaceAwareness.values())
            System.out.println(c);
        
        Returns:
        an array containing the constants of this enum type, in the order they are declared
      • valueOf

        public static EqualToXmlPattern.NamespaceAwareness valueOf​(java.lang.String name)
        Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (Extraneous whitespace characters are not permitted.)
        Parameters:
        name - the name of the enum constant to be returned.
        Returns:
        the enum constant with the specified name
        Throws:
        java.lang.IllegalArgumentException - if this enum type has no constant with the specified name
        java.lang.NullPointerException - if the argument is null