Package org.xmlunit.diff
Class XPathContext
- java.lang.Object
-
- org.xmlunit.diff.XPathContext
-
- All Implemented Interfaces:
java.lang.Cloneable
public class XPathContext extends java.lang.Object implements java.lang.Cloneable
Helper class that keeps track of the XPath of matched nodes during comparison.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
XPathContext.DOMNodeInfo
DOM based implementation ofXPathContext.NodeInfo
.private static class
XPathContext.Level
static interface
XPathContext.NodeInfo
Representation of a node used byXPathContext
.
-
Field Summary
Fields Modifier and Type Field Description private static java.lang.String
ATTR
private static java.lang.String
CLOSE
private static java.lang.String
COMMENT
private static java.lang.String
EMPTY
private static java.lang.String
OPEN
private java.util.Deque<XPathContext.Level>
path
private static java.lang.String
PI
private static java.lang.String
SEP
private static java.lang.String
TEXT
private java.util.Map<java.lang.String,java.lang.String>
uri2Prefix
-
Constructor Summary
Constructors Constructor Description XPathContext()
Starts with an empty context.XPathContext(java.util.Map<java.lang.String,java.lang.String> prefix2uri)
Starts with an empty context and a given namespace mapping.XPathContext(java.util.Map<java.lang.String,java.lang.String> prefix2uri, org.w3c.dom.Node root)
Starts with the context of an optional root node and an optional namespace mapping.XPathContext(org.w3c.dom.Node root)
Starts with the context of a root node.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private static int
add1OrIncrement(java.lang.String name, java.util.Map<java.lang.String,java.lang.Integer> map)
Increments the value name maps to or adds 1 as value if name isn't present inside the map.void
addAttribute(javax.xml.namespace.QName attribute)
Adds knowledge about a single attribute of the current node.void
addAttributes(java.lang.Iterable<? extends javax.xml.namespace.QName> attributes)
Adds knowledge about the current node's attributes.void
appendChildren(java.lang.Iterable<? extends XPathContext.NodeInfo> children)
Adds knowledge about the current node's children appending to the knowledge already present.XPathContext
clone()
Creates a deep copy of this XPathContext.private java.lang.String
getName(javax.xml.namespace.QName name)
java.lang.String
getParentXPath()
Stringifies the XPath of the current node's parent.java.lang.String
getXPath()
Stringifies the XPath of the current node.private java.lang.String
getXPath(java.util.Iterator<XPathContext.Level> dIterator)
private static java.util.Map<java.lang.String,java.lang.String>
invert(java.util.Map<java.lang.String,java.lang.String> m)
void
navigateToAttribute(javax.xml.namespace.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
navigateToParent()
Moves back to the parent.void
setChildren(java.lang.Iterable<? extends XPathContext.NodeInfo> children)
Adds knowledge about the current node's children replacing existing knowledge.
-
-
-
Field Detail
-
path
private java.util.Deque<XPathContext.Level> path
-
uri2Prefix
private final java.util.Map<java.lang.String,java.lang.String> uri2Prefix
-
COMMENT
private static final java.lang.String COMMENT
- See Also:
- Constant Field Values
-
PI
private static final java.lang.String PI
- See Also:
- Constant Field Values
-
TEXT
private static final java.lang.String TEXT
- See Also:
- Constant Field Values
-
OPEN
private static final java.lang.String OPEN
- See Also:
- Constant Field Values
-
CLOSE
private static final java.lang.String CLOSE
- See Also:
- Constant Field Values
-
SEP
private static final java.lang.String SEP
- See Also:
- Constant Field Values
-
ATTR
private static final java.lang.String ATTR
- See Also:
- Constant Field Values
-
EMPTY
private static final java.lang.String EMPTY
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
XPathContext
public XPathContext()
Starts with an empty context.
-
XPathContext
public XPathContext(org.w3c.dom.Node root)
Starts with the context of a root node.
-
XPathContext
public XPathContext(java.util.Map<java.lang.String,java.lang.String> prefix2uri)
Starts with an empty context and a given namespace mapping.- Parameters:
prefix2uri
- maps from prefix to namespace URI.
-
XPathContext
public XPathContext(java.util.Map<java.lang.String,java.lang.String> prefix2uri, org.w3c.dom.Node root)
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 Detail
-
navigateToChild
public void navigateToChild(int index)
Moves from the current node to the given child node.
-
navigateToAttribute
public void navigateToAttribute(javax.xml.namespace.QName attribute)
Moves from the current node to the given attribute.
-
navigateToParent
public void navigateToParent()
Moves back to the parent.
-
addAttributes
public void addAttributes(java.lang.Iterable<? extends javax.xml.namespace.QName> attributes)
Adds knowledge about the current node's attributes.
-
addAttribute
public void addAttribute(javax.xml.namespace.QName attribute)
Adds knowledge about a single attribute of the current node.
-
setChildren
public void setChildren(java.lang.Iterable<? extends XPathContext.NodeInfo> children)
Adds knowledge about the current node's children replacing existing knowledge.
-
appendChildren
public void appendChildren(java.lang.Iterable<? extends XPathContext.NodeInfo> children)
Adds knowledge about the current node's children appending to the knowledge already present.
-
getXPath
public java.lang.String getXPath()
Stringifies the XPath of the current node.
-
getParentXPath
public java.lang.String getParentXPath()
Stringifies the XPath of the current node's parent.
-
clone
public XPathContext clone()
Creates a deep copy of this XPathContext.- Overrides:
clone
in classjava.lang.Object
-
getXPath
private java.lang.String getXPath(java.util.Iterator<XPathContext.Level> dIterator)
-
getName
private java.lang.String getName(javax.xml.namespace.QName name)
-
add1OrIncrement
private static int add1OrIncrement(java.lang.String name, java.util.Map<java.lang.String,java.lang.Integer> map)
Increments the value name maps to or adds 1 as value if name isn't present inside the map.- Returns:
- the new mapping for name
-
invert
private static java.util.Map<java.lang.String,java.lang.String> invert(java.util.Map<java.lang.String,java.lang.String> m)
-
-