469,575 Members | 1,668 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,575 developers. It's quick & easy.

How to read and write Hierarchical Configuration Settings

Hi,
I need to read and write Configuration Settings as shown below:

<MySettings>
<General>
<Color>Red</Color>
<.Font>TimesNewRoman</Font>
<Path>C</Path>
</General>

<Employee Type="Manager"> //More than one employee
<Function Type="Stationary"> //More than one function
<Department name="Department1">
<Line Color="Blue" Font="" HideWhenShrinked="true/false">
<LineEntry Color="Green" Font="Arial">
<Tag> Tag1 </Tag>
<.Pre> Pre1</Pre>
<Post> Post1</Post>
</LineEntry>
<LineEntry Font="Arial">
<Tag> Tag2</Tag>
<.Pre> Pre2</Pre>
<Post>Post2</Post>
</LineEntry>
</Line>
</Department>
</Funtion>

<Function Type="Projects">
<Department name="Department2">
<Line HideWhenShrinked="true/false">
<LineEntry Color="Green" Font="Arial">
<Tag> Tag1 </Tag>
<.Pre> Pre1</Pre>
<Post> Post1</Post>
</LineEntry>
<LineEntry Color="Yellow" Font="Arial">
<Tag> Tag2</Tag>
<.Pre> Pre2</Pre>
<Post>Post2</Post>
</LineEntry>
<LineEntry Color="Yellow" Font="Arial">
<Tag> Tag3</Tag>
<.Pre> Pre3</Pre>
<Post>Post3</Post>
</LineEntry>
</Line>
</Department>
</Function>

</Employee>
</MySettings>

There are two aspects here:
(1) The settings are hierarchical.
(2) When a setting is not specified for any element (eg. Color) I need
to use the setting from the parent element and so on.. If an element
has no parent element I need to get the setting from the General
section.

How can I do this? Can I do this using the new ConfigurationSection in
..Net 2.0 or do I need to use XML and parse the settings file on my own?

Thanks for your help,
Satya.

May 23 '06 #1
2 2370
We solved a similar problem by creating a configuration class. When we
start our application, we read a file containing the settings and
deserialize into an object. At shutdown, we serialize the object into a
file.

The nice thing about using the class is that 1) It works with
propertygrid 2) You can manipulate data inside the accessors

Satya wrote:
Hi,
I need to read and write Configuration Settings as shown below:

<MySettings>
<General>
<Color>Red</Color>
<.Font>TimesNewRoman</Font>
<Path>C</Path>
</General>

<Employee Type="Manager"> //More than one employee
<Function Type="Stationary"> //More than one function
<Department name="Department1">
<Line Color="Blue" Font="" HideWhenShrinked="true/false">
<LineEntry Color="Green" Font="Arial">
<Tag> Tag1 </Tag>
<.Pre> Pre1</Pre>
<Post> Post1</Post>
</LineEntry>
<LineEntry Font="Arial">
<Tag> Tag2</Tag>
<.Pre> Pre2</Pre>
<Post>Post2</Post>
</LineEntry>
</Line>
</Department>
</Funtion>

<Function Type="Projects">
<Department name="Department2">
<Line HideWhenShrinked="true/false">
<LineEntry Color="Green" Font="Arial">
<Tag> Tag1 </Tag>
<.Pre> Pre1</Pre>
<Post> Post1</Post>
</LineEntry>
<LineEntry Color="Yellow" Font="Arial">
<Tag> Tag2</Tag>
<.Pre> Pre2</Pre>
<Post>Post2</Post>
</LineEntry>
<LineEntry Color="Yellow" Font="Arial">
<Tag> Tag3</Tag>
<.Pre> Pre3</Pre>
<Post>Post3</Post>
</LineEntry>
</Line>
</Department>
</Function>

</Employee>
</MySettings>

There are two aspects here:
(1) The settings are hierarchical.
(2) When a setting is not specified for any element (eg. Color) I need
to use the setting from the parent element and so on.. If an element
has no parent element I need to get the setting from the General
section.

How can I do this? Can I do this using the new ConfigurationSection in
..Net 2.0 or do I need to use XML and parse the settings file on my own?

Thanks for your help,
Satya.

May 24 '06 #2
Hi Gary,
In the configuration class that you wrote did you use any of the
..NET configuration classes or did you use xml and parse the whole file
yourself.

thanks,
Satya.

May 24 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by John Fred | last post: by
1 post views Thread by MrXs | last post: by
1 post views Thread by vkrasner | last post: by
2 posts views Thread by =?Utf-8?B?c2lwcHl1Y29ubg==?= | last post: by
6 posts views Thread by brianrpsgt1 | last post: by
reply views Thread by suresh191 | last post: by
4 posts views Thread by guiromero | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.