Design concept help needed: Loading a hierachical text file using a runtime xml rule/structure file

K

Kevin

Hi All
I am thinking about designing a library to load a text based file.
These libraries will be plugged in to a GUI for the end user.

I have a whole load of different file types (about 300 of them) that
all share a similar hierachical structure. Also they all have a
header and a footer, and fields are separated by a vertical bar. Here
is an example of quite a simple one. I hope it is readable.

Group Range L1 L2 L3 Item Name
A 1-*
x Core
x Failure
x Code
B 0-*
x Meter Id
C 0-*
x Type
x Reading

I know it isnt immediately obvious from this chart what is required,
so let me explain.
The file has a header and a footer. It also has 'groups', one per
line between the header and the footer. From the table above, these
groups are called A, B & C. In the file each group containins the
fields as shown above.

The L1, L2 & L3 are to signify the hierachy of the data; in this
example a 'x' doesnt really signify anything.
The Range shows what is required for each group. So from above, the
file must have at least one A group and can have as many as it likes.
Each A group can have zero (i.e. it is optional) to infinite B groups,
and each B group can have zero - infinite C groups.

So a file might look a little like this:
-------------------------
header (date sent etc)
A | 1234 | Yes | J
footer (checksum etc)
-------------------------
i.e:
Group = A
Core = 1234
Failure = Yes
Code = J

Or a file might look like this:
----------------------
header
A | 1234 | Yes | J
B | asdf
C | F | 1234.8
footer
----------------------
or
----------------------
header
A | 1234 | Yes | J
B | asdf
C | F | 1234.8
C | L | 3456.9
B | qwertyio
C | F | 789.5
footer
----------------------
but not
----------------------
header
A | 1234 | Yes | J
C | F | 1234.8
footer
----------------------

Still with me? I hope so.

So for an application I will basically be using a TreeView and a
PropertyGrid; it's going to be pretty simple.
Now I dont really want to have to create classes for all my file
types. What I had in mind is creating the structure of each file type
(i.e. like the table above) as an xml file. That way if a new file
type comes along later the user can just drop in the xml definition
file into the application directory and then have the ability to load
new file types, without a recompile. When the user loads a file, it
will simply locate the relevant xml definition and load/validate the
file according to that.

However, I am then kind of stuck as a design concept. I need to be
able to use databinding in order to user the PropertyGrid. The user
will need to be able to edit existing files and also create new ones
based on the rules.
Would I create an object at run time and then add properties to it?
Can you even add properties to an object at runtime? I'm not so
sure....

Has anyone done anything like this before, or read anything about it
so that I can move in the right direction?
Any help would be greatfully received.
Thanks
Kevin
 
K

Kevin

ok the table isnt very readable. Lets try again:
Group Range L1 L2 L3 Item Name
A 1-*
x Core
x Failure
x Code
B 0-*
x Meter Id
C 0-*
x Type
x Reading
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top