By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,241 Members | 799 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,241 IT Pros & Developers. It's quick & easy.

How to read and write Hierarchical Configuration Settings

P: n/a
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
Share this Question
Share on Google+
2 Replies


P: n/a
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

P: n/a
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.