/// <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);
        }
Example #2
0
		public bool Matches(XPathExpression xpath, XPathNavigator source)
		{
			xpath = (XPathExpression)xpath.Clone();
			xpath.SetContext(this);
			return source.Matches(xpath);
		}
Example #3
0
		public XPathNavigator SelectSingleNode(XPathExpression xpath, XPathNavigator source)
		{
			xpath = (XPathExpression)xpath.Clone();
			xpath.SetContext(this);
			return source.SelectSingleNode(xpath);
		}
Example #4
0
		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;
		}
 /// <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();
 }
        /// <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();
        }