Am Dienstag, 15. MÃrz 2005 19:05 schrieb Michael Gauckler: > Dear List, > > I am new to this list and XML in general. > > I'd like to use XML to feed parameters in our modular C++ application.
Hi Michael, this is a good idea - I had the same some months ago... > Modular in the sense that, depending on the configuration (determined > at program startup), different types of objects are created through a > factory. > > Example: > > Class A > { > Helper* h; > } > > Class ColoredHelper : public Helper > {..} > > Class StripedHelper : public Helper > {..} > > On construction an instances of A the factory creates the helper > according to the configuration file and lets h point to it. Seems to be the right concept. > The problems we are facing are: > > a) > > The configuration file must be made consistent. I am thinking of a XML > schema, which describes all possible classes that can be used as > Helper's. With the help of this xsd the configuration can be > validated, or maybe can be transformed into a GUI. Before starting the > application the configuration file can easily be checked against the > schema. Ok, this is the purpose of xml-schema. What is the problem regarding this? > b) > > Parametrization of the Helpers. The different helpers might need > different parameters (ColorHelper maybe only one, whereas > StripedHelper needs two parameters). I am thinking of XML fragments, > which are parsed by the helper object to extract the appropriate > parameters. I usually map argument values to attribute values. They can be checked against their valid range during validation. Different arguments have different attribute names (as 'key'), so you can map each Helper class to an xml element that has as many attributes as the number of arguments the constructor takes. > At the moment I am considering the Xerces parser in SAX mode. Is this > the right decision, or should I rather go for DOM? > > Can XML fragments be passed to another object for parsing (upon > detection of the helpers token)? Or should I add new callback > functions according to the object generated? It's maybe a matter of taste, but I prefer handling DOM-trees for the extraction of xml contents. Be sure to have something like a hierarchical desicion-tree and pick the argument values for your object generation at the last step. > Is the approach feasible, or am I missing something fundamentally? In my applications, most of the persistent configuration information is accessible by the user via menu operation or dialogs. The user settings are written back to the xml configuration file after change, for convenience. Cheers, Axel -- Humboldt-UniversitÃt zu Berlin Institut fÃr Informatik Signalverarbeitung und Mustererkennung Dipl.-Inf. Axel Weià Rudower Chaussee 25 12489 Berlin-Adlershof +49-30-2093-3050 ** www.freesp.de ** --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]