Figaro - The XML Database for the .NET Framework
CopyC#
In XQuery FLWOR expressions, you can set variables using the let clause. In addition to this, you can use variables that are defined by Figaro. You define these variables using SetVariableValue.
You can declare as many variables this way as you need. Note that the variables that you declare this way can only be used from within a predicate. For example:
using (var mgr = new XmlManager(ManagerInitOptions.AllowExternalAccess) { DefaultContainerType = XmlContainerType.WholeDocContainer }) { using (var cont = mgr.OpenContainer(baseUri + testdb,ContainerSettings.Create)) { //create the query context var queryContext = mgr.CreateQueryContext(EvaluationType.Eager); //set some namespace values queryContext.SetNamespace("fruits","http://groceryItem.dbxml/fruits"); queryContext.SetNamespace("vegetables", "http://groceryItem.dbxml/vegetables"); cont.AddAlias("testdb"); queryContext.EvaluationType = EvaluationType.Eager; queryContext.SetVariableValue("myVar", "Artichoke"); string xquery = "collection('testdb')/product[item=$myVar]"; //ALWAYS close the container! cont.Close(); } }