Home > By category > Developer Tools >Components & Libraries > OPath.NET


  • Downloads: 
  • Views: 
  • Rating:

OPath.NET is a .NET 2.0 compliant library for evaluating string-based expressions. It leverages the .NET XPath evaluation engine and borrows the XPath API semantics.

It is perhaps best described by an example:

var expression = OPathExpression.Compile("MyVariable = 'Hello OPath.NET'");

var document = new OPathDocument();
document.Add("MyVariable", "Hello OPath.NET");

var navigator = OPathNavigator.CreateNavigator(document);

var result = navigator.Evaluate(expression);


This results in "True" being written to the console.

Let us go through each step in detail.

var expression = OPathExpression.Compile("MyVariable = 'Hello OPath.NET'");

This parses the string expression and builds an internal representation of the expression ready for evaluation. If the expression contains errors then an exception is thrown. The expression object can be cached to improve performance when the same expression is evaluated multiple times.

var document = new OPathDocument();
document.Add("MyVariable", "Hello OPath.NET");

This create an OPath document to evaluate our expression against. An OPath document is a dictionary of named objects.

var navigator = OPathNavigator.CreateNavigator(document);

This creates a navigator object to evaluate expressions against the document containing the named objects.

var result = navigator.Evaluate(expression);

This evaluates the expression against the named objects and returns the result. If the evaluation fails for any reason then an exception is thrown.
Object References

The object references within an OPath expression can contain:

* Properties
* Parameterless methods
* Static string or integer indexers

For example, the following is a valid OPath expression:

StringDictionary["Key1"].Trim().Length > IntList.ToArray()[0].ToString().Length

Object references cannot contain dynamic indexers, i.e. other object references. For example, the following is not a valid OPath expression;

IntArray[IntValue] > 0

Custom Keywords

The OPath evaluation engine is built upon the core XPath evaluation engine and so inherits a number of syntax quirks of XPath. For convenience, OPath offers some more familiar alternatives:

* div - division operator, OPath allows this or '/'
* mod - modulus operator, OPath allows this or '%'
* = equality operator, OPath allows this or '=='
* true() - true function, OPath allows this or just 'true'
* false() - false function, OPath allows this or just 'false'

This means the following expressions are valid in OPath:

10 / 2 == 10 % 2
true == false

OPath also allows testing for null via the custom 'null' keyword. For example:

MyObject == null

XPath contains a 'not' function. OPath offers an alternative of '!'. For example:

!(true) == not(true)

OPath Options

If part of an XPath returns no match then the whole of the XPath returns no match. It is sometimes desirable to have a similar behaviour when evaluating object references. OPath allows you to do this by specifying options when evaluating. For example:

var expression = OPathExpression.Compile("MyVariable.Length = 0");

var document = new OPathDocument();
document.Add("MyVariable", null);

var navigator = OPathNavigator.CreateNavigator(document);

var result = navigator.Evaluate(expression);


This results in an exception being thrown with the following message:

Exception occurred evaluating variable reference MyVariable.Length: MyVariable evaluated to ''.

We can avoid this exception by specifying the ReturnDefaultForNull option as follows:

var result = navigator.Evaluate(expression, OPathOptions.ReturnDefaultForNull);


This results in 'False' being written to the console, as by default the default value is null. We can go a step further and specify a default value.

var result = navigator.Evaluate(expression, OPathOptions.ReturnDefaultForNull, 0);


This results in 'True' being written to the console.

There is another option that can be specified, ReturnDefaultIfException. This works in a similar way to ReturnDefaultForNull, but means that any exception that occurs when evaluating the object reference is interpreted as the default value.

OPath allows you to hook into how an expression is evaluated. This can be invaluable when debugging, as otherwise the evaluation engine is somewhat of a black box. The example below shows how a delegate can be provided when evaluating to output the evaluation of the individual object references:

var expression = OPathExpression.Compile("StringArray[0].Length > Int");

var document = new OPathDocument();
document.Add("StringArray", new string[] { "String" });
document.Add("Int", 0);

var navigator = OPathNavigator.CreateNavigator(document);

