0

Using XQuery 3.1 (under eXistDB 4.4), I have a function which returns a serialized output of 710 delimited rows like these:

MS609-0001~ok~0001~1r~Deposition~De_Manso_Sanctarum_Puellarum_1~self~1245-05-27~Arnald_Garnier_MSP-AU~self
MS609-0002~ok~0002~1r~Deposition~De_Manso_Sanctarum_Puellarum_1~MS609-0001~1245-05-27~Guilhem_de_Rosengue_MSP-AU~MS609-0001
MS609-0003~ok~0003~1r~Deposition~De_Manso_Sanctarum_Puellarum_1~MS609-0001~1245-05-27~Hugo_de_Mamiros_MSP-AU~MS609-0001

I get the above serialized results in another function that should store it in the directory /db/apps/deheresi/documents as a flatfile depositions.txt

let $x := schedule:deposition-textfile()

return xmldb:store(concat($globalvar:URIdb,"documents"), "deposition.txt", $x)

But when I execute the xmldb:store action, it returns an error:

Description: err:XPTY0004 checking function parameter 3 
in call xmldb:store(untyped-value-check[xs:string, 
concat("/db/apps/deheresi/", "documents")], "depositions.txt", $x): 

XPTY0004: The actual cardinality for parameter 3 does not 
match the cardinality declared in the function's signature: 
xmldb:store($collection-uri as xs:string, 
$resource-name as xs:string?, 
$contents as item()) xs:string?. 

Expected cardinality: exactly one, got 710. 

How do I get these serialized results into the text file?

Thanks in advance.

UPDATE: I tried wrapping the serialized output in <result> and that fixes the problem of cardinality, BUT it writes the <result> element to the file as plain text:

<result>MS609-0001~ok~0001~1r~Deposition~De_Manso_Sanctarum_Puellarum_1~self~1245-05-27~Arnald_Garnier_MSP-AU~self
MS609-0002~ok~0002~1r~Deposition~De_Manso_Sanctarum_Puellarum_1~MS609-0001~1245-05-27~Guilhem_de_Rosengue_MSP-AU~MS609-0001
MS609-0003~ok~0003~1r~Deposition~De_Manso_Sanctarum_Puellarum_1~MS609-0001~1245-05-27~Hugo_de_Mamiros_MSP-AU~MS609-0001</result>

Even if I add:

declare option exist:serialize "method=text";
jbrehr
  • 775
  • 6
  • 19

2 Answers2

2

I don't know the function you are calling, but perhaps you should use string-join() to combine the 710 strings into one, with a newline separator.

Michael Kay
  • 156,231
  • 11
  • 92
  • 164
2

The error message seems quite clear. The return type of schedule:deposition-textfile() is not acceptable to xmldb:store(). You want a single string, not 710.

Either change the return type of your function, or search the xQuery function documentation for xmldb:store to find a suitable alternative for your returntype.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
duncdrum
  • 723
  • 5
  • 13
  • That fixed it: I had forgotten to put `as xs:string` as return type on the original function. Thanks. – jbrehr Dec 01 '18 at 10:15