从RDB数据重建XML树 [英] reconstructing an XML tree from RDB data

查看:81
本文介绍了从RDB数据重建XML树的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不确定这个讨论是否更适合Access或XML论坛,我不想双重发帖,所以我开始使用Access,因为你很有帮助对我来说


我正在准备一个演示文稿,比较使用关系数据库与内容管理系统中的原生XML数据库来管理基于XML的文档。我试图提出的一点是,一旦数据突然进入RDB结构,重构XML层次结构/树是多么困难。我使用一个简单的家谱作为我的例子,我已经建立了一个样本数据库(在Access中),其中一个表记录了每个家庭成员的姓名和其他统计数据(年龄等),另一个表连接了家庭成员和关系:


家庭

------

f_id

name

年龄


rships

------

r_id

f_id

f_id2

rship


(你选择两个家庭成员以及他们之间的关系。这是最有效的我可以想到代表这个递归数据的方式。)


现在,如果我尝试在XML类型树视图中重新创建族树,我该如何去做?我不想要任何特定的代码,只是典型的RDB可能采用的一般方法来重建树,如果有可能以任何有意义的方式解释它而不需要技术和具体。我知道它将依赖于模式,复杂,并且如果家族树结构发生变化等需要维护。这正是我想要做的一点。


我应该指出,我仍然感觉到对通常对Access和RDB的热爱......只是试图证明它不一定是XML的最佳工具。我没有想要利用这篇文章开始讨论NXD与RDB的争论。我想要对XML重建过程进行一般性解释。


提前谢谢。

解决方案


我不确定这个讨论是否更适合Access或XML论坛,我不想双重发帖,所以我开始使用Access因为你在这里对我很有帮助。


我正在准备一个演示文稿,比较使用关系数据库与内容管理系统中的原生XML数据库来管理基于XML的文档。我试图提出的一点是,一旦数据突然进入RDB结构,重构XML层次结构/树是多么困难。我使用一个简单的家谱作为我的例子,我已经建立了一个样本数据库(在Access中),其中一个表记录了每个家庭成员的姓名和其他统计数据(年龄等),另一个表连接了家庭成员和关系:


家庭

------

f_id

name

年龄


rships

------

r_id

f_id

f_id2

rship



好​​的,我认为你不需要这里的r_id。两个f_id'是主键(复合主键),如下所示:

rships

f_id1(Compostite主键 - 外键引用家庭的主键)

f_id2(Compostite主键 - 外键引用家庭的主键)

rship


这实际上是一个连接表,但它不是加入两个不同表之间的多对多关系,而是加入了与自身的多对多关系。


现在如果我试图在XML类型的树视图中重新创建族树,我该怎么做呢?我不想要任何特定的代码,只是典型的RDB可能采用的一般方法来重建树,如果有可能以任何有意义的方式解释它而不需要技术和具体。我知道它将依赖于模式,复杂,并且如果家族树结构发生变化等需要维护。这正是我想要做的一点。


我应该指出,我仍然感觉到对通常对Access和RDB的热爱......只是试图证明它不一定是XML的最佳工具。我没有想要利用这篇文章开始讨论NXD与RDB的争论。我想对XML重建过程进行一般性解释。


提前谢谢。



从数据库的角度构建树视图是你永远不会做的事情。但是,这样的树视图很难实现。树是您从父母开始的地方,每个父母可以有一个或多个孩子,每个孩子都可以拥有一个或多个孩子。当你有伴侣,丈夫,妻子等时,你的问题就出现了。这使事情变得非常复杂。


但是,我确定有一种以编程方式表示这一点的方法。我将要求其他论坛的一些专家来看看这个。


我认为从概念上讲,一个问题就是没有规则定义关系。例如,如果`f_id` 1是`f_id` 2的子,那么`f_id` 2也是`f_id` 1'的父亲。如果`f_id` 3是`f_id` 2'的妻子,那么`f_id` 1也是`f_id` 3的儿子,即使`f_id` 1和`f_id` 2代表一个''单位''如果你要创建一个家谱的可视化表示。


我认为构建数据库的一种更易于管理的方法是添加一个`father_id`和一个`mother_id`字段'family`表,因为我们知道每个人都有其中一个(除了`f_id` 0和`f_id` 1;我们称之为......嗯,Sadam和Steve)。


我可以看到,如果你想创建一个更像btree的设置,创建一个`siblings`视图,你将匹配`f_id`s与相同的`father_id`和`mother_id`。 / blockquote>


从概念上讲,我认为一个问题是没有定义关系的规则。例如,如果`f_id` 1是`f_id` 2的子,那么`f_id` 2也是`f_id` 1'的父亲。如果`f_id` 3是`f_id` 2'的妻子,那么`f_id` 1也是`f_id` 3的儿子,即使`f_id` 1和`f_id` 2代表一个''单位''如果你要创建一个家谱的可视化表示。


我认为构建数据库的一种更易于管理的方法是添加一个`father_id`和一个`mother_id`字段'family`表,因为我们知道每个人都有其中一个(除了`f_id` 0和`f_id` 1;我们称之为......嗯,Sadam和Steve)。


我可以看到,如果你想创建一个更像btree的设置,创建一个`siblings`视图,你将匹配`f_id`s与相同的`father_id`和`mother_id`。



你也有这样的问题:兄弟姐妹可以拥有同一个父亲但母亲不同。


基本上是数据库方式这将是一个表

tblPerson

PersonID(主键)

FatherID(引用此表的主键的外键)

