Doug Ransom wrote:
> How can one add a section to their configuration file which allows for
> whatever XML the author wants? The
> System.Configuration.SingleTagSectionHandler doesn't work if I want
> my own xml elements within the config file.
>
> The config file mechanism seems really bizaree to me. I cannot
> understand the advantage provided with the current format over just
> having an XML file and allowing people to put in their own elements
> and read out what they expect to be there, and the dotnet framework
> Configuration.Settings could have just provided the file location or
> XML DOM Tree. If I wanted everything to be key/value pairs, an ini
> file would have been good enough.
Its actually quite straightforward.
1) add a <section> or a <sectionGroup> and <section> for your new XML
section in the configuration file. This can be your app config file or
machine.config
2) in <section name> give the name of your section
3) in <section type> give the full type name of a handler (ie the full name
including the namespace and the full name of the assembly)
4) create an assembly that has the handler that implements
IConfigurationSectionHandler. This class should have a method called
Create() that is called when code tries to access your section. Your code
should read the section and create an appropriate object from the data, for
example a HashTable.
5) your client code calls ConfigurationSettings.GetConfig to read the
section. If the section is nested then you give the full path within the
<configuration> node with XPath like syntax (ie separate the elements of the
path with /).
Here is a simple example that illustrates what I have said:
http://www.grimes.demon.co.uk/Downlo...stomConfig.zip
The code creates a new section that describes a form. The section handler
reads this information, creates the form and controls on the form and
returns the form so that it can be displayed.
Richard
--
my email
(E-Mail Removed) is encrypted with ROT13 (
www.rot13.org)