Link to home
Start Free TrialLog in
Avatar of pathurun
pathurun

asked on

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

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.
Avatar of gregoryyoung
gregoryyoung
Flag of Canada image

why not just serialize it to XML ?

http://www.topxml.com/xmlserializer/serializer.PDF
Avatar of jjacksn
jjacksn

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.
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
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
ASKER CERTIFIED SOLUTION
Avatar of gregoryyoung
gregoryyoung
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial