Class Nodes

java.lang.Object
org.xmlunit.util.Nodes

public final class Nodes extends Object
Utility algorithms that work on DOM nodes.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private static final char
     
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    private
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static Map<QName,String>
    Obtains an element's attributes as Map.
    static String
    Tries to merge all direct Text and CDATA children of the given Node and concatenates their value.
    static QName
    Extracts a Node's name, namespace URI (if any) and prefix as a QName.
    private static void
    handleWsRec(Node n, boolean normalize)
    Trims textual content of this node, removes empty text and CDATA children, recurses into its child nodes.
    (package private) static String
    Normalize a string.
    static Node
    Creates a new Node (of the same type as the original node) that is similar to the orginal but doesn't contain any empty text or CDATA nodes and where all textual content including attribute values or comments are trimmed and normalized.
    private static void
     
    static Node
    Creates a new Node (of the same type as the original node) that is similar to the orginal but doesn't contain any text or CDATA nodes that only consist of whitespace.
    static Node
    Creates a new Node (of the same type as the original node) that is similar to the orginal but doesn't contain any empty text or CDATA nodes and where all textual content including attribute values or comments are trimmed.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • Constructor Details

    • Nodes

      private Nodes()
  • Method Details

    • getQName

      public static QName getQName(Node n)
      Extracts a Node's name, namespace URI (if any) and prefix as a QName.
      Parameters:
      n - the node
      Returns:
      its QName
    • getMergedNestedText

      public static String getMergedNestedText(Node n)
      Tries to merge all direct Text and CDATA children of the given Node and concatenates their value.
      Parameters:
      n - the node
      Returns:
      an empty string if the Node has no Text or CDATA children.
    • getAttributes

      public static Map<QName,String> getAttributes(Node n)
      Obtains an element's attributes as Map.
      Parameters:
      n - the node
      Returns:
      attributes
    • stripWhitespace

      public static Node stripWhitespace(Node original)
      Creates a new Node (of the same type as the original node) that is similar to the orginal but doesn't contain any empty text or CDATA nodes and where all textual content including attribute values or comments are trimmed.
      Parameters:
      original - the original node
      Returns:
      cloned node without empty text or cdata children
    • normalizeWhitespace

      public static Node normalizeWhitespace(Node original)
      Creates a new Node (of the same type as the original node) that is similar to the orginal but doesn't contain any empty text or CDATA nodes and where all textual content including attribute values or comments are trimmed and normalized.

      "normalized" in this context means all whitespace characters are replaced by space characters and consecutive whitespace characaters are collapsed.

      Parameters:
      original - the original node
      Returns:
      cloned node without empty text or cdata children and where all attributes and texts are normalized
    • stripElementContentWhitespace

      public static Node stripElementContentWhitespace(Node original)
      Creates a new Node (of the same type as the original node) that is similar to the orginal but doesn't contain any text or CDATA nodes that only consist of whitespace.

      This doesn't have any effect if applied to a text or CDATA node itself.

      Parameters:
      original - the original node
      Returns:
      cloned node without whitespace-only text or cdata children
      Since:
      XMLUnit 2.6.0
    • handleWsRec

      private static void handleWsRec(Node n, boolean normalize)
      Trims textual content of this node, removes empty text and CDATA children, recurses into its child nodes.
      Parameters:
      n - the node
      normalize - whether to normalize whitespace as well
    • normalize

      static String normalize(String s)
      Normalize a string.

      "normalized" in this context means all whitespace characters are replaced by space characters and consecutive whitespace characaters are collapsed.

    • stripECW

      private static void stripECW(Node n)