Solved

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

Posted on 2004-08-06
5
216 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
Comment Utility
why not just serialize it to XML ?

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

Expert Comment

by:jjacksn
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
This video discusses moving either the default database or any database to a new volume.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

744 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

16 Experts available now in Live!

Get 1:1 Help Now