David Thielen
David Thielen

Reputation: 32996

XPath matches() using regular expressions in C#

Update: I wrote up what I did, with source code and things to watch for, at - Adding XPath 2.0 functionality and variables to .NET XPath (my blog).

Is there a way to pass a regular expression to matches() for an XPath statement in .NET?

Example: do an xpath of

"/windward-studios/Employees/Employee[matches(string(LastName), '.*A?B[12]C.*')]"

Upvotes: 3

Views: 4675

Answers (2)

Michael Kay
Michael Kay

Reputation: 163587

Microsoft's XSLT processor does not support XSLT 2.0, but there are at least two others available on .NET that do: Saxon and XQSharp.

Microsoft basically decided some time ago to go down a proprietary route with Linq, and if you want to stick with a standards-based approach, you will have to go to third parties.

Upvotes: 0

Richard Schneider
Richard Schneider

Reputation: 35477

XPath 2.0 supports the matches function. However, .Net implements XPath 1.0.

You would need to add a custom function to implement match. See http://msdn.microsoft.com/en-us/library/ms950806.aspx

It looks like the Mvp.Xml Project: EXSLT.NET module implements most of XPath 2.0; including matches. See http://mvp-xml.sourceforge.net/exslt/

Upvotes: 4

Related Questions