Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / New Users / April 2006

Tip: Looking for answers? Try searching our database.

How to write code for this XML configuration section?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
W. Jordan - 04 Apr 2006 10:18 GMT
Hello,

I would like to add a section in the configuration file like that:

<job name="cleanup">
   <executor type="Test.MyExecutor"/>
   <parameters>
       <string name="outputFile" value="C:\output.log" />
       <int name="maxValue" value="12" />
       <timespan name="timespan" value="0:0:15"/>
   </parameters>
</job>

A job can have multiple (0 to n) parameters. The parameters can be
some values, with a name, of any types.

How can I put it into the exe configuration file? And what kind of classes
should I build to support the configuration?

Signature

Best Regards,
W. Jordan

Kevin Spencer - 04 Apr 2006 12:19 GMT
What version of the .Net Framework?

Signature

HTH,

Kevin Spencer
Microsoft MVP
Professional Numbskull

Show me your certification without works,
and I'll show my certification
*by* my works.

> Hello,
>
[quoted text clipped - 14 lines]
> How can I put it into the exe configuration file? And what kind of classes
> should I build to support the configuration?
W. Jordan - 06 Apr 2006 08:20 GMT
Oops, it is .net 2.0.

I saw something like ConfigurationSection, ConfigurationElement,
ConfigurationSectionGroup, and some other classes, but I did not
see an appropriate example of how to implement the XML config
that I posted at the beginning of this thread.

Signature

Best Regards,
W. Jordan

> What version of the .Net Framework?
>
[quoted text clipped - 17 lines]
>> classes
>> should I build to support the configuration?
Kevin Spencer - 06 Apr 2006 12:12 GMT
I'm not sure where you're looking, and therefore where you "saw" what you
saw. Since I don't know what resources you have available locally, I can
only point you to some references online.

First, the documentation for the .Net Framework 2.0 can be found at:
http://msdn2.microsoft.com/en-us/library/default.aspx

Notice that this is MSDN2, not MSDN.

Here are several other salient points of interest with regards to working
with Configuration in .Net 2.0:

http://msdn2.microsoft.com/en-us/library/kza1yk3a(VS.80).aspx
http://msdn2.microsoft.com/en-us/library/sbk7ee6x(VS.80).aspx
http://msdn2.microsoft.com/en-us/library/system.configuration(VS.80).aspx
http://msdn2.microsoft.com/en-us/library/1fk1t1t0(VS.80).aspx

Now, as to the specifics, you will want to look over the
System.Configuration Namespace:

http://msdn2.microsoft.com/en-us/library/system.configuration(VS.80).aspx

There are several classes in particular that you will work with most often:

http://msdn2.microsoft.com/en-us/library/system.configuration.configuration(VS.8
0).aspx

( Look for the sample code included)

http://msdn2.microsoft.com/en-us/library/system.configuration.configurationeleme
nt(VS.80).aspx

( Look for the sample code included)

http://msdn2.microsoft.com/en-us/library/system.configuration.configurationeleme
ntcollection(VS.80).aspx

( Look for the sample code included)

http://msdn2.microsoft.com/en-us/library/system.configuration.configurationmanag
er(VS.80).aspx

( Look for the sample code included)

http://msdn2.microsoft.com/en-us/library/system.configuration.configurationsecti
on(VS.80).aspx

( Look for the sample code included)

http://msdn2.microsoft.com/en-us/library/system.configuration.configurationsecti
oncollection(VS.80).aspx

( Look for the sample code included)

http://msdn2.microsoft.com/en-us/library/system.configuration.configurationsecti
ongroup(VS.80).aspx

( Look for the sample code included)

http://msdn2.microsoft.com/en-us/library/system.configuration.configurationsecti
ongroupcollection(VS.80).aspx

( Look for the sample code included)

http://msdn2.microsoft.com/en-us/library/system.configuration.configurationsetti
ngs(VS.80).aspx

( Look for the sample code included)

These are your major players. the .Net Framework 2.0 has a much more
powerful and strongly-typed Configuration model. You will need to create
some custom Configuration classes to work with your custom Configuration
Sections.

The bottom-most class is the ConfigurationElement class, which is used for
individual Configuration Elements, at the lowest node level of the XML.
Above this, you have the ConfigurationElementCollection, which manages a
collection of ConfigurationElements.

Generally, you will also need a ConfigurationSection, and possibly a
ConfigurationSectionGroup class to group your ConfigurationElements into
Sections.

Signature

HTH,

Kevin Spencer
Microsoft MVP
Professional Numbskull

Show me your certification without works,
and I'll show my certification
*by* my works.

> Oops, it is .net 2.0.
>
[quoted text clipped - 24 lines]
>>> classes
>>> should I build to support the configuration?
W. Jordan - 07 Apr 2006 03:36 GMT
Hello Kevin,

I am sorry that I am inexperienced. I have the .Net Framework 2.0
Documentation installed on my machine. Thanks for pointing out the
locations of the online resources. I will learn those examples and
try to find out a way to implement my XML configuration sections.

Signature

Best Regards,
W. Jordan

> I'm not sure where you're looking, and therefore where you "saw" what you
> saw. Since I don't know what resources you have available locally, I can
[quoted text clipped - 90 lines]
>>>> classes
>>>> should I build to support the configuration?
Kevin Spencer - 07 Apr 2006 14:06 GMT
Don't be discouraged. When I first started working with the new
configuration model, I had a hard time figuring it out myself.
Unfortunately, that was about a year ago, and I had nobody to point me to at
least the right classes and points of reference. Once I figured those out,
the rest was not so difficult.

Signature

HTH,

Kevin Spencer
Microsoft MVP
Professional Numbskull

Show me your certification without works,
and I'll show my certification
*by* my works.

> Hello Kevin,
>
[quoted text clipped - 97 lines]
>>>>> classes
>>>>> should I build to support the configuration?
Tim Johnson - 23 Apr 2006 08:10 GMT
There was a really excellent article on "The Last Configuration File I'll
Ever Need" that applied to .Net v1.0.

http://www.codinghorror.com/blog/archives/000161.html

But I've never seen any update anywhere related to .Net v2.0.  It basically
uses XML serialization to make generic section readers, as I understand it.  
Do you have any insight on an updated version of this valuable technique for
v2.0?  

> Don't be discouraged. When I first started working with the new
> configuration model, I had a hard time figuring it out myself.
[quoted text clipped - 103 lines]
> >>>>> classes
> >>>>> should I build to support the configuration?
Kevin Spencer - 23 Apr 2006 13:09 GMT
Configuration in .Net 2.0 is fundamentally different than in .Net 1.1. I
would advise you to stick with the resources I posted!

Signature

HTH,

Kevin Spencer
Microsoft MVP
Professional Numbskull

Hard work is a medication for which
there is no placebo.

> There was a really excellent article on "The Last Configuration File I'll
> Ever Need" that applied to .Net v1.0.
[quoted text clipped - 124 lines]
>> >>>>> classes
>> >>>>> should I build to support the configuration?

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.