I need your suggestion about storing data as XML

Results 1 to 2 of 2

Thread: I need your suggestion about storing data as XML

  1. #1
    Join Date
    Dec 1969

    Default I need your suggestion about storing data as XML

    This may be a bit long, but I will try to explain it clearly, so please read on.<BR><BR>I&#039;m writing a web-based file management application (in ASP.NET/C#) that requires keeping track of a hierarchy of the names of folders and their files and subfolders (which may include their own files and subfolders). I need to store this whole organizational structure in memory at all times for quick access and modification. This structure will frequently need to be saved to a single file in some format (text, binary or xml) for storage after the application ends.<BR><BR>At first, I thought of using ArrayLists (one for folders and one for files). Each would be written as a single object into a binary file for storage. But I realize that it would be rather hard to manage nested folders using an ArrayList.<BR><BR>My next attempt is to keep track of the folders using a tree stucture. For instance, the 1st level child nodes will be the 1st level folders, and their children nodes can represent their subfolders, and so on. I need to be using a general tree, not a binary tree because a folder cna have more than 2 subfolders. However, I cannot find a Tree class in .NET anywhere. (There&#039;s not even a BinaryTree class).<BR><BR>But I did notice that an XML document resembles a general tree structure, which is what I need. My question is that is it possible and efficient for me to store a whole folder hierarchy in XML format?<BR><BR>I&#039;ve never worked with XML documents before, but basically, I want to know if it possible for me to keep track of nested folders like this: (my syntax may be far from correct)<BR><BR>&lt;folder name="Main Folder" folderCount="2" fileCount="1"&gt;<BR> &lt;folder name="Subfolder 1" folderCount="1" fileCount="0"&gt;<BR> &lt;folder name="Subfolder 1a" folderCount="0" fileCount="0"&gt;<BR> &lt;/folder&gt;<BR> &lt;/folder&gt;<BR> &lt;folder name="Subfolder 2" folderCount="0" fileCount="0"&gt;<BR> &lt;/folder&gt;<BR> &lt;file name="File 1"&gt;<BR> &lt;/file&gt;<BR>&lt;/folder&gt;<BR><BR>And remember, I need to be able to keep on adding as many levels of nested folders as I want. Am I able to do this with an XML structure? Also, can I dynamically add, remove or modify any folder?<BR><BR>MSDN says that ".NET XMLDocument class implements the W3C Document Object Model (DOM) Level 1 Core and the Core DOM Level 2. The DOM is an in-memory (cache) tree representation of an XML document and enables the navigation and editing of this document"<BR><BR>If I understand this correctly, it means that this "XML Document" is still an object stored in memory which will allow quick access. I can then write this object to an XML or binary file at any time. <BR><BR>.NET also has an easy way to load the data from the XMLDocument object into a DataSet. This can be very convenient for me because I can map this DataSet to a DataView and then display it on the screen using a DataGrid or DataList. That would be perfect.<BR><BR>OK. So would you suggest the XML method? Or should I just stop dreaming and find a way to manage nested folder using ArrayLists and DataTables? Please let me know. Thanks.

  2. #2
    Join Date
    Dec 1969

    Default XML, to me, seems like the..

    .. perfect solution.<BR><BR>I would use a structure like:<BR>&#060;root&#062;<BR> &#060;folders&#062;<BR> &#060;folder name="whatever"&#062;<BR> &#060;folders&#062;<BR> &#060;folder name="another"&#062;<BR> &#060;folders /&#062;<BR> &#060;files&#062;<BR> &#060;file name="pickme.asp"&#062;&#060;/file&#062;<BR> &#060;/files&#062;<BR> &#060;/folder&#062;<BR> &#060;files /&#062;<BR> &#060;/folders&#062;<BR> &#060;files&#062;<BR> &#060;file name="car.asp"&#062;&#060;/file&#062;<BR> &#060;file name="truck.asp"&#062;&#060;/file&#062;<BR> &#060;/files&#062;<BR> &#060;/folder&#062;<BR> &#060;/folders&#062;<BR> &#060;files&#062;<BR> &#060;file name="rootfile.asp"&#062;&#060;/file&#062;<BR> &#060;/files&#062;<BR>&#060;/root&#062;<BR><BR>As you can see, you have an arbitrary root. With in, it has a folders collection and a files collection.<BR><BR>The folders collection contains 1 or more &#060;folder&#062; nodes. Each &#060;folder&#062; node matches the root&#039;s structure of having a folders collection and files collection.<BR><BR>The files collection contains 1 or more &#060;file&#062; nodes.<BR><BR>You can add as many levels as you wish by adding more and more subfolders. I personally don&#039;t see the need of adding a FolderCount and FileCount, as you can easily figure this out.<BR><BR>And, lastly - I personally don&#039;t see how the dataset could be intelligent enough to load a structure like this. Maybe I&#039;m wrong and it does -- but, you&#039;ll have to test it out. You can use XSLT to transform the output to HTML as you need.<BR><BR>I would think you are better off figuring out your own management routines, using XML and XPATH to manage the XML document.<BR><BR>And, the XML document allows for easy saving and loading.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts