Two absolute paths can also be compared to calculate the relative path between them. A relative path can be applied to an absolute path to calculate another absolute path.
Note that the paths are normally XPath compliant, so can be read by other XPath engines.
However, toString() will select a node list while explicit() will always select
an individual node. If the return type of the XPath evaluation is a node, the result will be the same,
because XPath will then use the first element of the list. The following are examples of path
expressions that the Path object supports:
Note that the implementation does not take care if the paths are XPath compliant, it simply manages the values between the path separator. However, it normalizes the path if a path element ends with a selector for the first element (i.e. "[1]"). Those will be handled transparent i.e. two Paths are treated equal if one was created with path elements containing this selector and the other one without.
The following are examples of path expressions that the Path object supports:
Path a = new Path("/html/body/div[1]/table[2]/tr[3]/td/div");
Path b = new Path("/html/body/div/table[2]/tr[6]/td/form");
Path relativePath = a.relativeTo(b); // produces: "../../../tr[6]/td/form"
Path c = a.apply(relativePath); // same as Path b.
PathTracker
| Modifier and Type | Field and Description |
|---|---|
| private final String[] | |
| private static final Path | |
| private transient String | |
| private transient String |
| Access | Constructor and Description |
|---|---|
| public | |
| public |
| Modifier and Type | Method and Description |
|---|---|
| public Path | |
| private int | |
| public boolean | equals(Object
the reference object with which to compare. o)Overrides java. |
| public String | |
| public int | |
| public boolean | |
| private String | |
| public Path | |
| public String |
| chunks | back to summary |
|---|---|
| private final String[] chunks | |
| DOT | back to summary |
|---|---|
| private static final Path DOT | |
| pathAsString | back to summary |
|---|---|
| private transient String pathAsString | |
| pathExplicit | back to summary |
|---|---|
| private transient String pathExplicit | |
| Path | back to summary |
|---|---|
| public Path(String pathAsString) | |
| Path | back to summary |
|---|---|
| public Path(String[] chunks) | |
| apply | back to summary |
|---|---|
| public Path apply(Path relativePath) | |
| depthOfPathDivergence | back to summary |
|---|---|
| private int depthOfPathDivergence(String[] path1, String[] path2) | |
| equals | back to summary |
|---|---|
| public boolean equals(Object o) Overrides java. Doc from java. Indicates whether some other object is "equal to" this one.
The
An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes.
| |
| explicit | back to summary |
|---|---|
| public String explicit() | |
| hashCode | back to summary |
|---|---|
| public int hashCode() Overrides java. Doc from java. Returns a hash code value for the object. This method is
supported for the benefit of hash tables such as those provided by
The general contract of
| |
| isAncestor | back to summary |
|---|---|
| public boolean isAncestor(Path child) | |
| normalize | back to summary |
|---|---|
| private String normalize(String s, int start, int end) | |
| relativeTo | back to summary |
|---|---|
| public Path relativeTo(Path that) | |
| toString | back to summary |
|---|---|
| public String toString() Overrides java. Doc from java. Returns a string representation of the object.
| |