【问题标题】:Use c# functions inside XPath expressions在 XPath 表达式中使用 c# 函数
【发布时间】:2012-03-16 06:39:32
【问题描述】:

是否可以在 .Net XPath 评估器中添加/使用自定义函数?例如,我想使用 xPath 1.0 不支持的正则表达式进行搜索。我可以添加类似的东西

bool RegexSearch(string regex, string text)

并用类似于

的东西注册它
xPathNavigator.RegisterFunction("regex-search",RegexSearch);

所以我可以在我的 xPath 查询中使用它?

【问题讨论】:

    标签: c# xpath


    【解决方案1】:

    是的,您需要从System.Xml.Xsl.XsltContext 继承。有关实施的详细信息,请查看此链接。

    Using ms: xpath functions inside XPathExpression

    MSDN - Adding Custom Functions to XPath

    Microsoft 知识库文章,MS 上的原始链接是dead。但我设法找到了替代品—— HOW TO: Implement and Use Custom Extension Functions When You Execute XPath Queries in Visual C# .NET.

    【讨论】:

    猜你喜欢
    • 2014-03-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-02-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多