Query generate 'XDMP-CHILDNODEKIND: $final — element nodes cannot have binary node children' error

Deadly 提交于 2021-02-10 13:55:15

问题


Below is my simple query, that reads all files from a directory and holds all files in $final Variable save in one single file.

But when run this query, after taking some time, it prompt [1.0-ml] XDMP-CHILDNODEKIND: $final -- element nodes cannot have binary node children error.

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>})

Actually, I have 10000 small files in the local system and I want to Merge in single file.


回答1:


The directory likely contains binary documents (i.e. PDF, images, etc). When you read those documents with xdmp:document-get(), you will get a binary() node.

As the error message indicates, binary() nodes cannot be children of an XML element.

Your $final variable will be a sequence of documents, and at least one of them is a binary() node.

You could exclude those binary() nodes. For instance, by adding a predicate filter to the results of the 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())]

or you could base64 encode the binary data, so that it can be added to the 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


来源:https://stackoverflow.com/questions/56170819/query-generate-xdmp-childnodekind-final-element-nodes-cannot-have-binary-n

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!