0

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, and I enabled the file module (and built it). What am I missing here?

Thanks!

Joe Wicentowski
  • 5,159
  • 16
  • 26
rx1234
  • 1

3 Answers3

1

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.

acco
  • 11
  • 1
0
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().

Joe Wicentowski
  • 5,159
  • 16
  • 26
  • Yes I know, but for this example on stackoverflow I replaced them with stars. – rx1234 Mar 23 '11 at 10:32
  • Okay, good. Next: is this your entire query? Do you have a "return" clause? A "let" without a "return" is an orphaned expression. If you've got a complete query, can you simplify the file:serialize() by replacing it with, say, ? Any luck? – Joe Wicentowski Mar 24 '11 at 23:15
0

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>
};
r1234
  • 1
  • 1
  • 1