views:

377

answers:

5

MS's OneNote uses a data hierarchy that is essentially a simple tree, even though the info is displayed via a tabbed interface rather than a treeview. You begin with "notebooks," which can have "sections," which have "pages." I'm trying to model this. In my case, a page would be linked to the contents of a RichEdit.

My problem is not that I can't figure out a way to do this. My problem is that I am unsure which of several possibilities will ultimately be simplest. That's where I am hoping you will come in.

I could, for example, use a regular [MyBase] database. A Page dataset would have fields for its name, and the RichEdit data. Pages would be nested inside Sections, and Sections would be nested inside Notebooks.

If I thought about it for awhile, it seems like this is something that could be modeled with simple stringLists as well, especially if each element in the list included comma separate values for an ID and position in the hierarchy, as well as notebook/section/page name.

But then this also seems like something that might be well suited for XML ... if I were to learn more about XML :-)

What do you more experienced folks think?

Thanks, as always ...

+2  A: 

I think it depends on how you want to save the data. If you plant to use a database for shared access, speed and large amounts of data: just normalize the data and create the structure you proposed.

If you want the user to save data locally on a filesystem, I do think that XML will be a good solution because it allows you to store the data in a structured file.

So... how do you want the user to store and use the data?

birger
Thanks for the response ... I want users to save data locally on a filesystem. Perhaps it's time for me to learn more about XML in Delphi :-)
Al C
+3  A: 

Whether you go with a database or XML, try putting your data access routines in a datamodule. Let your GUI unit(s) make calls to public methods of the datamodule, and ensure that those calls do not depend on how your data are stored. That way, you can start with one approach, and switch to the other just by editing your datamodule.

Argalatyr
+3  A: 

One thing you could try would be to use a structured storage system. The concept is simple, you work with a datafile much like you would a disk and folders...thing is that the folders and files are all under your exclusive control. The only issue is that it doesn't exactly scale well to multiple users, but then neither does XML. (a good structured storage library is available on gabr's blog)

For a "multi-user" system, your best option will be to implement using tables. You can probably get a good start at things using Microsoft Access and ADO, which migrates to MS Sql Server very easily. From your brief description, I would expect you to have three tables, NOTEBOOKS, SECTIONS, PAGES. The Pages would have a Foreign key relationship (detail/master) to Sections and sections would have a Foreign key relationship with Notebooks.

skamradt
+2  A: 

If you are storing it in a file system, why not use.... folders? That's what OneNote does. A "notebook" and a "section group" are simply regular file system folders. The only other level is a section which is the .one file. There is a very limited hierarchy in there (it's just pages, any of which can be marked as subpages but these are not really linked in any way to a parent.)

Inside the .one file you can use XML to represent your pages, though this is not what OneNote does. OneNote uses a binary file format in order to facilitate fast edits, object-level synchronization, multi-user access, and compact storage.

If you look around for info about "random access files" you can get an idea for how to do this. But try to avoid using XML if you think it can get large because it will become cumbersome to make edits. You'd need to load the entire XML file, make changes in-memory, then write the whole thing back out again.

Josh Einstein
+1  A: 

I think at your data like a tree.

node { 
    id
    parent_id
    content
    type
}

nodes with paren_id = 0 are notebook. type is optional but could be useful. content on page and notebook will give you a page/notebook description for free :D

I will use a simple table on sqlite or MyBase or whatever. I think a little db is better than Xml because xml force you to load all data in memory.

Massimiliano