下面是我的简单查询,它从目录中读取所有文件并将 $final 变量中的所有文件保存在一个文件中。
但是当运行这个查询时,花了一些时间后,它提示 [1.0-ml] XDMP-CHILDNODEKIND: $final -- 元素节点不能有二进制节点 child 错误。
let $input-dir :=xdmp:filesystem-directory("d:\work\may\06-05-2019\all-
feeds-input-output\clc\log\clc-true-ouput\")/dir:entry
let $final :=
for $each at $i in $input-dir
return
xdmp:document-get($each/dir:pathname/text(),
<options xmlns="xdmp:document-get">
<repair>full</repair>
<encoding>UTF-8</encoding>
</options>)
return
xdmp:save("D:\WORK\MAY\06-05-2019\ALL-FEEDS-INPUT-OUTPUT\CLC\LOG\COMBINE-XMLs\Combine-CLC-TRUE-INPUT.xml",
document{<records>{$final}</records>})
实际上,我本地系统中有10000个小文件,我想合并为单个文件。
最佳答案
该目录可能包含二进制文档(即 PDF、图像等)。当您使用xdmp:document-get()
读取这些文档时,您将获得一个binary()
节点。
如错误消息所示,binary()
节点不能是 XML 元素的子节点。
您的 $final
变量将是一系列文档,其中至少有一个是 binary()
节点。
您可以排除那些 binary()
节点。例如,通过向 xdmp:document-get()
的结果添加谓词过滤器:
let $final :=
for $each at $i in $input-dir
return
xdmp:document-get($each/dir:pathname/text(),
<options xmlns="xdmp:document-get">
<repair>full</repair>
<encoding>UTF-8</encoding>
</options>
)[not(. instance of binary())]
或者你可以base64 encode二进制数据,以便可以将其添加到 XML:
let $final :=
for $each at $i in $input-dir
let $doc :=
xdmp:document-get($each/dir:pathname/text(),
<options xmlns="xdmp:document-get">
<repair>full</repair>
<encoding>UTF-8</encoding>
</options>)
return
if ($doc instance of binary())
then xdmp:base64-encode($doc)
else $doc
关于xquery - 查询生成 'XDMP-CHILDNODEKIND: $final -- element nodes cannot have binary node children'错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56170819/