views:

148

answers:

3

Hello

I don't want to create separate configuration file for my app but store the data in the web.config.

I just want to put some XML there and manually parse it because current implementation of ConfigurationManager isn't appropriate for my case.

However, without dummy classes and properties I can't add my XML there without getting Configuration Error: Parser Error Message: Unrecognized element XXXXX. Even if I create dummy configuration classes I can't fix this error in all cases...

Is there any way to mark my XML not to be parsed so that I can use System.XML to manually get the data.

Thx.

A: 

I don't think you can do this - you need to conform to the XML schema for configuration files if you play around in the *.config files - and this means, you need to have your sections according to the specified schema, and if that's the case, ConfigurationManager will be able to parse them (and will do so).

If you need extra config information that doesn't conform to the standard .NET config schema, you'll have to use extra, separate config files - I don't see any other way, sorry.

Marc

marc_s
+1  A: 

Use System.Configuration.IgnoreSectionHandler.

Example:

<configuration>
  <configSections>
    <section 
     name="myCustomSection" 
     type="System.Configuration.IgnoreSectionHandler, System, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" 
     allowLocation="false" />
  </configSections>
...
  <myCustomSection>
     ...
  </myCustomSection>
...
</configuration>
Joe
:)        Thank you
majkinetor
BTW, just curiousity, is it possible to create custom configuration section that will let me handle arbitrary xml configuration in my section ? See http://stackoverflow.com/questions/887437/how-to-get-configuration-element/887507#887507
majkinetor
"is it possible to create custom configuration section that will let me handle arbitrary xml configuration". Yes it is. Look at the System.Configuration.ConfigurationSection class.
Joe
ConfigurationSection doesn't allow for such kind of parsing AFAIK. It is totally oriented on getting properties via attributes, and I didn't see so far any example how to get property contained within element. However, I found IConfigurationSectionHandler, outdated interface that is exactly what I want.
majkinetor
It does allow elements, see my answer to your other post. If the simple example in the MSDN documentation for System.Configuration.ConfigurationElement isn't clear enough, a good way to understand this is to use Lutz Reflector to look at an implementation of a class in the Framework that's similar to what you want. E.g. System.Web.Configuration.AuthenticationSection is an example of a ConfigurationSection with child elements such as FormsAuthenticationConfiguration (which derives from ConfigurationElement).
Joe
+1  A: 

I would suggest creating a custom figuration section if you want to store the data in your .configs

www.codeproject.com/KB/cs/CustomConfigurationSectio.aspx

Dan