Package org.xmlunit.util
Class Nodes
- java.lang.Object
-
- org.xmlunit.util.Nodes
-
public final class Nodes extends java.lang.ObjectUtility algorithms that work on DOM nodes.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.util.Map<javax.xml.namespace.QName,java.lang.String>getAttributes(org.w3c.dom.Node n)Obtains an element's attributes as Map.static java.util.Map<javax.xml.namespace.QName,java.lang.String>getAttributes(org.w3c.dom.Node n, Predicate<org.w3c.dom.Attr> attributeFilter)Obtains an element's attributes as Map.static org.w3c.dom.NodeListgetChildNodes(org.w3c.dom.Node n)Helper deals with thegetChildNodesimplementation ofAttr.static java.lang.StringgetMergedNestedText(org.w3c.dom.Node n)Tries to merge all direct Text and CDATA children of the given Node and concatenates their value.static javax.xml.namespace.QNamegetQName(org.w3c.dom.Node n)Extracts a Node's name, namespace URI (if any) and prefix as a QName.static org.w3c.dom.NodenormalizeWhitespace(org.w3c.dom.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.static org.w3c.dom.NodestripElementContentWhitespace(org.w3c.dom.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.static org.w3c.dom.NodestripWhitespace(org.w3c.dom.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.
-
-
-
Method Detail
-
getQName
public static javax.xml.namespace.QName getQName(org.w3c.dom.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 java.lang.String getMergedNestedText(org.w3c.dom.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 java.util.Map<javax.xml.namespace.QName,java.lang.String> getAttributes(org.w3c.dom.Node n)
Obtains an element's attributes as Map.- Parameters:
n- the node- Returns:
- attributes
-
getAttributes
public static java.util.Map<javax.xml.namespace.QName,java.lang.String> getAttributes(org.w3c.dom.Node n, Predicate<org.w3c.dom.Attr> attributeFilter)Obtains an element's attributes as Map.- Parameters:
n- the nodeattributeFilter- is used to suppress unwanted attributes. Only attributes where the filter's test returnstrueare returned- Returns:
- attributes
- Since:
- XMLUnit 2.10.0
-
stripWhitespace
public static org.w3c.dom.Node stripWhitespace(org.w3c.dom.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 org.w3c.dom.Node normalizeWhitespace(org.w3c.dom.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 org.w3c.dom.Node stripElementContentWhitespace(org.w3c.dom.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
-
getChildNodes
public static org.w3c.dom.NodeList getChildNodes(org.w3c.dom.Node n)
Helper deals with thegetChildNodesimplementation ofAttr.For non-
Attrnodes this method simply returnsn.getChildNodes. For the special case of anAttrwith anullvalue this returns aNodeListwith an emptyTextelement containing a empty string rather than aNodeListcontaining a singlenullNode.- Parameters:
n- the node to obtain the children of- Returns:
- children of the node
- Since:
- XMLUnit 2.10.4
-
-