Is it possible to add/use custom functions inside .Net XPath evaluator? For example, I’d like to do a search with regex, which xPath 1.0 does not support. Can I add something similar to
bool RegexSearch(string regex, string text)
and register it with something similar to
xPathNavigator.RegisterFunction("regex-search",RegexSearch);
so I can use it inside my xPath queries?
Yes, you will need to inherit from
System.Xml.Xsl.XsltContext. Please check this link for details of the implementation.Using ms: xpath functions inside XPathExpression
MSDN – Adding Custom Functions to XPath
Microsoft KB Article, the original link on MS is dead. But I manage to find an alternate –
HOW TO: Implement and Use Custom Extension Functions When You Execute XPath Queries in Visual C# .NET.