?
Solved

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

Posted on 2004-08-06
5
Medium Priority
?
235 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 2000 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

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

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

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
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.
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

762 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