0

是否有用于加载文本文件的 XQuery 命令?

我可以通过执行以下操作来加载 xml 文档;

declare variable $text := doc("test.xml");

但它似乎只有在 test.xml 是格式良好的 xml 文档时才有效。我想要的是将一个普通的 test.txt 文件加载到一个字符串变量中。像这样的东西;

declare variable $str as xs:string := fn:loadfile("test.txt");

可以做到吗?

我正在使用撒克逊引擎,但在撒克逊文档中找不到答案。

4

5 回答 5

2

XQuery 3.0 has the function fn:unparsed-text (which was originally defined in XSLT), which does exactly what you want. XQuery 3.0 is still a work in progress though, but whilst there are not many XQuery 3.0 processors available, many XQuery processors already support this function (including Saxon).

于 2010-12-07T10:54:48.767 回答
2

实际上,您可以在 Zorba 中找到文件函数的一种实现:http ://www.zorba-xquery.com/doc/zorba-1.4.0/zorba/xqdoc/xhtml/www.zorba-xquery.com_modules_file.html

于 2010-12-03T10:45:58.973 回答
1

在 EXPath 上有一个标准化的工作。XQuery File 模块的规范已经存在,它能够执行您所描述的操作:EXPath File Module Spec

然而,我不知道有多少实现。不幸的是,撒克逊人似乎没有实现它(或者,请指出它)。zorba 附带了一个示例实现(请参阅Zorba 的 XQDoc 站点)。如果您想知道如何开始使用 zorba,可以查看本教程:XQuery 和 Zorba 入门

于 2010-12-03T09:26:29.587 回答
0

XQuery by default( means fn: namespace ) doesn;t have any file-access methods.

MarkLogic : xdmp:filesystem-file() xdmp:filesystem-directory()

Zorba: already mentioned by user457056

Exist Exist File Module

于 2010-12-07T20:11:43.753 回答
0

Saxon 自 9.2 版以来具有 fn:collection 的扩展,可用于读取未解析的文本。这是一个例子:

    collection('file:///c:/TEMP?select=text.txt;unparsed=yes')

这在9.2 的“此版本中的更改”中进行了描述。显然函数库文档中没有提到它。但是它运作良好,我一直在使用它。

于 2010-12-10T23:03:35.223 回答