XQuery all files under a specific directory?
Asked Answered
N

3

14

Can I use XQuery to query all XML files under a specific directory? All the XML files have the same structure.

Also, from what I have seen you can XQuery many files but you need to write the names of them in the query. In my case, I need to query 500 XML files with quite different names each. So Is there a way I can say:

for $x in doc("ALL files under a specific directory")/Foo
return $x/Something
Neeley answered 8/4, 2011 at 23:29 Comment(2)
Good question, +1. See my answer for a complete and probably the shortest and most standard solution.Aeneous
I wanted to go into subfolders. I found this option for the collection function in the DataDirect web site: '?select=*.xml;recurse=yes'Drench
A
11

Use the collection() function.

In its Saxon implementation, one can use:

collection('file:///a/b/c/d?select=*.xml')
Aeneous answered 9/4, 2011 at 5:16 Comment(1)
Zorba collection documentation hereWashhouse
G
1

For MarkLogic:

for $x in cts:search(fn:doc()/Foo, cts:directory-query("/target/directory/"))
return $x/Something
Gloaming answered 11/4, 2011 at 12:32 Comment(0)
H
0

Use the collection() function.

In its Saxon implementation, one can use: collection('file:///a/b/c/d?select=*.xml')

I tried this example under Windows 7 with Saxon HE 9.5.1.5J. The URI then takes a different form, for example: file:/C:/work/GIT/managedSoftwareDoc/experimenting/xQuery?select=*.xml

Hieroglyphic answered 17/8, 2014 at 18:11 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.