BaseX fn:collection() questions

Saturday, 30 January 2016 · 3 messages · last reply 31 Jan 2016
BD
Bridger Dyson-Smith30 Jan 2016 23:40 #
Hi all, I'm using BaseX 8.3.1 and am trying to access a directory structure like so:
declare namespace t = "http://www.tei-c.org/ns/1.0";
for $ready in
fn:collection("/usr/home/bridger/Documents/foo/bar/?select=*.xml;recurse=yes")/t:TEI
let $title := fn:data($ready/t:teiHeader/t:fileDesc/t:titleStmt/t:title)
return $title
The structure under bar/ looks something like bar/ 001/ 001.xml 002/ 002.xml 003/ 003.xml ... ... 009/ 009.xml Does BaseX's fn:collection() allow for recursion into a directory structure like this with the /?select syntax options or should I use a combination of functions from the File Module to move through these directories? Note: I'm not pulling these files into a database, rather I'm just using BaseX as a query processor. Thanks for your time. Best, Bridger
CG
Christian Grün31 Jan 2016 13:28 #
Hi Bridger,
Quoted text · Bridger Dyson-Smith · 1 line
> fn:collection("/usr/home/bridger/Documents/foo/bar/?select=*.xml;recurse=yes")/t:TEI
As far as I know, the "recurse" option is Saxon-Specific. But by default, all XML files in the directory and its sub-directories will be recursed. Have you tried to use fn:collction as follows?
  fn:collection("/usr/home/bridger/Documents/foo/bar/")
Another, more flexible alternative is to use the File Module (which, by the way, is also supported by Saxon):
  let $root :="/usr/home/bridger/Documents/foo/bar/"
  for $file in file:list($root, true(), "*.xml")
  return fn:doc($root || $file)
Hope this helps, Christian
Quoted text · Bridger Dyson-Smith · 27 lines
> let $title := fn:data($ready/t:teiHeader/t:fileDesc/t:titleStmt/t:title) > return $title > > The structure under bar/ looks something like > bar/ > 001/ > 001.xml > 002/ > 002.xml > 003/ > 003.xml > ... > ... > 009/ > 009.xml > > Does BaseX's fn:collection() allow for recursion into a directory structure > like this with the /?select syntax options or should I use a combination of > functions from the File Module to move through these directories? > > Note: I'm not pulling these files into a database, rather I'm just using > BaseX as a query processor. > > Thanks for your time. > Best, > Bridger >
BD
Bridger Dyson-Smith31 Jan 2016 16:05 #
Hi Christian, that's perfect, thank you very much. Also, thank you for the File Module example -- beyond some reading I hadn't started to explore its uses. Cheers, Bridger
Quoted text · Christian Grün · 55 lines
On Sun, Jan 31, 2016 at 7:28 AM, Christian Grün <christian.gruen at gmail.com> wrote: > Hi Bridger, > > > > fn:collection("/usr/home/bridger/Documents/foo/bar/?select=*.xml;recurse=yes")/t:TEI > > As far as I know, the "recurse" option is Saxon-Specific. But by > default, all XML files in the directory and its sub-directories will > be recursed. Have you tried to use fn:collction as follows? > > fn:collection("/usr/home/bridger/Documents/foo/bar/") > > Another, more flexible alternative is to use the File Module (which, > by the way, is also supported by Saxon): > > let $root :="/usr/home/bridger/Documents/foo/bar/" > for $file in file:list($root, true(), "*.xml") > return fn:doc($root || $file) > > Hope this helps, > Christian > > > > > let $title := fn:data($ready/t:teiHeader/t:fileDesc/t:titleStmt/t:title) > > return $title > > > > The structure under bar/ looks something like > > bar/ > > 001/ > > 001.xml > > 002/ > > 002.xml > > 003/ > > 003.xml > > ... > > ... > > 009/ > > 009.xml > > > > Does BaseX's fn:collection() allow for recursion into a directory > structure > > like this with the /?select syntax options or should I use a combination > of > > functions from the File Module to move through these directories? > > > > Note: I'm not pulling these files into a database, rather I'm just using > > BaseX as a query processor. > > > > Thanks for your time. > > Best, > > Bridger > > >

⚡Generated with XQuery