首页 > 解决方案 > XQuery 集合 - 无法从目录中获取多个文件

问题描述

我正在尝试从在 XML 元素中具有特定字符串的目录中获取所有文件名。我为此使用此代码:

for $x in collection('file:///C:/Sricpts/Software20180101-V1.1.1/workspace/Data_PreProcessing?select=*.xml')
where matches($x, 'INSERT INTO')
return $x

但是,当我运行代码时,它会给出该错误:

[FODC0002] Resource 'C:/Program Files (x86)/BaseX/file:/file:///C:/Sricpts/Software20180101-V1.1.1/workspace/Data_PreProcessing?select=*.xml' does not exist.

我怎么解决这个问题?

非常感谢!

标签: xquerycollect

解决方案


如果使用 BaseX,则无需指定文件过滤器。指定目录中出现的所有 XML 文档都将添加到您的集合中:

for $x in collection('file:///C:/Sricpts/Software20180101- V1.1.1/workspace/Data_PreProcessing')
where matches($x, 'INSERT INTO')
return $x

如果您想更好地控制要选择的文档,可以利用File Module

let $root := 'C:\Sricpts\Software20180101- V1.1.1\workspace\Data_PreProcessing'
for $path in file:list($root, true(), '*.xml')
let $doc := doc($root || $path)
where matches($doc, 'INSERT INTO')
return $doc

推荐阅读