reconstructing an XML tree from RDB data

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • lwwhite
    New Member
    • Dec 2006
    • 16

    reconstructing an XML tree from RDB data

    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.
  • MMcCarthy
    Recognized Expert MVP
    • Aug 2006
    • 14387

    #2
    Originally posted by lwwhite
    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.

    Originally posted by lwwhite
    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 programmaticall y representing this. I'm going to ask some of the experts from the other forums to have a look at this.

    Comment

    • pbmods
      Recognized Expert Expert
      • Apr 2007
      • 5821

      #3
      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`.

      Comment

      • MMcCarthy
        Recognized Expert MVP
        • Aug 2006
        • 14387

        #4
        Originally posted by pbmods
        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.

        Comment

        • MMcCarthy
          Recognized Expert MVP
          • Aug 2006
          • 14387

          #5
          Originally posted by mmccarthy
          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.
          [CODE=sql]
          SELECT P1.PersonID, P2.PersonID As FatherOf, P3.PersonID As MotherOf
          FROM ((tblPerson P1 INNER JOIN tblPerson P2
          ON P1.PersonID = P2.FatherID)
          INNER JOIN tblPerson P3
          ON P1.PersonID = P3.MotherID)
          [/CODE]
          And this is just a basic one level relationship. After this it would get pretty complicated.

          Comment

          • JosAH
            Recognized Expert MVP
            • Mar 2007
            • 11453

            #6
            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

            Comment

            • danp129
              Recognized Expert Contributor
              • Jul 2006
              • 323

              #7
              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?

              Comment

              • Purple
                Recognized Expert Contributor
                • May 2007
                • 404

                #8
                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

                Comment

                • Motoma
                  Recognized Expert Specialist
                  • Jan 2007
                  • 3236

                  #9
                  Originally posted by lwwhite
                  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:

                  [code=xml]
                  <xml>
                  <family>
                  <member f_id=1 name="Mom" age=43 />
                  <member f_id=2 name="Dad" age=59 />
                  <member f_id=3 name="Child" age=24 />
                  </family>
                  <rships>
                  <rship f_id=1 f_id2=2 rtype=1 />
                  <rship f_id=1 f_id2=3 rtype=2 />
                  <rship f_id=2 f_id2=3 rtype=2 />
                  </rships>
                  </xml>
                  [/code]

                  Did I miss something?

                  Comment

                  • Dököll
                    Recognized Expert Top Contributor
                    • Nov 2006
                    • 2379

                    #10
                    Originally posted by lwwhite
                    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:



                    Any questions, stay tuned, we're here to help...

                    Comment

                    • MMcCarthy
                      Recognized Expert MVP
                      • Aug 2006
                      • 14387

                      #11
                      Originally posted by Dököll
                      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:



                      Any questions, stay tuned, we're here to help...
                      Should that not be in the Articles sections ?

                      Comment

                      • Dököll
                        Recognized Expert Top Contributor
                        • Nov 2006
                        • 2379

                        #12
                        Originally posted by mmccarthy
                        Should that not be in the Articles sections ?
                        I am trying to be careful:-)

                        Comment

                        • MMcCarthy
                          Recognized Expert MVP
                          • Aug 2006
                          • 14387

                          #13
                          Originally posted by Dököll
                          I am trying to be careful:-)
                          I think that one is a pure article.

                          Comment

                          • Dököll
                            Recognized Expert Top Contributor
                            • Nov 2006
                            • 2379

                            #14
                            Originally posted by mmccarthy
                            I think that one is a pure article.
                            Looks like our Articles portion are off limits for postings, has anything changed?

                            Comment

                            • Dököll
                              Recognized Expert Top Contributor
                              • Nov 2006
                              • 2379

                              #15
                              Originally posted by Dököll
                              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:-)
                              Last edited by Dököll; Jul 4 '07, 02:08 PM. Reason: Added remark...

                              Comment

                              Working...