使用XQuery3.1(在eXistDB4.4下(,我有一个函数,它返回710个分隔行的串行输出,如下所示:
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
我在另一个函数中得到了上面的序列化结果,该函数应该将其作为平面文件depositions.txt
存储在目录/db/apps/deheresi/documents
中
let $x := schedule:deposition-textfile()
return xmldb:store(concat($globalvar:URIdb,"documents"), "deposition.txt", $x)
但当我执行xmldb:store
操作时,它返回一个错误:
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.
如何将这些序列化的结果放入文本文件?
提前谢谢。
更新:我尝试在<result>
中包装序列化输出,这修复了基数问题,但它将<result>
元素以纯文本形式写入文件:
<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>
即使我加上:
declare option exist:serialize "method=text";
错误消息似乎很清楚。schedule:deposition-textfile()
的返回类型对于xmldb:store()
是不可接受的。你想要一个字符串,而不是710。
更改函数的返回类型,或者在xQuery函数文档中搜索xmldb:store
,以找到适合您的返回类型的替代方法。
我不知道您正在调用的函数,但也许您应该使用字符串join((将710个字符串组合为一个,并使用换行符。