开发者

using file:serialize to write files with eXist db

开发者 https://www.devze.com 2023-02-18 15:11 出处:网络
I\'m trying to use the file:serialize function to write some content to a file using eXist-db. Here\'s the code I\'m using, it\'s just a login and the call of the serialize function.

I'm trying to use the file:serialize function to write some content to a file using eXist-db.

Here's the code I'm using, it's just a login and the call of the serialize function. someFunction just returns a node with some content.

let $null := xdb:login("/db", "*", "*"), $someBool := file:serialize(local:someFunction(),"test.txt","")

The very helpful error I'm getting is:

Error found

Message: Error null

I'm using version 1.4.0 on Ubuntu, a开发者_运维知识库nd I enabled the file module (and built it). What am I missing here?

Thanks!


I had the same problem like OP.
Turns out your third parameter to the serialize function is wrong.

This:

$someBool := file:serialize(local:getSomething(),"test.txt","")

Should be this:

$someBool := file:serialize(local:getSomething(),"test.txt",())

As the third parameter has to be a sequence, not a string.

Hope it helps.


let $null := xdb:login("/db", "*", "*")

First, let's rule something out: the 2nd and 3rd parameters should be the username and password of a dba user. See the docs for xmldb:login() and file:serialize().


This is the function in which I want to write the file, so I'm just trying to write some test content:

declare function local:getSomething() as node(){
    let $s := "something"
    return
        <test>{$s}</test>
};
declare function local:mainPage() as node()?
{
   let $null := xdb:login("/db", "*", "*"),
       $someBool := file:serialize(local:getSomething(),"test.txt","") 
   return
    <test>Succes!</test>
};
0

精彩评论

暂无评论...
验证码 换一张
取 消