Solved

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

Posted on 2004-08-06
5
222 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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

821 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