Class RxPath
Represents a RanoreXPath.
public class RxPath : ICloneable, IComparable<RxPath>
- Inheritance
-
RxPath
- Implements
- Inherited Members
Remarks
RanoreXPath is modeled after W3C XPath and allows easy identification/searching/filtering of web elements and navigation in web documents. For detailed usage, please refer to the user guide and to the RanoreXPath examples.
Constructors
RxPath(string)
Creates a new RanoreXPath instance, using the supplied path.
public RxPath(string path)
Parameters
pathstringThe path to be represented by this instance.
Exceptions
- RxPathException
Thrown if the path is not valid.
- ArgumentNullException
If
pathisnull.
Fields
DefaultWeightFilterThreshold
The weight threshold which determines whether an attribute is used in generated RxPaths.
public const int DefaultWeightFilterThreshold = 100
Field Value
LabelWeightFilterThreshold
The weight threshold which determines whether an attribute is used in element labels.
public const int LabelWeightFilterThreshold = 10
Field Value
Root
Represents the RxPath for the root element.
public static readonly RxPath Root
Field Value
Properties
BuildOptions
Settings which allow tweaking the PathBuildMode.StepCostReduce algorithm.
public static PathBuildOptions BuildOptions { get; set; }
Property Value
- PathBuildOptions
DataProvider
The data provider to use for resolving variables.
public IDataProvider DataProvider { get; set; }
Property Value
DefaultSearchTimeout
The timeout used when elements are searched by assigning a path to an element variable (implicit cast operator).
public static Duration DefaultSearchTimeout { get; set; }
Property Value
Examples
The timeout value set to this property is used for searching when implicitly casting a path (in its string representation) to an element variable:
Element elem = "pathToElem";
Remarks
This property is equivalent to DefaultSearchTimeout.
IsAbsolute
Gets or sets a value indicating whether this instance is absolute.
public bool IsAbsolute { get; set; }
Property Value
- bool
trueif this instance is absolute; otherwise,false.
Length
The number of location steps contained in the RxPath.
public int Length { get; }
Property Value
LocationSteps
Gets or sets the location steps of this path.
public IList<LocationStep> LocationSteps { get; set; }
Property Value
- IList<LocationStep>
The location steps.
MaxMatchTextLen
The maximum length to use for attribute values that have a TruncationLength
of -1 when building paths. Longer attribute values are truncated at the next word boundary (if available)
using StartsWith expressions.
public static int MaxMatchTextLen { get; set; }
Property Value
Methods
BuildElementPath(Element, Element, PathBuildMode)
Builds a RanoreXPath for a given element.
public static RxPath BuildElementPath(Element relativeParent, Element element, PathBuildMode mode)
Parameters
relativeParentElementThe ancestor element to which the path should be relative to. If this parameter is null, an absolute path is built.
elementElementThe node to build the path for.
modePathBuildModeThe path building mode. This basically controls the degree of optimization applied to the path.
Returns
- RxPath
The path of the specified element relative to the specified parent element.
BuildElementPath(Element, Element, PathBuildMode, bool)
Builds a RanoreXPath for a given element.
public static RxPath BuildElementPath(Element relativeParent, Element element, PathBuildMode mode, bool forceRobustPath)
Parameters
relativeParentElementThe ancestor element to which the path should be relative to. If this parameter is null, an absolute path is built.
elementElementThe node to build the path for.
modePathBuildModeThe path building mode. This basically controls the degree of optimization applied to the path.
forceRobustPathboolSpecifies if building robuts path sholub be forced.
Returns
- RxPath
The path of the specified element relative to the specified parent element.
CalcElementScore(Element, out CostInfo)
Calculates a score for an individual element used for determining the best RxPath layer/step selection.
public static int CalcElementScore(Element e, out RxPath.CostInfo rawCost)
Parameters
Returns
- int
The cost value, higher is better.
ChangePrefix(RxPath, RxPath, RxPath)
Changes a given prefix of an RxPath to a new prefix.
public static RxPath ChangePrefix(RxPath path, RxPath oldPrefix, RxPath newPrefix)
Parameters
Returns
- RxPath
The path with the changed prefix.
Exceptions
- RxPathException
If
oldPrefixis not a prefix of the supplied path.
ChangePrefix(RxPath, RxPath, RxPath, bool)
Changes a given prefix of an RxPath to a new prefix.
public static RxPath ChangePrefix(RxPath path, RxPath oldPrefix, RxPath newPrefix, bool fastNoCheck)
Parameters
pathRxPathThe path to change.
oldPrefixRxPathThe old prefix.
newPrefixRxPathThe new prefix.
fastNoCheckboolDetermines whether the existing prefixes are checked or not.
Returns
- RxPath
The path with the changed prefix.
Exceptions
- RxPathException
If
oldPrefixis not a prefix of the supplied path.
Clone()
Creates a clone of the path.
public object Clone()
Returns
- object
The cloned path.
CompareTo(RxPath)
Compares the current path with another path.
public int CompareTo(RxPath other)
Parameters
otherRxPathA path to compare with this path.
Returns
- int
A 32-bit signed integer that indicates the relative order of the objects being compared. The return value has the following meanings:
Value Meaning Less than zero This instance is less than other.Zero This instance is equal to other.Greater than zero This instance is greater than other.
Concat(RxPath, RxPath)
Concatenates two paths.
public static RxPath Concat(RxPath left, RxPath right)
Parameters
Returns
- RxPath
The new path resulting from concatenating both input paths.
ConvertToCanonicalAndChain(IList<IPredicate>)
Returns a list of predicates iff the preds can be represented
as a flat list of predicates.
public static IList<ComparisonPredicate> ConvertToCanonicalAndChain(IList<IPredicate> preds)
Parameters
predsIList<IPredicate>The predicates to convert.
Returns
- IList<ComparisonPredicate>
A flat list of predicates.
Equals(object)
Compares an RxPath to an object.
public override bool Equals(object obj)
Parameters
objobjectThe object to compare to.
Returns
- bool
True if the object is an RxPath and the paths are exactly the same.
Escape(string)
Escapes string values for use within RxPath literals.
public static string Escape(string literal)
Parameters
literalstringThe value to escape.
Returns
- string
The escaped value.
ExtractCommonPrefix(IList<RxPath>)
Extracts the longest common prefix from a list of RxPaths.
public static RxPath ExtractCommonPrefix(IList<RxPath> paths)
Parameters
Returns
- RxPath
The longest common prefix of the specified paths.
Remarks
It is not allowed to mix relative and absolute paths in the list.
GetCapabilityForTailNodeTest()
Map the RxPath nodetest name expression to a capability.
public Capability GetCapabilityForTailNodeTest()
Returns
- Capability
The best matching capability or Role.Unknown.
GetHashCode()
Calculates a hash value for the RxPath.
public override int GetHashCode()
Returns
- int
The hash value.
GetParentPath(RxPath)
Returns a path which applies to parent elements of an element with the specified path.
public static RxPath GetParentPath(RxPath path)
Parameters
pathRxPathThe path to create the parent path from.
Returns
- RxPath
Returns a path which applies to parent elements of an element with the specified path.
GetPrefixPath(RxPath, int)
Returns a path with the specified number of prefix steps
public static RxPath GetPrefixPath(RxPath path, int len)
Parameters
Returns
- RxPath
Returns a path with the specified prefix length.
GetRxPathTokens(string, out bool, out string, out int)
Gets the tokens which form an RxPath.
public static IList<RxPathToken> GetRxPathTokens(string queryPath, out bool syntaxOk, out string errorMessage, out int errorPosition)
Parameters
queryPathstringThe query path.
syntaxOkboolSet to
trueif the sytnax of the RxPath is valid.errorMessagestringThe error message (if there was a syntax error).
errorPositionintThe error position (if there was a syntax error).
Returns
- IList<RxPathToken>
A list of tokens.
Invert(RxPath)
Inverts the specified path.
public static RxPath Invert(RxPath path)
Parameters
pathRxPathThe path to invert.
Returns
- RxPath
The inverted path.
Remarks
Inverse path work like that: A = B.Find(P) results in B = A.Find(P^-1)
IsPrefixOf(RxPath)
Determines whether the path is a prefix of the specified path.
public bool IsPrefixOf(RxPath path)
Parameters
pathRxPathThe path.
Returns
- bool
trueif the path is prefix of the specified path; otherwise,false.
IsSimilar(RxPath, RxPath, out int, IDataProvider)
Determines whether two paths are similar. Per definition, paths are similar if they could yield an intersecting set of result elements.
public static bool IsSimilar(RxPath a, RxPath b, out int warnCount, IDataProvider provider)
Parameters
aRxPathThe first path.
bRxPathThe second path.
warnCountintThe warn count is set to the number of significant differences both paths have (but are not a contradiction per se).
providerIDataProviderThe data provider to use to resolve variable values.
Returns
- bool
trueif the specified the paths are similar; otherwise,false.
Parse(string)
Parses a string into an RxPath.
public static RxPath Parse(string path)
Parameters
Returns
Exceptions
- RxPathException
Thrown if the path is not valid.
- ArgumentNullException
If
pathisnull.
RemovePrefix(RxPath, RxPath, bool)
Removes a given prefix from a specific path.
public static RxPath RemovePrefix(RxPath path, RxPath prefix, bool fastNoCheck)
Parameters
pathRxPathThe path to remove the prefix from.
prefixRxPathThe prefix to remove.
fastNoCheckboolAssumes that the supplied prefix is valid.
Returns
- RxPath
The path without the prefix.
Exceptions
- RxPathException
If
prefixis not a prefix of the supplied path.
ToResolvedString()
Converts the RxPath to its string representation, with the variables resolved to their current values.
public string ToResolvedString()
Returns
- string
The RxPath as string.
Remarks
To correctly resolve the variables, an active DataProviderContext is needed.
ToString()
Converts the RxPath to its string representation.
public override string ToString()
Returns
- string
The RxPath as string.
ToStringSteps()
Creates a list of strings where each location step in the RxPath corresponds to one string.
public string[] ToStringSteps()
Returns
- string[]
The RxPath as string.
TryCreate(string, out RxPath)
Tries to create an RxPath instance.
public static bool TryCreate(string path, out RxPath rxPath)
Parameters
pathstringThe path to be represented by the
rxPathinstance.rxPathRxPathWhen this method returns, contains the created RxPath instance or a
nullreference if creating the RxPath failed.
Returns
Unescape(string)
Unescapes string values used within RxPath literals.
public static string Unescape(string literal)
Parameters
literalstringThe value to unescape.
Returns
- string
The unescaped value.
Operators
operator ==(RxPath, RxPath)
Implements the operator ==.
public static bool operator ==(RxPath left, RxPath right)
Parameters
Returns
- bool
The result of the operator.
implicit operator RxPath(string)
Implicitly converts a string to an RxPath.
public static implicit operator RxPath(string path)
Parameters
Returns
Exceptions
- RxPathException
Thrown if the path is not valid.
- ArgumentNullException
If
pathisnull.
operator !=(RxPath, RxPath)
Implements the operator !=.
public static bool operator !=(RxPath left, RxPath right)
Parameters
Returns
- bool
The result of the operator.