storing Hierarchical data in an xml file instead of the database...

Posted on 2005-04-29
Last Modified: 2008-01-09
For a project, the data needs to be sotred in a Hierarchical fashion. I've been reading articles on it and everyone seems to save it in the database. I wanted to know is there a problem with saving the data as an xml file and just updating this file rather than the database? Does anyone see any potenial problems with this?
Question by:dotnet22
    LVL 10

    Expert Comment

    Hi dotnet22,

    It Depends on the size of your data, you would not want to store many rows ()  in XML as searching and sorting would be very inefficient

    LVL 23

    Expert Comment

    There has got to be a good reason why everyone uses databases. Databases use time-tested techniques and affords efficiencies when dealing with large data. Xml is best used as a delivery mechanism between disparate, heterogeneous environments. It is useful for describing small data sets, but is not a good choice as a storage mechanism (unless it is temporary). You can use Xml to store data if you purchase Tamino Server from Software AG but it is very pricey.

    I'd recommend against it if you can gain access and usage to databases. Dont re-invent the wheel.

    Author Comment

    But this is a dynamic tree structure... I'm not quite sure how to handle this in the database... Setting up the parent/child relationships

    Author Comment

    This is what I don't understand: How to store the hierrchical data in the database, then take this data and display it in a treeview and allow the user to dynamically create a new node and then setting up this relationship in the database...
    LVL 23

    Accepted Solution

    Consider the following table structure:

    ID            int                  NOT NULL            IDENTITY(1,1)            Primary Key
    Text            varchar 100       NOT NULL
    ParentID      int                  NULL                                          Indexed (Self-Reference To ID Column)

    Now that's the data stored:

    Now you can grab this data into a DataSet:

    Then you can transverse the hierarchy through code:

    IterateNodes(table.Select("ParentID IS NULL","ID"),treeView.Nodes);

    // ROOT
    private void IterateNodes(DataRow [] rows,TreeNodeCollection collection)
          //pseudo-code using for example the WinForms Tree View
          foreach(DataRow row in rows)
                TreeNode node = new TreeNode();
                node.Text = (string)row["Text"];
                node.Tag = row["ID"].ToString() + "!" + row["ParentID"].ToString();
                IterateNodes(row.Table.Select(string.Format("ParentID = {0}",row["ID"]),"ID"),node.Nodes);


    Featured Post

    Highfive Gives IT Their Time Back

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
    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…
    Sending a Secure fax is easy with eFax Corporate ( First, Just open a new email message.  In the To field, type your recipient's fax number You can even send a secure international fax — just include t…
    This video discusses moving either the default database or any database to a new volume.

    728 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

    18 Experts available now in Live!

    Get 1:1 Help Now