Update Module question: update:apply
Sunday, 25 February 2018 · 3 messages · last reply 26 Feb 2018
BD
Bridger Dyson-Smith25 Feb 2018 04:14 #
Hi all --
I was working with the
update:apply example [1], and it throws an error: [XPTY0004] Cannot convert xs:string to node(): "doc.xml".
I'm a little confused by this: if I modify the example, and change the last to
db:add('existing-db', 'doc.xml') (which is db:add#1, right?), it works fine. However, keeping the local:update and trying to use db:add#1 generates another error:
[XPST0017] db:add(database,input[,path[,options]]): 1 argument supplied, 2-4 expected
Would someone be able to shed some light on where this is going wrong?
Thanks,
Bridger
[1] http://docs.basex.org/wiki/Update_Module#update:applyCG
Christian Grün26 Feb 2018 12:10 #
Hi Bridger,
Quoted text · Bridger Dyson-Smith · 2 lines
> I was working with the update:apply example [1], and it throws an error: > [XPTY0004] Cannot convert xs:string to node(): "doc.xml".
Thanks for the observation. A wrong static type for
db:add was specified in the BaseX code; this is why you got the misleading error message (one rewriting step failed). It is working now in the latest version of BaseX [1].Quoted text · Bridger Dyson-Smith · 2 lines
> `db:add('existing-db', 'doc.xml')` (which is db:add#1, right?), it works > fine.
If the "#" character is used, a »named function reference« will be created for the given function and the given number of arguments.
db:add#1 indicates that the function item, which is created for the db:add function, can be invoked with 1 argument later on.
The following variants (and surely various others) can be used to invoke db:add: (: Simple function call :)
db:add('existing-db', 'doc.xml') (: Named function reference :)
updating
db:add#2('existing-db', 'doc.xml')
(: Partially applied function :)
updating db:add(?,?)('existing-db', 'doc.xml') (: Function item :)
updating function($db, $doc) {
db:add($db, $doc)
}('existing-db', 'doc.xml')The leading 'updating' keyword is required to indicate that the function item to be called is updating.
Hope this helps,
Christian
[1] http://files.basex.org/releases/latest/
BD
Bridger Dyson-Smith26 Feb 2018 22:35 #
Christian -
as always, thank you for the informative response.
Quoted text · Christian Grün · 34 lines
On Mon, Feb 26, 2018 at 6:10 AM, Christian Grün <christian.gruen at gmail.com> wrote: > Hi Bridger, > > > I was working with the update:apply example [1], and it throws an error: > > [XPTY0004] Cannot convert xs:string to node(): "doc.xml". > > Thanks for the observation. A wrong static type for db:add was > specified in the BaseX code; this is why you got the misleading error > message (one rewriting step failed). It is working now in the latest > version of BaseX [1]. > > > `db:add('existing-db', 'doc.xml')` (which is db:add#1, right?), it works > > fine. > > If the "#" character is used, a »named function reference« will be > created for the given function and the given number of arguments. > db:add#1 indicates that the function item, which is created for the > db:add function, can be invoked with 1 argument later on. > > The formal term is much appreciated :). > The following variants (and surely various others) can be used to invoke > db:add: > > (: Simple function call :) > db:add('existing-db', 'doc.xml') > > (: Named function reference :) > updating db:add#2('existing-db', 'doc.xml') > > (: Partially applied function :) > updating db:add(?,?)('existing-db', 'doc.xml') > > And, this notation is Really Cool - more neat stuff to try getting my head
around.
Quoted text · Christian Grün · 10 lines
> (: Function item :) > updating function($db, $doc) { > db:add($db, $doc) > }('existing-db', 'doc.xml') > > The leading 'updating' keyword is required to indicate that the > function item to be called is updating. > > Hope this helps, >
Absolutely!
Quoted text · Christian Grün · 4 lines
> Christian > > [1] http://files.basex.org/releases/latest/ >
Cheers,
Bridger
Written for BaseX 8.6. BaseX may have changed since: please check the current documentation.
⚡Generated with XQuery