PhoenixmlDb.XQuery

XQueryParserFacade

Public API for parsing XQuery 3.1 source text into an abstract syntax tree (AST).

#XQueryParserFacade

Namespace: PhoenixmlDb.XQuery.Parser

Public API for parsing XQuery 3.1 source text into an abstract syntax tree (AST).

This class provides two parsing strategies:

The returned XQueryExpression AST can be inspected, transformed, or passed directly to QueryEngine.Compile for compilation and execution. This is useful for syntax validation without execution, AST-level transformations, or building tooling such as formatters and linters.

#Example

Parse and validate syntax:

csharp
var parser = new XQueryParserFacade();
if (parser.TryParse("for $x in (1,2,3) return $x * 2", out var errors) is { } ast)
    Console.WriteLine("Valid XQuery");
else
    foreach (var error in errors)
        Console.Error.WriteLine($"Line {error.Line}: {error.Message}");
                                  

#Properties

Name Description
AllowNamespaceAxis When true, the parser accepts XPath/XSLT-only constructs that XQuery rejects — currently the namespace:: axis (XQuery raises XQST0134, but XPath 3.1 and XSLT 3.0 retain it as an optional axis used by stylesheets like DocBook xslTNG). Default false preserves strict XQuery semantics.
AllowRawAmpersand When true, a raw & character is accepted inside string literals and is treated as a literal ampersand rather than the start of an entity reference. XPath (used by XSLT stylesheets) has no entity references — the & was already decoded to & by the XML parser before the expression text reached this parser — so an XPath string literal can legitimately contain a bare & (e.g. the W3C regex conformance test regex-070 mode j uses 'Special characters$&'). Default false preserves strict XQuery semantics, under which & must introduce a predefined entity reference or character reference.
NormalizeLineEndings Whether to apply XQuery's source-level end-of-line normalization (§A.2.1) before parsing. Default true, which is correct for a query FILE.

#Methods

#Parse(String)

Parses an XQuery expression string into an AST, throwing on any syntax error.

Parameters:

  • xquery — The XQuery source text. Must not be null.

Returns: The root XQueryExpression node of the parsed AST.

Exceptions:

See also: XQueryParserFacade.TryParse

#TryParse(String,Collections.Generic.IReadOnlyList<PhoenixmlDb.XQuery.Parser.ParseError>@)

Attempts to parse an XQuery expression without throwing on syntax errors.

Parameters:

  • xquery — The XQuery source text.

  • errors — When the method returns null, contains one or more ParseError instances with location details. Empty on success.

Returns: The parsed AST on success, or null if parsing failed.

Unlike

, this method never throws for syntax errors. It returns

null

and populates

with all parse errors including line and column information. This is the preferred method for interactive validation scenarios.

See also: XQueryParserFacade.Parse

#Fields

Name Description
MaxParseDepth Maximum ANTLR parser rule-invocation nesting depth accepted before the parse is aborted with a catchable XQueryParseException. The generated recursive-descent parser (and the visitor that later walks its tree) recurse once per grammar rule, so an adversarially deep query — e.g. thousands of nested parentheses or predicates — would otherwise exhaust the native call stack and abort the process with an uncatchable StackOverflowException on untrusted input.