?
Solved

best method to implement a family tree ?

Posted on 2009-04-27
10
Medium Priority
?
375 Views
Last Modified: 2013-12-12
I need to make a family tree. But i don't know how to make make it.
I asked someone and done some searching in Google.
I found three ways as follows
1. Using Database (foreign key to represent relation ship)
2. Using XML to store the data.
3. Using binary tree.

But the problem is I am not familiar with any of the above.
Please suggest me the easiest way to this. Also I need to make the list dynamic.
Also any new method which is simpler than the above.

If you can suggest some sample code please make it in php.

Thanks in advance,
0
Comment
Question by:danishbacker
  • 4
  • 3
  • 3
10 Comments
 
LVL 39

Assisted Solution

by:abel
abel earned 600 total points
ID: 24240733
Let's skip the binary tree, you won't be needing that. The database is an option, though it is a bit tricky to get right. The easiest way, in my opinion, would be to use XML. The XML language is designed for (among other things) hierarchical relations.
0
 
LVL 39

Assisted Solution

by:abel
abel earned 600 total points
ID: 24240760
With any of the techniques you mentioned you can define the structure yourself. Using XML will probably yield the least amount of work, but whatever technique you choose, it will have a learning curve and it depens where you are coming from whether or not it will be easy to do and to play / work with it.

As an example (just from the top of my hat, nothing "real workld" about it, purely informational) have a look at the following. You'll see that by just looking at it you can read it and understand it. While it is humanly readable (a good thing) it is also machine-readable, by any compliant XML parser.

How you would go from this example to a more elaborate example will cost a bit of time and depends on what information you want to put into it and what relations you want to be clear from it.

<FamilyTree>
    <Family name="Johansson">
        <Father name="John" birthdate="1967-12-14" />
        <Mother name="Clarice" birthdate="1971-07-09" />
        <Child name="Mo" gender="male" birthdate="1998-04-16" />
        <Child name="Clair" gender="female" birthdate="2000-03-26" />
    </Family>
</FamilyTree>

Open in new window

0
 
LVL 20

Expert Comment

by:ChristoferDutz
ID: 24240786
Hehe ... I remember a course at the university that was quite similar. Most people's family trees are hierachical ... unfortunately not all families. In my case we had to display the family tree of Egypt's pharaos and this tree contains a few cycles ... the Database approach is the approach which is best resistant against structural problems ... afer all ... you only have one father and one mother. Doing this in Xml could get tricky ... not impossible, but tricky.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 39

Expert Comment

by:abel
ID: 24240809
Define "tricky"? But I assume you mean that forcing the relationships is just harder. Which is where XSD or RelaxNG comes in,which can be considered what is known as a Database Design for database, but then for XML. Then the "tricky" bit goes away...

Obviously, anything will be tricky unless you know how to define the relationships.
0
 
LVL 20

Accepted Solution

by:
ChristoferDutz earned 400 total points
ID: 24240850
Well as in the case of the pharaos, I think one grandpa had a child with one of his granddaughter. When displaying this with a normal Xml structure, you would have to use Ids and IDrefs. Best would be to define the persons and their relations separately. In ourdays the construct "family" is sadly a rather temporal construct:
<FamilyTree>
    <Relations>
        <child personId="person3" fatherId="person1" motherId="person2"/>
        <child personId="person4" fatherId="person1" motherId="person2"/>
    </Relations>
    <Persons>
        <Person id="person1" name="John" birthdate="1967-12-14" />
        <Person id="person2" name="Clarice" birthdate="1971-07-09" />
        <Person id="person3" name="Mo" gender="male" birthdate="1998-04-16" />
        <Person id="person4" name="Clair" gender="female" birthdate="2000-03-26" />
    </Persons>
</FamilyTree>

Open in new window

0
 

Author Comment

by:danishbacker
ID: 24240882
Thank u both for trying to help me,

I think it is better to go with XML even if dont know it well.
I found many different approaches in XML too
like Parsing XML using DOM, SAX ...?
which one should i use ?
i may need to add and edit child node or some time new family.

is it difficult to do that using XML?

At first I tried to do this with database but it seems very difficult to me, as cud not design the database well.

Also i need to make a view of this family tree.
0
 

Author Comment

by:danishbacker
ID: 24240889
Special Thanks to Abel
0
 
LVL 39

Assisted Solution

by:abel
abel earned 600 total points
ID: 24240907
If you use PHP (which you seem to state in your question) you would automatically go for DOM, because there's no other way. If you use Java, you can go for SAX as well, in .NET you also have the choice (though they do not call it SAX but XmlTextReader).

If the data is huge, SAX-style parsing is recommended, but requires more work to get right. If you use normal sized data, DOM would be fine. As a rule of thumb, on most systems loading XML in your program will require roughly 4 to 5 times the amount of bytes in memory as it takes on disk.

Not, it is not difficult to add child nodes etc. But it helps if you already know a programming language. Start with something very small and then make it slowly bigger.

-- Abel --
0
 
LVL 20

Expert Comment

by:ChristoferDutz
ID: 24240939
In general Sax is great for transforming, Dom is the method of choice, if you want to work with the thing. Cou can think of Sax being someone reading the document out loud and you can hook on to events and read out your own stuff. But after a tag is "read" and all listeners have finished, the information is gone. In dom you get an object representation of the entire document. I'd suggest sticking to the DOM approach.
0
 

Author Comment

by:danishbacker
ID: 24243698
I am happy with the solution. Both of you recommended the same thing (DOM).
I'll carry on with the DOM approach. I think I now know where to start.
 :)

I'll come again if I have doubts when doing this. Hope you people will help me.

Many Thanks to Abel and ChristoferDutz.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to dynamically set the form action using jQuery.
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
Suggested Courses
Course of the Month16 days, 11 hours left to enroll

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question