如何从 XQuery 中加载文本文件?

发布于 2024-10-05 17:19:19 字数 353 浏览 0 评论 0原文

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

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

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

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

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

能做到吗?

我正在使用 Saxon 引擎,但在 saxon 文档中找不到答案。

Is there an XQuery command to load a text file?

I can load an xml document by doing the following;

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

But it only seems to work if test.xml is a well-formed xml document. What I want is to load a plain test.txt file into a string variable. Something like this;

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

Can it be done?

I'm using the Saxon engine but I can't find an answer in the saxon documentation.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

眼眸印温柔 2024-10-12 17:19:19

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

Indeed you can find one implementation of the file functions in Zorba: http://www.zorba-xquery.com/doc/zorba-1.4.0/zorba/xqdoc/xhtml/www.zorba-xquery.com_modules_file.html

怎言笑 2024-10-12 17:19:19

XQuery 3.0 具有函数 fn:unparsed-text (最初是在 XSLT 中定义的),它完全可以满足您的需求。尽管 XQuery 3.0 仍在进行中,但虽然可用的 XQuery 3.0 处理器并不多,但许多 XQuery 处理器已经支持此功能(包括 Saxon)。

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

暮年 2024-10-12 17:19:19

EXPath 上为此进行了标准化工作。 XQuery 文件模块的规范已经存在,该模块能够执行您所描述的操作:EXPath 文件模块规范

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

There is a standardization effort for this on EXPath. A spec already exists for an XQuery File module that is capable of doing what you describe: EXPath File Module Spec.

Yet, I don't know how many implementations are out there. Saxon doesn't seem to implement it unfortunately (Or, please point me to it). An example implementation is shipped with zorba (see XQDoc Site of Zorba). If you want to know how to get started with zorba, you can check out this tutorial: Get Started with XQuery and Zorba.

淡墨 2024-10-12 17:19:19

默认情况下,XQuery(表示 fn: 命名空间)没有任何文件访问方法。

马克逻辑:
xdmp:文件系统文件()
xdmp:文件系统目录()

Zorba:
用户457056已经提到

存在
现有文件模块

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

别想她 2024-10-12 17:19:19

Saxon 从 9.2 版本开始有一个 fn:collection 扩展,可以用来读取未解析的文本。以下是一个示例:

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

此版本中的更改”下对此进行了描述9.2。显然函数库文档中没有提到它。不过它效果很好,而且我已经经常使用它了。

Saxon since version 9.2 has an extension of fn:collection that can be used to read unparsed text. Here is an example:

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

This is described under "Changes in this Release" for 9.2. Apparently it is not mentioned in the function library documentation. However it works well and I have been using it a lot.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文