Class ElementSelectors
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic interface
Allows to build complexElementSelector
s by combining simpler blocks.static interface
-
Field Summary
Modifier and TypeFieldDescriptionstatic final ElementSelector
Elements with the same local name (and namespace URI - if any) can be compared.static final ElementSelector
Elements with the same local name (and namespace URI - if any) and attribute values for all attributes can be compared.static final ElementSelector
Elements with the same local name (and namespace URI - if any) and nested text (if any) can be compared.static final ElementSelector
Always returns true, i.e. each element can be compared to each other element. -
Method Summary
Modifier and TypeMethodDescriptionstatic ElementSelector
and
(ElementSelector... selectors) Accepts two elements if all of the given ElementSelectors do.static final ElementSelector
byNameAndAllAttributes
(Predicate<Attr> attributeFilter) Elements with the same local name (and namespace URI - if any) and attribute values for all attributes can be compared.static ElementSelector
byNameAndAttributes
(String... attribs) Elements with the same local name (and namespace URI - if any) and attribute values for the given attribute names can be compared.static ElementSelector
byNameAndAttributes
(QName... attribs) Elements with the same local name (and namespace URI - if any) and attribute values for the given attribute names can be compared.static ElementSelector
byNameAndAttributesControlNS
(String... attribs) Elements with the same local name (and namespace URI - if any) and attribute values for the given attribute names can be compared.static ElementSelector
Selects two elements as matching if the child elements selected via XPath match using the given childSelector.static ElementSelector
byXPath
(String xpath, ElementSelector childSelector) Selects two elements as matching if the child elements selected via XPath match using the given childSelector.static ElementSelector
byXPath
(String xpath, XPathEngine xpathEngine, Map<String, String> prefix2Uri, ElementSelector childSelector) Selects two elements as matching if the child elements selected via XPath match using the given childSelector.static ElementSelector
byXPath
(String xpath, XPathEngine engine, ElementSelector childSelector) Selects two elements as matching if the child elements selected via XPath match using the given childSelector.Allows to build complexElementSelector
s by combining simpler blocks.static ElementSelector
conditionalSelector
(Predicate<? super Element> predicate, ElementSelector es) Applies the wrapped ElementSelector's logic if and only if the control element matches the given predicate.static ElementSelector
not
(ElementSelector es) Negates another ElementSelector.static ElementSelector
or
(ElementSelector... selectors) Accepts two elements if at least one of the given ElementSelectors does.static ElementSelector
selectorForElementNamed
(String expectedName, ElementSelector es) Applies the wrapped ElementSelector's logic if and only if the control element has the given (local) name.static ElementSelector
selectorForElementNamed
(QName expectedName, ElementSelector es) Applies the wrapped ElementSelector's logic if and only if the control element has the given name.static ElementSelector
xor
(ElementSelector es1, ElementSelector es2) Accepts two elements if exactly on of the given ElementSelectors does.
-
Field Details
-
Default
Always returns true, i.e. each element can be compared to each other element.Generally this means elements will be compared in document order.
-
byName
Elements with the same local name (and namespace URI - if any) can be compared. -
byNameAndText
Elements with the same local name (and namespace URI - if any) and nested text (if any) can be compared. -
byNameAndAllAttributes
Elements with the same local name (and namespace URI - if any) and attribute values for all attributes can be compared.This
ElementSelector
doesn't know anything about a potentially configured attribute filter so may also compare attributes that are excluded from comparison by the filter. UsebyNameAndAllAttributes(Predicate)
passing in your attribute filter if this causes problems.
-
-
Method Details
-
byNameAndAllAttributes
Elements with the same local name (and namespace URI - if any) and attribute values for all attributes can be compared.- Parameters:
attributeFilter
- filter to use when comparing attributes. Only attributes where the filter returnstrue
are considered.- Returns:
- an ElementSelector
- Since:
- XMLUnit 2.10.0
-
byNameAndAttributes
Elements with the same local name (and namespace URI - if any) and attribute values for the given attribute names can be compared.Attributes are only searched for in the null namespace.
- Parameters:
attribs
- the names of all attributes who's values must be the same- Returns:
- the ElementSelector
-
byNameAndAttributesControlNS
Elements with the same local name (and namespace URI - if any) and attribute values for the given attribute names can be compared.Namespace URIs of attributes are those of the attributes on the control element or the null namespace if they don't exist.
- Parameters:
attribs
- the names of all attributes who's values must be the same- Returns:
- the ElementSelector
-
byNameAndAttributes
Elements with the same local name (and namespace URI - if any) and attribute values for the given attribute names can be compared.- Parameters:
attribs
- the qualified names of all attributes who's values must be the same- Returns:
- the ElementSelector
-
not
Negates another ElementSelector.- Parameters:
es
- the ElementSelector to negate- Returns:
- the ElementSelector
-
or
Accepts two elements if at least one of the given ElementSelectors does.There is an important difference between using
or(org.xmlunit.diff.ElementSelector...)
to combine multipleElementSelector
s and usingDefaultNodeMatcher
's constructor with multipleElementSelector
s:Consider
ElementSelector
se1
ande2
and two control and test nodes each. Assumee1
would match the first control node to the second test node and vice versa if used alone, whilee2
would match the nodes in order (the first control node to the first test and so on).or(org.xmlunit.diff.ElementSelector...)
creates a combinedElementSelector
that is willing to match the first control node to both of the test nodes - and the same for the second control node. Since nodes are compared in order when possible the result will be the same as runninge2
alone.DefaultNodeMatcher
with twoElementSelector
s will consult theElementSelector
s separately and only invokee2
if there are any nodes not matched bye1
at all. In this case the result will be the same as runninge1
alone.- Parameters:
selectors
- the ElementSelectors to combine- Returns:
- the ElementSelector
-
and
Accepts two elements if all of the given ElementSelectors do.- Parameters:
selectors
- the ElementSelectors to combine- Returns:
- the ElementSelector
-
xor
Accepts two elements if exactly on of the given ElementSelectors does.- Parameters:
es1
- the first ElementSelector to combinees2
- the second ElementSelector to combine- Returns:
- the ElementSelector
-
conditionalSelector
public static ElementSelector conditionalSelector(Predicate<? super Element> predicate, ElementSelector es) Applies the wrapped ElementSelector's logic if and only if the control element matches the given predicate.- Parameters:
predicate
- the predicate applied to the control elementes
- the ElementSelector to consult- Returns:
- the ElementSelector
-
selectorForElementNamed
Applies the wrapped ElementSelector's logic if and only if the control element has the given (local) name.- Parameters:
expectedName
- expected name of the control elementes
- the ElementSelector to consult- Returns:
- the ElementSelector
-
selectorForElementNamed
Applies the wrapped ElementSelector's logic if and only if the control element has the given name.- Parameters:
expectedName
- expected name of the control elementes
- the ElementSelector to consult- Returns:
- the ElementSelector
-
byXPath
Selects two elements as matching if the child elements selected via XPath match using the given childSelector.The xpath expression should yield elements. Two elements match if a DefaultNodeMatcher applied to the selected children finds matching pairs for all children.
- Parameters:
xpath
- XPath expression applied in the context of the elements to chose from that selects the children to compare.childSelector
- ElementSelector to apply to the selected children.- Returns:
- the ElementSelector
-
byXPath
public static ElementSelector byXPath(String xpath, XPathEngine engine, ElementSelector childSelector) Selects two elements as matching if the child elements selected via XPath match using the given childSelector.The xpath expression should yield elements. Two elements match if a DefaultNodeMatcher applied to the selected children finds matching pairs for all children.
- Parameters:
xpath
- XPath expression applied in the context of the elements to chose from that selects the children to compare.engine
- XPathEngine to use. Ifnull
aJAXPXPathEngine
with default configuration will be used.childSelector
- ElementSelector to apply to the selected children.- Returns:
- the ElementSelector
- Since:
- XMLUnit 2.9.1
-
byXPath
public static ElementSelector byXPath(String xpath, Map<String, String> prefix2Uri, ElementSelector childSelector) Selects two elements as matching if the child elements selected via XPath match using the given childSelector.The xpath expression should yield elements. Two elements match if a DefaultNodeMatcher applied to the selected children finds matching pairs for all children.
- Parameters:
xpath
- XPath expression applied in the context of the elements to chose from that selects the children to compare.prefix2Uri
- maps from prefix to namespace URI.childSelector
- ElementSelector to apply to the selected children.- Returns:
- the ElementSelector
-
byXPath
public static ElementSelector byXPath(String xpath, XPathEngine xpathEngine, Map<String, String> prefix2Uri, ElementSelector childSelector) Selects two elements as matching if the child elements selected via XPath match using the given childSelector.The xpath expression should yield elements. Two elements match if a DefaultNodeMatcher applied to the selected children finds matching pairs for all children.
- Parameters:
xpath
- XPath expression applied in the context of the elements to chose from that selects the children to compare.xpathEngine
- XPathEngine to use. Ifnull
aJAXPXPathEngine
with default configuration will be used.prefix2Uri
- maps from prefix to namespace URI.childSelector
- ElementSelector to apply to the selected children.- Returns:
- the ElementSelector
- Since:
- XMLUnit 2.9.1
-
conditionalBuilder
Allows to build complexElementSelector
s by combining simpler blocks.All pairs created by the
when*
/thenUse
pairs are evaluated in order until one returns true, finally thedefault
, if any, is consulted.- Returns:
- a builder for conditional ElementSelectors
-