473,387 Members | 1,597 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

reconstructing an XML tree from RDB data

lwwhite
16
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.
Jun 25 '07 #1
15 2654
MMcCarthy
14,534 Expert Mod 8TB
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.
Jun 29 '07 #2
pbmods
5,821 Expert 4TB
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`.
Jun 29 '07 #3
MMcCarthy
14,534 Expert Mod 8TB
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.
Jun 29 '07 #4
MMcCarthy
14,534 Expert Mod 8TB
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.
Looking at this the problem with it from a query point of view is you would have to create a new instance of the table in the query for each parent child relationship.
Expand|Select|Wrap|Line Numbers
  1. SELECT P1.PersonID, P2.PersonID As FatherOf, P3.PersonID As MotherOf
  2. FROM ((tblPerson P1 INNER JOIN tblPerson P2
  3. ON P1.PersonID = P2.FatherID)
  4. INNER JOIN tblPerson P3
  5. ON P1.PersonID = P3.MotherID)
  6.  
And this is just a basic one level relationship. After this it would get pretty complicated.
Jun 29 '07 #5
JosAH
11,448 Expert 8TB
Relational databases and trees don't like each other. You need at least an
extension to SQL to handle this matter. Have a look how Oracle did it.

kind regards,

Jos
Jun 29 '07 #6
danp129
323 Expert 256MB
I don't like XML much and don't use it alot so I'm having a hard time picturing how the mother/father (or father/father adoption heh) would look like. Do you have an example XML file for a family tree starting from grandparents on down that your goal is to rebuild from the RDB?
Jun 29 '07 #7
Purple
404 Expert 256MB
Hi all,

Just to add a MSSQL perspective;

take a look at this which details microsoft's best practice on XML in SQL Server 2005..

Regards Purple
Jun 29 '07 #8
Motoma
3,237 Expert 2GB
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.
Perhaps I have entirely missed the point of your question, but if I were to try and structure an XML document from the dataset you have givien, it would be identical to the way it was represented in the database:

Expand|Select|Wrap|Line Numbers
  1. <xml>
  2.   <family>
  3.     <member f_id=1 name="Mom" age=43 />
  4.     <member f_id=2 name="Dad" age=59 />
  5.     <member f_id=3 name="Child" age=24 />
  6.   </family>
  7.   <rships>
  8.     <rship f_id=1 f_id2=2 rtype=1 />
  9.     <rship f_id=1 f_id2=3 rtype=2 />
  10.     <rship f_id=2 f_id2=3 rtype=2 />
  11.   </rships>
  12. </xml>
  13.  
Did I miss something?
Jun 29 '07 #9
Dököll
2,364 Expert 2GB
I would just like a general explanation of the XML reconstruction process, please.

Thanks in advance.
Hello, lwwhite!

You might find this interesting, new post. I am not sure exactly how you are attempting to ditinguish XML and Access databases. If you can do a little reading, please get an idea here:

http://www.thescripts.com/forum/thread672308.html

Any questions, stay tuned, we're here to help...
Jul 4 '07 #10
MMcCarthy
14,534 Expert Mod 8TB
Hello, lwwhite!

You might find this interesting, new post. I am not sure exactly how you are attempting to ditinguish XML and Access databases. If you can do a little reading, please get an idea here:

http://www.thescripts.com/forum/thread672308.html

Any questions, stay tuned, we're here to help...
Should that not be in the Articles sections ?
Jul 4 '07 #11
Dököll
2,364 Expert 2GB
Should that not be in the Articles sections ?
I am trying to be careful:-)
Jul 4 '07 #12
MMcCarthy
14,534 Expert Mod 8TB
I am trying to be careful:-)
I think that one is a pure article.
Jul 4 '07 #13
Dököll
2,364 Expert 2GB
I think that one is a pure article.
Looks like our Articles portion are off limits for postings, has anything changed?
Jul 4 '07 #14
Dököll
2,364 Expert 2GB
Looks like our Articles portion are off limits for postings, has anything changed?
Please disregard, I figured it out. No questions but ideas/projects yes!

Has been moved, thanks:-)
Jul 4 '07 #15
Dököll
2,364 Expert 2GB
Another option: http://www.thescripts.com/forum/show...80#post2631280
Jul 4 '07 #16

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Henry Jordon | last post by:
I have everything pretty much done but I need to fix something in my coding. I want to be able to enter strings such as "love", "hate", "the", etc. but am unable to figure how to do this. I have...
4
by: Jerry Krinock | last post by:
I've written the following demo to help me understand a problem I'm having in a larger program. The "main" function constructs a Foo object, and then later "reconstructs" it by calling the...
4
by: Tarique Jawed | last post by:
Alright I needed some help regarding a removal of a binary search tree. Yes its for a class, and yes I have tried working on it on my own, so no patronizing please. I have most of the code working,...
25
by: prabhat143 | last post by:
Hi, Given a singly linked, null terminated list, how can it be converted to tree? Each node in the list has three attributes: it's ID, it's parent ID and of course, the next node it's pointing...
6
by: sathyashrayan | last post by:
#include<stdio.h> #include<stdlib.h> #include<string.h> struct tree { int data; struct tree *left,*right; }; void init(struct tree *node)
4
by: Ken | last post by:
I have a binary tree in VB NET and insertions seem to be slow. The program receives data from one source and inserts it into the tree. The program receives data from another source and...
2
by: andrew browning | last post by:
gbd says the segmentation fault is being generated in the insert function. //CONSTRUCTOR tree():data(value_type()), left(0), right(0){}; tree(value_type vt, tree* l = 0, tree* r = 0):...
1
by: hn.ft.pris | last post by:
I have the following code: Tree.h defines a simple binary search tree node structure ########## FILE Tree.h ################ #ifndef TREE_H #define TREE_H //using namespace std; template...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.