Package org.xmlunit.diff
Class XPathContext
java.lang.Object
org.xmlunit.diff.XPathContext
- All Implemented Interfaces:
Cloneable
Helper class that keeps track of the XPath of matched nodes during
comparison.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic final class
DOM based implementation ofXPathContext.NodeInfo
.static interface
Representation of a node used byXPathContext
. -
Constructor Summary
ConstructorDescriptionStarts with an empty context.XPathContext
(Map<String, String> prefix2uri) Starts with an empty context and a given namespace mapping.XPathContext
(Map<String, String> prefix2uri, Node root) Starts with the context of an optional root node and an optional namespace mapping.XPathContext
(Node root) Starts with the context of a root node. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addAttribute
(QName attribute) Adds knowledge about a single attribute of the current node.void
addAttributes
(Iterable<? extends QName> attributes) Adds knowledge about the current node's attributes.void
appendChildren
(Iterable<? extends XPathContext.NodeInfo> children) Adds knowledge about the current node's children appending to the knowledge already present.clone()
Creates a deep copy of this XPathContext.Stringifies the XPath of the current node's parent.getXPath()
Stringifies the XPath of the current node.void
navigateToAttribute
(QName attribute) Moves from the current node to the given attribute.void
navigateToChild
(int index) Moves from the current node to the given child node.void
Moves back to the parent.void
setChildren
(Iterable<? extends XPathContext.NodeInfo> children) Adds knowledge about the current node's children replacing existing knowledge.
-
Constructor Details
-
XPathContext
public XPathContext()Starts with an empty context. -
XPathContext
Starts with the context of a root node.- Parameters:
root
- the root node
-
XPathContext
Starts with an empty context and a given namespace mapping.- Parameters:
prefix2uri
- maps from prefix to namespace URI.
-
XPathContext
Starts with the context of an optional root node and an optional namespace mapping.- Parameters:
prefix2uri
- maps from prefix to namespace URI.root
- optional root node that determines the initial XPath
-
-
Method Details
-
addAttributes
Adds knowledge about the current node's attributes.- Parameters:
attributes
- attributes to add
-
addAttribute
Adds knowledge about a single attribute of the current node.- Parameters:
attribute
- attribute to add
-
setChildren
Adds knowledge about the current node's children replacing existing knowledge.- Parameters:
children
- children to add
-
appendChildren
Adds knowledge about the current node's children appending to the knowledge already present.- Parameters:
children
- children to add
-
getXPath
Stringifies the XPath of the current node.- Returns:
- current XPath
-
getParentXPath
Stringifies the XPath of the current node's parent.- Returns:
- parent's XPath
-
clone
Creates a deep copy of this XPathContext.