开发者

XPath matches() using regular expressions in C#

开发者 https://www.devze.com 2023-03-14 15:31 出处:网络
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).

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 开发者_Go百科an xpath of

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


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/


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消