473,395 Members | 1,972 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

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 2492
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: John Fred | last post by:
I have created a XML File With XmlTextWriter and the result is : <?xml version="1.0" encoding="utf-8" standalone="yes"?> <Configuration> <Settings> <DbName>DoxWork</DbName>...
7
by: | last post by:
In the beginning we had Ini files. Later we had registery files. Now have xml files and our read-only myapp.config file. My question now, is what is the best way to store and load user and...
3
by: Danny | last post by:
Hello, I was wondering if anyone knew if it was possible to make changes to an application's App.config file at runtime and then be able to access those changes immediately. The following is...
1
by: MrXs | last post by:
i have a setting form for my program and wish to allow the setting to be saved and reopened to the last set setting on program startup.. lets say i have a xml file like this : <?xml...
1
by: vkrasner | last post by:
It works with VS2003 and does not in VS2005: in VS2003 : string sMyvalue = ConfigurationSettings.AppSettings; in VS2005 (does not work!!) string sMyvalue = ConfigurationManager.AppSettings; ...
2
by: Mark Friedman | last post by:
I've seen lots of documentation on how to create and read custom configuration settings but I'm interested in reading a standard setting (i.e. the loginUrl attribute of the authentication/forms...
4
by: Josema | last post by:
Hi to all, Im searching a hand to solve an Exception that i get when i try to give the user to a gmail account... Any help would be appreciated.. Thanks in advance This is a piece of my...
2
by: =?Utf-8?B?c2lwcHl1Y29ubg==?= | last post by:
Hi Is there any way to Read an INIFile from a string or Stream instead of a physical file ??? I want to read the INIFile into a string then store in a db but when I read the string from the...
6
by: brianrpsgt1 | last post by:
I am new to scripting. I am trying to read the settings from a serial device using Python. I have been able to successfully connect to the device and change baud rate settings, ect... with...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.