将结果输出到文本文件时出现XQuery基数错误
使用XQuery 3.1(在eXistDB 4.4下),我有一个函数返回710个分隔行的序列化输出,如下所示:将结果输出到文本文件时出现XQuery基数错误,xquery,exist-db,Xquery,Exist Db,使用XQuery 3.1(在eXistDB 4.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~G
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>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>
我不知道您正在调用的函数,但也许您应该使用string-join()将710个字符串组合成一个带有换行符的字符串。我不知道您正在调用的函数,但也许您应该使用string-join()将710个字符串组合成一个带有换行符的字符串。错误消息似乎很清楚。
xmldb:store()
不接受schedule:deposition-textfile()
的返回类型。您需要的是单个字符串,而不是710
更改函数的返回类型,或搜索
xmldb:store
以找到适合您的返回类型的替代方法 错误信息似乎很清楚。xmldb:store()
不接受schedule:deposition-textfile()
的返回类型。您需要的是单个字符串,而不是710
更改函数的返回类型,或搜索
xmldb:store
以找到适合您的返回类型的替代方法 这就解决了问题:我忘记将作为xs:string
作为原始函数的返回类型。谢谢。这就解决了问题:我忘记将作为xs:string
作为原始函数的返回类型。谢谢
declare option exist:serialize "method=text";