MotherID(外键引用此表的主键)


使用此功能,您将永远不会实际记录兄弟关系。相反,兄弟姐妹会使用对数据的查询来解决。


I''m not sure if this discussion is a better fit for the Access or XML forum and I don''t want to double-post, so I''m starting in Access because you''ve been so helpful to me here.

I am preparing a presentation comparing using a relational database vs. a native XML database within a content management system to manage XML-based documentation. The point I am trying to make is how difficult it can be to reconstruct the XML hierarchy/tree once the data has been burst into an RDB structure. I am using a simple family tree as my example and I have built a sample database (in Access) with one table that records each family member''s name and other statistics (age, etc.) and a second table that joins family members and relationships:

family
------
f_id
name
age

rships
------
r_id
f_id
f_id2
rship

(Where you choose two family members and the relationship between them. This is the most efficient way I could think of to represent this recursive data.)

Now, if I were to try to recreate the family tree in a XML-type tree view, how would I go about that? I don''t want any specific code, just a general approach that a typical RDB might take to reconstruct the tree, if it is possible to explain that in any meaningful way without getting technical and specific. I know that it would be schema-dependent, complicated, and require maintenance should the family tree structure change, etc. That''s exactly the point I''m trying to make.

And I should point out that I''m still feelin'' the love for Access and RDBs in general...just trying to make the case that it''s not necessarily the best tool for XML. I don''t want to use this post to kick off a debate about NXD vs RDB. I would just like a general explanation of the XML reconstruction process, please.

Thanks in advance.

解决方案

I''m not sure if this discussion is a better fit for the Access or XML forum and I don''t want to double-post, so I''m starting in Access because you''ve been so helpful to me here.

I am preparing a presentation comparing using a relational database vs. a native XML database within a content management system to manage XML-based documentation. The point I am trying to make is how difficult it can be to reconstruct the XML hierarchy/tree once the data has been burst into an RDB structure. I am using a simple family tree as my example and I have built a sample database (in Access) with one table that records each family member''s name and other statistics (age, etc.) and a second table that joins family members and relationships:

family
------
f_id
name
age

rships
------
r_id
f_id
f_id2
rship

Ok, I don''t think you need the r_id here. The two f_id''s are the primary key (composite Primary key) as follows:

rships
f_id1 (Compostite Primary key - foreign key referencing primary key of family)
f_id2 (Compostite Primary key - foreign key referencing primary key of family)
rship

This is actually a join table but instead of joining a many to many relationship between two different tables it is joining a many to many relationship with itself.

Now, if I were to try to recreate the family tree in a XML-type tree view, how would I go about that? I don''t want any specific code, just a general approach that a typical RDB might take to reconstruct the tree, if it is possible to explain that in any meaningful way without getting technical and specific. I know that it would be schema-dependent, complicated, and require maintenance should the family tree structure change, etc. That''s exactly the point I''m trying to make.

And I should point out that I''m still feelin'' the love for Access and RDBs in general...just trying to make the case that it''s not necessarily the best tool for XML. I don''t want to use this post to kick off a debate about NXD vs RDB. I would just like a general explanation of the XML reconstruction process, please.

Thanks in advance.

Building a Tree View from a database point of view is something you would never do. However, a tree view for something like this would be difficult to implement. A tree is where you start with a parent and each parent can have one or more children and each of those children can themselves have one or more children. Your problem arises when you have partners, husbands, wives, etc. This make things extremely complicated.

However, I''m sure there is a way of programmatically representing this. I''m going to ask some of the experts from the other forums to have a look at this.


I think one problem, conceptually, with the situation is that there are no rules defining relationships. For example, if `f_id` 1 is the son of `f_id` 2, then `f_id` 2 is also `f_id` 1''s father. And if `f_id` 3 is `f_id` 2''s wife, then `f_id` 1 is also the son of `f_id` 3, even though `f_id` 1 and `f_id` 2 would represent one ''unit'' if you were to create a visual representation of the family tree.

I think a more manageable way to structure the database would be to add a `father_id` and a `mother_id` field to the `family` table, since we know each person has exactly one of those (except for `f_id` 0 and `f_id` 1; we''ll call them... um, Sadam and Steve).

I could see, if you wanted to create a more btree-like setup, creating a `siblings` view where you would match up `f_id`s with the same `father_id` and `mother_id`.


I think one problem, conceptually, with the situation is that there are no rules defining relationships. For example, if `f_id` 1 is the son of `f_id` 2, then `f_id` 2 is also `f_id` 1''s father. And if `f_id` 3 is `f_id` 2''s wife, then `f_id` 1 is also the son of `f_id` 3, even though `f_id` 1 and `f_id` 2 would represent one ''unit'' if you were to create a visual representation of the family tree.

I think a more manageable way to structure the database would be to add a `father_id` and a `mother_id` field to the `family` table, since we know each person has exactly one of those (except for `f_id` 0 and `f_id` 1; we''ll call them... um, Sadam and Steve).

I could see, if you wanted to create a more btree-like setup, creating a `siblings` view where you would match up `f_id`s with the same `father_id` and `mother_id`.

You also have the issue where siblings can have the same father but different mother.

Essentially database wise this would be one table

tblPerson
PersonID (Primary key)
FatherID (Foreign key referencing the Primary key of this table)
MotherID (Foreign key referencing the Primary key of this table)

Using this you would never actually record a sibling relationship. Instead siblings would be worked out using queries on the data.


这篇关于从RDB数据重建XML树的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