我可以使用file:serialize函数将现有的db XML文件保存到文件系统中的路径吗



我想在文件系统中保存一个XML,我发现file:serialize函数可以做到这一点。然而,我从文件中并不清楚(http://exist-db.org/exist/apps/fundocs/view.html?uri=http://exist-db.org/xquery/file#serialize.3)如何使用此函数。

有人能给我举个例子吗?

此脚本将存储在eXist数据库集合/db/apps/myapp/data中的名为mydocument.xml的文档保存到文件系统中的C:UsersJoeworkspace中(提供了一个典型的Mac目录作为注释供您启用;请注意Windows和Mac/Linux之间的斜杠差异)。我建议使用目标目录的绝对路径,正如示例所使用的那样。您可以修改序列化参数,如中所述http://exist-db.org/exist/apps/doc/xquery.xml#serialization(file:serialize()函数将采用"XQuery1.0中的序列化"下列出的参数。)

xquery version "3.0";
let $source-doc := doc('/db/apps/myapp/data/mydocument.xml')
let $filename := 'mydocument.xml'
let $target-directory := 
(: Mac :)
(: '/Users/Joe/workspace/' :)
(: Windows :)
'C:UsersJoeworkspace'
let $target-path:= 
(: Construct the full filesystem path for the file :)
concat($target-directory, $filename)
return 
file:serialize($source-doc, $target-path, ("omit-xml-declaration=yes", "indent=yes"))

最新更新