XQueryX

Represent query syntax as XML and compile it through the same XQuery execution pipeline.

DCoding.Xml 1.0.1Example: Community

Packages: DCoding.Xml.XQueryX

On this page

Query syntax as an XML document

XQueryX is an XML representation of XQuery syntax. It can be useful when a tool generates, inspects or exchanges queries as XML. It is not the XML data being queried, a serialization of the query result, or a replacement runtime engine. The query still has to be compiled and executed.

Text → XQueryX → compiled query

Convert creates the XQueryX document. Compile turns that document into the reusable query consumed by XQueryProcessor.Execute. Check the result at each boundary. The example prints the standard XQueryX namespace and the computed value 60. It requires no external resource access.

C#
using DCoding.Xml.Serialization;
using DCoding.Xml.XQuery;
using DCoding.Xml.XQueryX;

var options = new XQueryXProcessingOptions { Version = XQueryXVersion.XQueryX31 };
var converted = XQueryXProcessor.Convert("sum((10, 20, 30))", options);
if (!converted.Success)
    throw new InvalidOperationException(string.Join("; ",
        converted.Diagnostics.Select(d => $"{d.Id}: {d.Message}")));

var compiled = XQueryXProcessor.Compile(converted.Document!, options);
if (!compiled.Success)
    throw new InvalidOperationException(string.Join("; ",
        compiled.Diagnostics.Select(d => $"{d.Id}: {d.Message}")));

var result = XQueryProcessor.Execute(compiled.CompiledQuery!);
if (!result.Success)
    throw new InvalidOperationException(string.Join("; ",
        result.Diagnostics.Select(d => $"{d.Id}: {d.Message}")));

Console.WriteLine(converted.Document!.Root!.Name.NamespaceName);
Console.WriteLine(XdmSerializer.Serialize(result.Value!));

Download example project ZIP · C# · .NET 8 / 10 / 11

Choose grammar and query semantics separately

XQueryXProcessingOptions.Version selects the XML grammar profile: XQueryX10, XQueryX30 or XQueryX31. CompileOptions.LanguageVersion selects the underlying XQuery language semantics. Keep them compatible with any version declaration in the module. Selecting a grammar does not activate optional Full Text, Update or schema-aware capabilities.

Treat exchanged queries as executable input

Use finite XQueryXResourceLimits when accepting XML query documents. A well-formed XML document is not necessarily valid XQueryX; a valid XQueryX document is not necessarily a statically valid query. Reader and Stream overloads leave caller-owned inputs open. Resource resolvers, variables and other dynamic authority must still be supplied independently for execution.

Common questions

Will the original query text round-trip byte for byte?

Do not use syntax conversion as a source-format preservation contract. Formatting and equivalent syntax spellings may change. Check semantics and results; CanonicalQueryText is decoded query text, not a saved copy of the original file.

Does a saved XQueryX document retain credentials?

The syntax representation grants no credentials or resolver permissions. Your host supplies current execution authority explicitly. Avoid putting secrets into query literals or external variable defaults.

Language specification

The W3C XQueryX specification defines the representation; the XQuery guide explains execution and dynamic parameters.

Sign in

Choose how you would like to sign in.

Email + password Google Microsoft
Create accountForgot password?