本文整理汇总了C#中System.Xml.XPath.XPathExpression.Clone方法的典型用法代码示例。如果您正苦于以下问题:C# XPathExpression.Clone方法的具体用法?C# XPathExpression.Clone怎么用?C# XPathExpression.Clone使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Xml.XPath.XPathExpression
的用法示例。
在下文中一共展示了XPathExpression.Clone方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Select
/// <summary>
/// Selects a node set, using the specified XPath expression.
/// </summary>
/// <param name="navigator">A source XPathNavigator.</param>
/// <param name="expression">An XPath expression.</param>
/// <param name="variables">A set of XPathVariables.</param>
/// <returns>An iterator over the nodes matching the specified expression.</returns>
public static XPathNodeIterator Select(this XPathNavigator navigator, XPathExpression expression, params XPathVariable[] variables)
{
if (variables == null || variables.Length == 0 || variables[0] == null)
return navigator.Select(expression);
var compiled = expression.Clone(); // clone for thread-safety
var context = new DynamicContext();
foreach (var variable in variables)
context.AddVariable(variable.Name, variable.Value);
compiled.SetContext(context);
return navigator.Select(compiled);
}
示例2: Matches
public bool Matches(XPathExpression xpath, XPathNavigator source)
{
xpath = (XPathExpression)xpath.Clone();
xpath.SetContext(this);
return source.Matches(xpath);
}
示例3: SelectSingleNode
public XPathNavigator SelectSingleNode(XPathExpression xpath, XPathNavigator source)
{
xpath = (XPathExpression)xpath.Clone();
xpath.SetContext(this);
return source.SelectSingleNode(xpath);
}
示例4: Evaluate
public bool Evaluate(XPathExpression xpath, XPathNavigator source, out object result)
{
xpath = (XPathExpression)xpath.Clone();
xpath.SetContext(this);
result = source.Evaluate(xpath);
if (xpath.ReturnType == XPathResultType.NodeSet)
{
if (((XPathNodeIterator)result).Count == 0)
result = null;
}
return result != null;
}
示例5: EvalXPathExpr
/// <summary>
/// Returns the string result from evaluating an xpath expression against the given document and context.
/// </summary>
public static string EvalXPathExpr(IXPathNavigable doc, XPathExpression xpe, CustomContext c) {
XPathExpression t = xpe.Clone();
t.SetContext(c);
return doc.CreateNavigator().Evaluate(t).ToString();
}
示例6: EvalXPathExpr
/// <summary>
/// This is used to get the string result from evaluating an XPath expression against the given
/// document and context.
/// </summary>
/// <param name="document">The document to use</param>
/// <param name="expression">The XPath expression to evaluate</param>
/// <param name="context">The context to use</param>
/// <returns>The evaluated expression result</returns>
/// <overloads>There are two overloads for this method</overloads>
public static string EvalXPathExpr(this IXPathNavigable document, XPathExpression expression,
CustomContext context)
{
XPathExpression t = expression.Clone();
t.SetContext(context);
return document.CreateNavigator().Evaluate(t).ToString();
}