将结果输出到文本文件时出现 XQuery 基数错误
XQuery cardinality error on outputting results to text file
使用 XQuery 3.1(在 eXistDB 4.4 下),我有一个函数 returns 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
动作时,它returns一个错误:
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";
我不知道你调用的函数,但也许你应该使用 string-join() 将 710 个字符串合并为一个,并使用换行符分隔符。
错误信息看起来很清楚。 schedule:deposition-textfile()
的 return 类型不被 xmldb:store()
接受。您需要一个字符串,而不是 710。
要么更改函数的 return 类型,要么在 xQuery function documentation 中搜索 xmldb:store
以找到适合您的 return 类型的替代方法。
使用 XQuery 3.1(在 eXistDB 4.4 下),我有一个函数 returns 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
动作时,它returns一个错误:
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";
我不知道你调用的函数,但也许你应该使用 string-join() 将 710 个字符串合并为一个,并使用换行符分隔符。
错误信息看起来很清楚。 schedule:deposition-textfile()
的 return 类型不被 xmldb:store()
接受。您需要一个字符串,而不是 710。
要么更改函数的 return 类型,要么在 xQuery function documentation 中搜索 xmldb:store
以找到适合您的 return 类型的替代方法。