使用 XQuery 引用 BaseX DB 中的特定文档

发布于 2024-09-12 04:17:19 字数 346 浏览 13 评论 0原文

如果我向 BaseX DB 添加两个文档,例如 normal.xmlnormal2.xml,是否有一种方法可以单独引用每个文档?

我知道 doc() 函数,但它会在文件系统中查找它们的位置,而不是在数据库本身中。

例如,如果我使用以下查询:doc("normal.xml")/name,那么我将收到有关未找到normal.xml的错误。

我也尝试过: basex:db("my-db-name")/doc("normal.xml")/name 并收到相同的错误。

有什么想法吗?

If I add two documents to a BaseX DB, let's say normal.xml and normal2.xml, is there a way to refer to each one individually?

I know about the doc() function, but it looks at the filesystem for their location, rather than in the database itself.

For instance, if I query with this: doc("normal.xml")/name, then I will get an error about normal.xml not being found.

I also tried: basex:db("my-db-name")/doc("normal.xml")/name and received the same error.

Any ideas?

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

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

发布评论

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

评论(3

离旧人 2024-09-19 04:17:19

我最终在 BaseX 邮件列表上询问我收到的答案如下:

for $doc in collection('test-db')
    where matches(document-uri($doc), 'example.xml')
return $doc

我还询问了为什么没有直接的方法来引用人们想要在恒定时间内提取数据的文档,得到的答复是:

这是由于 XQuery 数据模型。 XQuery 对于数据库/集合中的文件没有正式的概念(如果我错了,Christian 可能会纠正我),
因此,collection() 命令返回给定数据库的任何(文档)节点序列。
由用户选择他想要处理的节点。

我们目前正在寻找更直观地导航集合的想法;类似的东西
“collection('db/path-to/document.xml')”仍应符合当前的 W3C 建议。
由于后续的 document-uri() 通常工作得足够好,因此它在我们的优先级列表中并不是太高。

不过还是谢谢你的帮助。

I ended up asking on the BaseX mailing list and the answer I received is as follows:

for $doc in collection('test-db')
    where matches(document-uri($doc), 'example.xml')
return $doc

I also inquired as to why there was no direct way to reference the document one would want to extract data from in constant time, and the response was:

This is due to the XQuery data model. XQuery has no formal notion of files inside a database/collection (Christian might correct me if I am wrong),
so the collection() command returns any sequence of (document-)nodes for the given database.
It is up to the user to pick those nodes he wants to process.

We are currently looking for ideas on navigating collections more intuitively; something similar to
"collection('db/path-to/document.xml')" that should still conform to the current W3C recommendation.
As the subsequent document-uri() usually works well enough this is not too high on our priority list.

Thanks for the help though.

淑女气质 2024-09-19 04:17:19

以下查询可能对您有帮助:

for $doc in collection('your-db-name')
let $path := base-uri($doc)
where ends-with($path, 'normal.xml')
return $doc/name

The following query might help you:

for $doc in collection('your-db-name')
let $path := base-uri($doc)
where ends-with($path, 'normal.xml')
return $doc/name
鹿港小镇 2024-09-19 04:17:19

假设您知道,doc() 函数就是您所需要的。假设您已经创建并打开了名为“mydb”的数据库,如果您使用以下命令添加文档:

ADD TO your_name /some/path/on/filesystem.xml

您始终可以使用以下命令打开以下文档:

XQUERY doc('mydb/your_name')

ADD TO 将忽略您为其指定的文件名并使用您在URI。但请注意:运行该命令时,无法保证“your_name”的唯一性。如果它不是唯一的,(doc) 函数将抛出一个 BaseX 错误(不是 XQuery 标准的一部分),表明它匹配多个文档。

The doc() function is all you need assuming you know. Assuming you have created and opened a database named 'mydb,' if you add a document with the following command:

ADD TO your_name /some/path/on/filesystem.xml

You can always open the following document using:

XQUERY doc('mydb/your_name')

ADD TO will ignore the file name you gave it and use the name you specified in the URI. Be warned though: there is no guarantee of uniqueness of 'your_name' when you run that command. And if it's not unique, the (doc) function will throw a BaseX error (not part of XQuery standard) saying it matches more than one document.

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