Solved

Storing a tree of objects in a column as a string or binary form.

Posted on 2004-08-06
5
219 Views
Last Modified: 2010-04-15
I am wondering which is a better way of storing a tree of objects in DB.
I have requirement like this
and i have 2 options
1. convert the tree into xml and store it as a string or
2. Serialize it and store it in binary form.
Anny suggestions please.

Thanks.
0
Comment
Question by:pathurun
5 Comments
 
LVL 37

Expert Comment

by:gregoryyoung
ID: 11739932
why not just serialize it to XML ?

http://www.topxml.com/xmlserializer/serializer.PDF
0
 
LVL 5

Expert Comment

by:jjacksn
ID: 11742578
It depends on what you are trying to do.  binary storage will be much smaller, but unreadable outside of your program.  You will be able to read XML outside of your program, and, in general, I would recommend using XML unless there is a reason not to.
0
 
LVL 4

Expert Comment

by:Jigit
ID: 11745685
Another option is to store it in a table with the following schema:

ID | Parent ID | Data
0  | null         | root data
1  | 0            | first child data
2 |  0            | second child data
0
 
LVL 2

Expert Comment

by:jrberg
ID: 11764465
I agree with Jigit.  It's always best IMO to store data in a database so that it could be read in by other applications and sources and understood and serialization in binary would take that away from you.  Ofcourse with XML serialization this is somewhat true also because some of the state information is going to be stored as nested garbeled text in the XML.  I would just create a method for saving data and retreiving data and saving it in the format Jigit shows.

-- Jerry
0
 
LVL 37

Accepted Solution

by:
gregoryyoung earned 500 total points
ID: 11764611
whether or not you want to use that format depends completely on what the data is ...

for instance if this data is a users customized web menu this may very well be the wrong way of doing it, it would be much more difficult to maintain especially if the data has no use outside the context of dealing with the menu ...

Another good example of when to not use this would be if you don't know the types of data being placed in i.e. the format is dynamic (users can define their own types etc). Again very easy to do with XML very difficult to do in a database.

Another reason for possibly storing in XML would be if speed is a huge concern ... when you store data in a table as above you need to query multiple times as you build in order to get children (or you need to suck back the whole table and use rowfilters). this also holds true if a database query is considerred "expensive" in your system (i.e. remote or slow database etc)

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
A short film showing how OnPage and Connectwise integration works.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

914 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now