public final class ElementSelectors extends Object
Modifier and Type | Class and Description |
---|---|
static interface |
ElementSelectors.ConditionalSelectorBuilder
Allows to build complex
ElementSelector s by combining simpler blocks. |
static interface |
ElementSelectors.ConditionalSelectorBuilderThen
|
Modifier and Type | Field and Description |
---|---|
static ElementSelector |
byName
Elements with the same local name (and namespace URI - if any)
can be compared.
|
static ElementSelector |
byNameAndAllAttributes
Elements with the same local name (and namespace URI - if any)
and attribute values for all attributes can be compared.
|
static ElementSelector |
byNameAndText
Elements with the same local name (and namespace URI - if any)
and nested text (if any) can be compared.
|
static ElementSelector |
Default
Always returns true, i.e. each element can be compared to each
other element.
|
Modifier and Type | Method and Description |
---|---|
static ElementSelector |
and(ElementSelector... selectors)
Accepts two elements if all of the given ElementSelectors do.
|
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 |
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 |
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 |
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,
Map<String,String> prefix2Uri,
ElementSelector childSelector)
Selects two elements as matching if the child elements selected
via XPath match using the given childSelector.
|
static ElementSelectors.ConditionalSelectorBuilder |
conditionalBuilder()
Allows to build complex
ElementSelector 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(QName expectedName,
ElementSelector es)
Applies the wrapped ElementSelector's logic if and only if the
control element has the given name.
|
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 |
xor(ElementSelector es1,
ElementSelector es2)
Accepts two elements if exactly on of the given ElementSelectors does.
|
public static final ElementSelector Default
Generally this means elements will be compared in document order.
public static final ElementSelector byName
public static final ElementSelector byNameAndText
public static final ElementSelector byNameAndAllAttributes
public static ElementSelector byNameAndAttributes(String... attribs)
Attributes are only searched for in the null namespace.
public static ElementSelector byNameAndAttributesControlNS(String... attribs)
Namespace URIs of attributes are those of the attributes on the control element or the null namespace if they don't exist.
public static ElementSelector byNameAndAttributes(QName... attribs)
public static ElementSelector not(ElementSelector es)
public static ElementSelector or(ElementSelector... selectors)
There is an important difference between using or(org.xmlunit.diff.ElementSelector...)
to combine multiple ElementSelector
s and using DefaultNodeMatcher
's
constructor with multiple ElementSelector
s:
Consider ElementSelector
s e1
and e2
and two control and test nodes each. Assume e1
would
match the first control node to the second test node and vice
versa if used alone, while e2
would match the nodes in
order (the first control node to the first test and so on).
or(org.xmlunit.diff.ElementSelector...)
creates a combined ElementSelector
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 running e2
alone.
DefaultNodeMatcher
with two ElementSelector
s
will consult the ElementSelector
s separately and only
invoke e2
if there are any nodes not matched by e1
at all. In this case the result will be the same as
running e1
alone.
public static ElementSelector and(ElementSelector... selectors)
public static ElementSelector xor(ElementSelector es1, ElementSelector es2)
public static ElementSelector conditionalSelector(Predicate<? super Element> predicate, ElementSelector es)
public static ElementSelector selectorForElementNamed(String expectedName, ElementSelector es)
public static ElementSelector selectorForElementNamed(QName expectedName, ElementSelector es)
public static ElementSelector byXPath(String xpath, ElementSelector childSelector)
The xpath expression should yield elements. Two elements match if a DefaultNodeMatcher applied to the selected children finds matching pairs for all children.
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.public static ElementSelector byXPath(String xpath, Map<String,String> prefix2Uri, ElementSelector childSelector)
The xpath expression should yield elements. Two elements match if a DefaultNodeMatcher applied to the selected children finds matching pairs for all children.
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.public static ElementSelectors.ConditionalSelectorBuilder conditionalBuilder()
ElementSelector
s by combining simpler blocks.
All pairs created by the when*
/thenUse
pairs
are evaluated in order until one returns true, finally the
default
, if any, is consulted.
Copyright © 2001–2017 XMLUnit. All rights reserved.