/// <summary> /// Compile and execute an expression supplied as a <c>String</c>, with a given context item. /// </summary> /// <param name="expression">A string containing the source text of the XPath expression</param> /// <param name="contextItem">The context item to be used for evaluation of the XPath expression. /// May be null, in which case the expression is evaluated without any context item.</param> /// <returns>An <c>XdmValue</c> which is the result of evaluating the XPath expression.</returns> /// <exception cref="StaticError"> /// Throws a <c>Saxon.Api.StaticError</c> if there is any static error in the XPath expression. /// This includes both syntax errors, semantic errors such as references to undeclared functions or /// variables, and statically-detected type errors. /// </exception> /// <exception cref="DynamicError"> /// Throws a <c>Saxon.Api.DynamicError</c> if there is any dynamic error during evaluation of the XPath expression. /// This includes, for example, referring to the context item if no context item was supplied. /// </exception> public XdmValue Evaluate(String expression, XdmItem contextItem) { try { net.sf.saxon.s9api.XdmValue value = compiler.evaluate(expression, contextItem == null ? null : XdmItem.FromXdmItemItemToJXdmItem(contextItem)); return(XdmValue.Wrap(value.getUnderlyingValue())); } catch (JSaxonApiException err) { if (err.getCause() is JXPathException) { JXPathException xpathException = (JXPathException)err.getCause(); if (xpathException.isStaticError()) { throw new StaticError(err); } else { throw new DynamicError(err.getMessage()); } } else { throw new StaticError(err); } } }
/// <summary> /// Evaluate the expression, returning the result as an <c>XdmValue</c> (that is, /// a sequence of nodes, atomic values, and possibly function items such as maps and arrays). /// </summary> /// <remarks> /// Although a singleton result <i>may</i> be represented as an <c>XdmItem</c>, there is /// no guarantee that this will always be the case. If you know that the expression will return at /// most one node or atomic value, it is best to use the <c>EvaluateSingle</c> method, which /// does guarantee that an <c>XdmItem</c> (or null) will be returned. /// </remarks> /// <returns> /// An <c>XdmValue</c> representing the results of the expression. /// </returns> /// <exception cref="DynamicError"> /// Throws <c>Saxon.Api.DynamicError</c> if the evaluation of the XPath expression fails /// with a dynamic error. /// </exception> public XdmValue Evaluate() { try { net.sf.saxon.s9api.XdmValue value = selector.evaluate(); return(value == null ? null : XdmValue.Wrap(value.getUnderlyingValue())); } catch (JSaxonApiException err) { throw new DynamicError(err); } }
/// <summary> /// Evaluate the query, returning the result as an <c>XdmValue</c> (that is, /// a sequence of nodes and/or atomic values). /// </summary> /// <returns> /// An <c>XdmValue</c> representing the results of the query /// </returns> /// <exception cref="DynamicError">Throws a <c>DynamicError</c> if any run-time failure /// occurs while evaluating the query.</exception> public XdmValue Evaluate() { try { JXdmValue value = evaluator.evaluate(); return(XdmValue.Wrap(value.getUnderlyingValue())); } catch (JSaxonApiException err) { throw new DynamicError(err); } }
/// <summary> /// Call a global user-defined function in the compiled query. /// </summary> /// <remarks> /// If this is called more than once (to evaluate the same function repeatedly with different arguments, /// or to evaluate different functions) then the sequence of evaluations uses the same values of global /// variables including external variables (query parameters); the effect of any changes made to query parameters /// between calls is undefined. /// </remarks> /// <param name="function"> /// The name of the function to be called /// </param> /// <param name="arguments"> /// The values of the arguments to be supplied to the function. These /// must be of the correct type as defined in the function signature (there is no automatic /// conversion to the required type). /// </param> /// <exception cref="ArgumentException">If no function has been defined with the given name and arity /// or if any of the arguments does not match its required type according to the function /// signature.</exception> /// <exception cref="DynamicError">If a dynamic error occurs in evaluating the function. /// </exception> public XdmValue CallFunction(QName function, XdmValue[] arguments) { try { JXdmValue[] vr = new JXdmValue[arguments.Length]; for (int i = 0; i < arguments.Length; i++) { vr[i] = XdmValue.FromGroundedValueToJXdmValue(arguments[i].value); } JSequence result = evaluator.callFunction(function.UnderlyingQName(), vr).getUnderlyingValue(); return(XdmValue.Wrap(result)); } catch (JSaxonApiException e) { throw new DynamicError(e); } }
/// <summary> /// Get the value that has set for a schema processor (a parameter defined in the schema using the <c>saxon:param</c> /// extension) /// </summary> /// <param name="name">the parameter whose name is required</param> /// <returns>the value that has been set for the parameter, or the EmptySequence if no value has been set</returns> public XdmValue GetParameter(QName name) { net.sf.saxon.s9api.XdmValue value = schemaValidator.getParameter(name.UnderlyingQName()); return(value == null ? null : XdmValue.Wrap(value.getUnderlyingValue())); }