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
Nick J.
  • 143
  • 1
  • 4

3 Answers3

11

Use the collection() function.

In its Saxon implementation, one can use:

collection('file:///a/b/c/d?select=*.xml')
Ares
  • 1,411
  • 1
  • 19
  • 35
Dimitre Novatchev
  • 240,661
  • 26
  • 293
  • 431
  • Zorba collection documentation [here](http://cf.zorba-xquery.com.s3.amazonaws.com/doc/zorba-0.9.4/zorba/html/collections.html) – Pete Oct 11 '13 at 03:24
1

For MarkLogic:

for $x in cts:search(fn:doc()/Foo, cts:directory-query("/target/directory/"))
return $x/Something
Dave Cassel
  • 8,352
  • 20
  • 38
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

Martijn Dirkse
  • 543
  • 7
  • 16