PhoenixmlDb.XQuery

IDocumentResolver

Resolves document URIs to XDM documents for the XQuery fn:doc() and fn:collection() functions.

#IDocumentResolver

Namespace: PhoenixmlDb.XQuery

Resolves document URIs to XDM documents for the XQuery

fn:doc()

and

fn:collection()

functions.

This is the extension point for document resolution in the XQuery engine. When a query calls doc("orders.xml") or collection("archive"), the engine delegates to this interface to locate and load the documents.

Implementations can load documents from the filesystem, HTTP URLs, databases, in-memory caches, or any other source. The URI scheme is entirely up to the implementation.

Most developers do not need to implement this interface — the built-in PhoenixmlDb storage layer provides its own implementation. Implement it when you need to expose external documents to XQuery expressions, such as for cross-system joins or federated queries.

#Example

csharp
public class FileDocumentResolver : IDocumentResolver
{
    public XdmDocument? ResolveDocument(string uri)
    {
        if (!File.Exists(uri)) return null;
        return XdmDocument.Load(File.OpenRead(uri));
    }

    public bool IsDocumentAvailable(string uri) => File.Exists(uri);

    public IEnumerable<XdmNode> ResolveCollection(string? uri)
    {
        var dir = uri ?? "default-collection";
        return Directory.GetFiles(dir, "*.xml").Select(f => ResolveDocument(f)!);
    }
}
                                  

#Methods

#IsDocumentAvailable(String)

Checks whether a document is available at the given URI without loading it, corresponding to the XQuery

fn:doc-available()

function.

Parameters:

  • uri — The document URI.

Returns: true if the document exists and can be loaded; false otherwise.

#ResolveCollection(String)

Returns all documents in a named collection, corresponding to the XQuery

fn:collection()

function.

Parameters:

  • uri — The collection URI, or null for the default collection.

Returns: All document nodes in the collection. Returns an empty sequence if the collection is empty or unknown.

#ResolveDocument(String)

Loads a document by URI, corresponding to the XQuery

fn:doc()

function.

Parameters:

  • uri — The document URI (file path, URL, or logical name).

Returns: The document node, or null if the document cannot be resolved.

#See also

  • QueryEngine