JAVA xquery: accessing documents

Monday, 1 October 2018 · 3 messages · last reply 2 Oct 2018
JS
Jan Stapel1 Oct 2018 00:41 #
Hello, Normally (few basex-versions ago) I did:
session.execute("open main");
         session.execute("xquery doc("users.xml")//users");
But now, this results in basex interpreting the doc()-path as relative to it's home-directory thus cannot find the resource.. "xquery doc("main/users.xml")//users" gives the correct results. Do we no longer open a database but writing the full path of the document instead? Whats the performance of this if accessing multiple documents of the same database during runtime? -regards, jan
CG
Christian Grün1 Oct 2018 14:41 #
Hi Jan, In terms of performance, it’s advisable to open the database in advance if you run several commands on it. Otherwise, you can simply address it via XQuery. If you use fn:doc, the first path segment of the function argument must be the name of your database [1]. db:open will be the safer option, because there won’t be any attempt to find a non-retrievable resource on the local filesystem. Hope this helps, Christian [1] http://docs.basex.org/wiki/Databases#XML_Documents
Quoted text · Jan Stapel · 27 lines
On Mon, Oct 1, 2018 at 12:41 AM Jan Stapel <janstapel00 at hotmail.com> wrote: > > Hello, > > Normally (few basex-versions ago) I did: > > session.execute("open main"); > session.execute("xquery doc("users.xml")//users"); > > But now, this results in basex interpreting the doc()-path as relative > to it's home-directory thus cannot find the resource.. > > "xquery doc("main/users.xml")//users" gives the correct results. > > > Do we no longer open a database but writing the full path of the > document instead? > > Whats the performance of this if accessing multiple documents of the > same database during runtime? > > > -regards, > > jan > >
CG
Christian Grün2 Oct 2018 13:37 #
Hi Jan (cc to the list),
Quoted text · Christian Grün · 4 lines
> why is doc("users.xml") not working although the database has been > opened before? It says "resource 'home/jan/..../users.xml not found'.. > > doc("main/users.xml") is working.
See the following lines in our documentation: If the argument of fn:doc or fn:collection does not start with a valid database name, or if the addressed database does not exist, the string is interpreted as URI reference, and the documents found at this location will be returned. If the DEFAULTDB option is turned on, the path argument of the fn:doc or fn:collection function will first be resolved against the globally opened database. Hope this helps, Christian

⚡Generated with XQuery