var result =
navigator.Evaluate(expression, OPathOptions.Defaults, null,
new OPathNavigator.ValueLogger(delegate(string message)


The result is the following written to the console:

StringArray[0].Length evaluated to '6'
Int evaluated to '0'

Custom Functions

XPath has a set of core functions. The most useful of these cover some string manipulation and numeric operations. The date functions are of no use in the context of OPath, see Custom Data Types for alternatives.

The core XPath classes allow custom functions to be added via an XsltContext object. OPath abstracts this further to allow custom functions to be added by simply registering a delegate with the navigator object as the example below shows:

var expression = OPathExpression.Compile("my-prefix:my-function(String, Int)");

var document = new OPathDocument();
document.Add("String", "String" );
document.Add("Int", 616);

var navigator = OPathNavigator.CreateNavigator(document);

navigator.RegisterCustomFunction("my-prefix", "my-function",
new OPathCustomFunction(delegate(object[] args)
string[] stringArray = Array.ConvertAll(args, delegate(object o) { return o + ""; });
return string.Join(",", stringArray);

var result = navigator.Evaluate(expression);


The result is that 'String,616' is written to the console. As an alternative to registering the functions as shown, the navigator class can be sub-classed and custom functions registered within the constructor of the derived class. This technique can be used to override any of the core OPath custom functions.
Custom Data Types


Free download from Shareware Connection - OPath.

Publisher: Andy Blackledge | License: Freeware | Price: 0.00
Version: 1.0.1 | Size: 40 KB | Platform: Win2000, WinOther, WinServer
Released Date: | Rating: 0 | Title: OPath.NET

Author Url: http://sourceforge.net/apps/mediawiki/opathnet/index.php?title=Main_Page
Program Info Url: http://sourceforge.net/apps/mediawiki/opathnet/index.php?title=Main_Page
Download Url: http://nchc.dl.sourceforge.net/project/opathnet/OPath.NET%201.0.1/OPathNET_bin_1.0.1.zip

OPath.NET keywords:
OPath.NET related downloads:

Freeware .NET Obfuscator Skater Light - Freeware .NET Obfuscator Skater Light Edition is an obfuscation tool for .NET code protection. It implements all known software protection techniques and obfuscation algorithms.

Net-Cabinet - Net-Cabinet manages the storage of electronic documents in a document repository.

Document Organizer Deluxe - Document Organizer Deluxe is a simple yet complete document management software for Windows users. Our document management database solution gives you an easy way to gather and organize information about all your documents.

Navigator Elegance - Navigator Elegance Is A Full Fledged Internet Navigator With Elegant Design!

BarCode ASP.NET Web Control 1.5 - Barcode ASP.NET WEB Control lets you add barcodes to your ASP.NET web application in ten minutes without having to write complicated code. BarCode ASP.NET Web Control has been designed specially for the use in ASP.NET web applications.

Shareware Connection periodically updates pricing and software information of 'OPath.NET' from company source 'Andy Blackledge' , so some information may be slightly out-of-date. You should confirm all information before relying on it. Software piracy is theft,  Using 'OPath.NET' crack, password, serial numbers, registration codes, key generators is illegal and prevent future development of OPath.NET.

New Reviews

AOMEI Partition Assistant Lite Edition - No matter whether you are a casual PC user or deal with a number of computers for professional needs, taking care of hardware components is a necessity. Among all hardware components used in laptop or desktop, hard disk is the most important one. ...

Spark Browser - Nearly every PC user needs to browse the web nowadays, irrespective of age and gender. Whether you use a laptop or desktop, it is mandatory to use a web browser to access web or download files. There was a time a majority of Windows users ...

SyncMate - Just like windows users, Macintosh users also need to sync their data with myriads of other devices and other Macs. It is possible to use Apple’s much touted iCloud to sync a Mac with other iOS based devices but that may not fit ...

Device Doctor - Keeping the drivers of hardware components used in your PC is really important. Obsolete device drivers lead to a myriad of problems affecting PC performance. While advanced users may check for outdated drivers personally, this may not be an ...

Hekasoft Backup & Restore - There was a time a majority of Windows PC users stuck to Internet Explorer as it was the integrated web browsing app. After arrival and growth of Open Source rivals like Firefox and Chrome, the scenario has changed a lot. PC users are now spoilt ...

Format Factory - No matter what reason you use the computer mostly for, converting media files from one format to another can be necessary sometimes. This can be useful when you want to convert all those series of DVDs into formats that can be played across ...

MusicBee - Irrespective of what type of a PC you use, it will be necessary to use a media player app from time to time. If the WMP is not your cup of tea, you will have to pick from third-party music player apps. The problem with some such apps is that ...

Haihaisoft HUPlayer .4.5v - People use various types of media software to play back audio and video files in their PCs. While a majority of users stick with the bundled Windows Media player, some others opt for commercial and third party alternatives. If you want something ...

Norton Security with Backup - Symantec is an old time player in PC security and its various security suites with Norton brand name are used all over the world. With time, Norton security apps have been tweaked to consume fewer resources and they come with several bells and ...

VLC Media Player Portable - There are plenty of media player applications available for Windows and some of the popular ones are actually freeware. If you find the Windows media player inadequate or sluggish, give VLC media player a try. This versatile media player plays ...

New Downloads

BigCommerce ODBC Driver
(32/64 bit)

Devart ODBC Driver for
BigCommerce provides
high-performance and
feature-rich connectivity
solution for ODBC-based ...

J4L Barcode Vision for

Delphi barcode reader SDK for
barcode recognition. The
library can read (scan)
barcodes in images. It
supports code128, ...

Install Package IronOcr

IronOcr makes it simple to
read text and barcode content
from pictures & scanned
documents in your C# or VB.net

Virtual Serial Port Driver

Virtual Serial Port Driver by
Eltima creates virtual COM
port pairs in the system.
Using these ports serial
applications ...

ShellBrowser Delphi

The ShellBrowser components
give a Delphi programmer easy
access to the Windows Shell
functionality. The components
look ...


Make your application
upgradable over the internet
with this easy tool. Automatic
upgrages minimize the chance
for a user ...

Nevron Barcode for SSRS

Nevron Barcode for Reporting
Services is an advanced report
for all versions of Microsoft
Reporting Services. It is ...

VScodePrint 2015

Microsoft Visual Studio
Extension to print source code
in color. Print a complete
Solution, selected projects,
project ...


With WebAcappella you can
easily create and design web
pages without the need of HTML


This is a useful software
packer that doesn\'t take a
lot of time to master, and
will having you packing and
compressing ...

GroupDocs.Annotation for

A lightweight .NET library for
HTML5-based document
annotation. The library is
designed for easy integration
into web, ...

Smart .NET Obfuscator

Skater Smart .NET Obfuscator
is an obfuscation tool for
.NET code protection. It
implements software protection