Class XPath2Expression

Assembly: redb.Route.XPath2.dll

An XPath 2.0 expression, usable in every position that takes an .

public class XPath2Expression : Expression, IPredicateExpression, IExpression

Inheritance

Object→Expression→XPath2Expression

Implements

Inherited Members

Properties

Path

The expression text.

public string Path { get; }

Methods

Evaluate<T>(IExchange)

Evaluates the expression and returns the result cast to T.

public override T Evaluate<T>(IExchange exchange)

From(IExpression)

Returns the same expression reading source instead of the message body.

public XPath2Expression From(IExpression source)

Matches(IExchange)

Evaluates the expression in a condition position.

public bool Matches(IExchange exchange)

Namespaces(params (string Prefix, string Uri)[])

Builds a namespace resolver from prefix/URI pairs, for the constructor.

public static IXmlNamespaceResolver Namespaces(params (string Prefix, string Uri)[] namespaces)

SetValue(IExchange, object)

Sets a value in the exchange according to this expression's semantics.

public override void SetValue(IExchange exchange, object value)

ToTemplateString()

Serializes this expression to a ${...} template string suitable for URI parameters.

public override string ToTemplateString()

Trimmed(bool)

Returns the same expression with whitespace trimmed off the text it extracts.

public XPath2Expression Trimmed(bool trim = true)

WithParameters(params (string Name, IExpression Value)[])

Returns the same expression with named XPath variables bound to expressions, so a value from

public XPath2Expression WithParameters(params (string Name, IExpression Value)[] parameters)

Constructors

XPath2Expression(string, IXmlNamespaceResolver?)

Compiles an XPath 2.0 expression.

Remarks

XPath 1.0 has no regular expressions, no sequences, no date arithmetic and no conditional; a
route that needs one of those has to leave the language. XPath 2.0 has all of them —
matches, replace, tokenize, distinct-values, string-join,
avg, max, if…then…else, for $x in … return …,
some/every … satisfies, xs:date comparisons, instance of.


What this is not. XQuery. let, where and order by are XQuery
clauses, not XPath 2.0 ones, and the engine rejects them — so there is no sorting and no
grouping here. Filtering goes in a predicate (for $o in /orders/order[total > 8] return …)
rather than in a where. A full XQuery processor is not shipped: every .NET
implementation of one is commercial.


The path is compiled once, when the route is built, so a malformed expression fails the build
rather than the first message — the same rule the rest of the expression layer follows.