XML 本机数据库与关系数据库 — PHP 与 XQuery

发布于 2024-10-16 14:44:37 字数 601 浏览 4 评论 0原文

我正在尝试开发一个网站,其中存储并为客户检索许多食谱。我有一些关于 XML 和基于 XML 的原生数据库的课程,这些课程介绍了原生 XML 数据库的概念。此外,如果我没记错的话,我们了解到 XQuery 是最适合处理 XML 的编程语言。由于菜谱的半结构性和不那么表格化的性质,我猜想(如果我错了,请纠正我)它可以最好地用 XML 文件来表达,如下所示:

<recipe>
  <ingredients>
    <name='floor' amount='500g'/>
    <name='y' amount='200g'/>
  </ingredients>
  <steps>
    <step id='1'> first prepare .....
  <steps>
</recipe>

我知道关系数据库有其优点,并且优于其他选项,但是在这种特殊情况下,它会导致表上有如此多的联接操作。另一方面,就其处理大量数据的性能和能力而言,本机 XML 数据库对我来说似乎不太有前途。此外,考虑到互联网上大量的教程和帮助,PHP 编程比 XQuery 简单得多。 我真的不知道该怎么办,所以我才来找你们。

I'm trying to develop a website in which many recipes are stored, and retrieved for the clients. I had some courses about XML and native XML-based databases, and those courses introduced the concept of native XML databases. Besides, if I remember correctly, we learned that XQuery is the most suitable programming language for working with XML. Because of the semi-structure and not so tabular nature of a recipe, I guess(please correct me if I'm wrong) that it can be best expressed in an XML file, like below :

<recipe>
  <ingredients>
    <name='floor' amount='500g'/>
    <name='y' amount='200g'/>
  </ingredients>
  <steps>
    <step id='1'> first prepare .....
  <steps>
</recipe>

I know that relational databases have their advantages and glories over other options, however it would result in so many join operations on tables in this particular case. On the other hand, native XML databases don't seem very promising to me, regarding their performance and abilities to handle a large amount of data. Besides, programming in PHP is much more simpler than XQuery, considering the huge volume of tutorials and helps on internet.
I really don't know what to do, and that's why I came to you guys.

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

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

发布评论

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

评论(3

扶醉桌前 2024-10-23 14:44:37

一些简单的确定理论,无需考虑任何强烈的要求或其他东西。
首先你的数据源在哪里。

  1. 如果您的数据是通过用户输入屏幕生成的。
  2. 如果您的数据经过单个应用程序(例如网络)的有效验证和处理。
  3. 如果您的数据属性和功能几乎被冻结并且没有新的维度。
  4. 如果您的数据具有交易性质。

那么你可以想到关系-db。

  1. 如果您的数据来自不同的数据源,例如平面文件、xml、互联网屏幕抓取等,
  2. 相对较少的交易
  3. 数据属性是流动的,并且可以有不同的切片/维度。
  4. 准备好使用 XQuery 等函数式语言或 XSLT 等 Xmllized 语言,

那么 Xml 数据库是关键。

some simple determination theory without looking any strong requirements or something.
first where is your data-source gonna be.

  1. if your data is being generated through a user input screens.
  2. if your data is well validated and processed by a single application( e.g) web ).
  3. if your data properties and features are pretty much freezed and no new dimension to it.
  4. if your data is of transaction nature.

then you can think of relation - db.

  1. if your data is coming from different datasources like flat file, xml, internet screen scraping , etc etc.
  2. comparatively less amount transaction
  3. data properties are fluid and can have various slice / dimension to it.
  4. ready to work with functional languages like XQuery or Xmllized language like XSLT

then Xml Database is the key.

往事风中埋 2024-10-23 14:44:37

使用关系数据库 - 因为如果您获得更多记录,它会更快,并且创建起来更简单。
(对于您的示例,它是 3 张表 - 一张包含食谱,另一张包含成分,最后一张包含步骤。另一种方法是创建包含所有已知成分的表格并使用关联 - 例如包含食谱 ID、成分 ID 和数量的表格)

Use relations DB - because it is much more faster if you get bigger amout of records , and it is simplier to create.
( for your example it is 3 tables - one with recipes, another with ingredients and the last one with steps. Alternative is to create table with all known ingredients and use association - eg. table with ID of recipe, ID of ingredient and amount )

各自安好 2024-10-23 14:44:37

您似乎认为必须在此处选择一个或另一个。事实并非如此,XQuery 并不是真正被设置为一个完整的 Web 脚本环境,它只是 SQL 而不是 PHP 的替代品。因此,您当然可以使用 PHP 来完成网站中以 Web 为中心的部分,例如用户登录(也可以在关系数据库中),然后仅将 XQUery 用于您的配方查询层。

一些 XML 数据库(例如 MarkLogic)也可以完成等式的所有 Web 逻辑方面的工作,但它们还没有提供相同丰富的库,因此我肯定会推荐 PHP 或类似的 Web 层数据库。

It seems that you're thinking that you have to choose one or the other here. That isn't the case, XQuery isn't really setup to be a complete web scripting environment, it's a replacement to SQL not PHP. Therefore you can certainly use PHP to do the web focused parts of the site such as user logins (which could also be in a relational DB) then use XQUery just for your recipe querying layer.

Some XML databases such as MarkLogic can also do all the web logic side of the equation but they don't offer the same richness of libraries yet, so I would certainly recommend PHP or something like that for the web tier.

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