com.thoughtworks.xstream.io.path
Class Path

java.lang.Object
  extended by com.thoughtworks.xstream.io.path.Path

public class Path
extends Object

Represents a path to a single node in the tree.

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:

Example

 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.
 

Author:
Joe Walnes
See Also:
PathTracker

Constructor Summary
Path(String pathAsString)
           
Path(String[] chunks)
           
 
Method Summary
 Path apply(Path relativePath)
           
 boolean equals(Object o)
           
 String explicit()
           
 int hashCode()
           
 boolean isAncestor(Path child)
           
 Path relativeTo(Path that)
           
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Path

public Path(String pathAsString)

Path

public Path(String[] chunks)
Method Detail

toString

public String toString()
Overrides:
toString in class Object

explicit

public String explicit()

equals

public boolean equals(Object o)
Overrides:
equals in class Object

hashCode

public int hashCode()
Overrides:
hashCode in class Object

relativeTo

public Path relativeTo(Path that)

apply

public Path apply(Path relativePath)

isAncestor

public boolean isAncestor(Path child)


Copyright © 2004-2014 XStream. All Rights Reserved.