[feature] Support file: URIs in fn:collection() for filesystem directory querying#6192
[feature] Support file: URIs in fn:collection() for filesystem directory querying#6192joewiz wants to merge 1 commit intoeXist-db:developfrom
Conversation
| if (dynamicCollection != null) { | ||
| items.addAll(dynamicCollection); | ||
|
|
||
| } else if (collectionUri.getScheme() != null && collectionUri.getScheme().equals("file")) { |
There was a problem hiding this comment.
| } else if (collectionUri.getScheme() != null && collectionUri.getScheme().equals("file")) { | |
| } else if ("file".equals(collectionUri.getScheme()) { |
This would be even a simpler check...
fn:collection() now supports file: URIs to scan a directory for XML
files and return them as in-memory documents. This matches the behavior
of BaseX and Saxon.
Usage:
collection("file:///path/to/dir") (: all *.xml files :)
collection("file:///path/to/dir?select=*.xhtml") (: glob filter :)
Security: only DBA users can access file: URIs (same restriction as
fn:doc for file system access). Non-parseable files are silently
skipped. Non-existent directories throw FODC0002.
Implementation: in getCollectionItems(), checks if the URI scheme is
"file", scans the directory with DirectoryStream + glob pattern, and
parses each matching file via DocUtils.parse() into a memtree document.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
a0dec57 to
f5b2336
Compare
|
[This response was co-authored with Claude Code. -Joe] Good catch, @reinhapa — simplified to |
|
A few thoughts:
|
Summary
fn:collection()to supportfile:URIs, enabling queries over filesystem directoriesfn:collection("file:///path/to/dir")scans for*.xmlfiles by defaultfn:collection("file:///path/to/dir?select=*.xhtml")supports glob filtering (Saxon convention)file:URIs (security boundary, consistent withfn:doc())Motivation
BaseX and Saxon both support
collection("file:/path/to/dir")for querying filesystem directories. eXist'sfn:doc()already supportsfile:URIs butfn:collection()was limited to database collections only. The W3C spec saysfn:collection()is implementation-defined, making this a conformant extension.Test plan
collection("file:///tmp/test-xml/")returns XML documents?select=*.xhtmlglob filtering works🤖 Generated with Claude Code
Co-Authored-By: Claude Opus 4.6 (1M context) noreply@anthropic.com