I'm building a program – let's call it a generic framework - that reads configuration data from XML files and should make that data easily accessible to application programmers. The trick is that the program does not know ahead of time what's in the XML files or the structure of the files. (Other than it's XML.)
In my prototype, I used examples, and knew ahead of time what configuration data was being read. (cheating) …. I created
java objects as data structures to hold the specific data from the XML files. I was then able to write a nice, pretty generic reusable processing algorithm that matches XML tag names to defined variables in the object and assigns values. Since the XML file could contain more than one instance of the same data structure, I stored as a vector of such java objects.
Now, to do the same thing without knowing the data file structure in advance, I could use reflection to build data objects as the program reads in the XML files.
I don't want to make my question confusing, but I should say that I'm at a point of wondering whether this is a good approach. So, that's kind of my real question – better ideas?
This is part of an open-source project called “High Level Logic” (HLL). The core system has configuration needs for such things as IP and port to communicate with other systems (or within HLL as a way of being loosely coupled). So, there are some things that I can handle by knowing the structure of the data files in advance.
But ultimately, I'd like to allow application programmers to define their own configuration files to extend the system in any way that they'd like, and I'm just trying to make that process as simple as possible for the application developer (and for other reasons that I won't mention just to try to keep this simple); i.e. they would not need to predefine data structures in their application programs. They could add as many application specific configuration files as they'd like. Unlike my program, the application programmers that create the XML files would know what they contain and would fetch data using a core method that takes search tree information as argument.
(I haven't completely rejected the idea of storing the XML data as Document objects and doing DOM processing to recover information - I'm just guessing that my way provides a faster way to access data when the program is running. Don't know if I want to build this in many ways and
test speed though. This project has been spread out over years, and just now I can't remember whether I had other reasons to avoid this approach when I created the prototype.)