Click here to Skip to main content
12,894,930 members (59,688 online)
Click here to Skip to main content
Add your own
alternative version


10 bookmarked
Posted 2 Jul 2006

Retrieving settings in different XML configuration formats

, 2 Jul 2006 CPOL
Rate this:
Please Sign up or sign in to vote.
A simple code that retrieves configurations from an external XML file.


We always use the regular app.config or web.config. But sometimes, we want our configuration files to be more flexible. Here's a simple piece of code that will allow you to use more customizable config files.

The Code

What I did here was to create an XmlTextReader and an XPathNavigator to make things easier for me.

xmlTextReader = new XmlTextReader (configurationPath); 

The rest was simple iterations:

XPathNodeIterator iterator = _xPathNavigator.Select(XPath);
while (iterator.MoveNext())
{htValues.Add(iterator.Current.GetAttribute(attributeKey, string.Empty), 

If you want to use the library, all you have to do is call the GetValue method. Please see the sample application.


It's just a simple piece of code. Originally, it was started by a friend, Ivy. But we needed to modify the original version as the need for reusability came in. Of course, you would want to use some objects in between that will fetch the code for you. I used straightforward calls just to show how to fetch the settings (plus, I'm busy with work :p).



This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

John Conrad
Web Developer
Philippines Philippines
John lives in the Philippines with his family, working as a programmer. He used to program VB6 but is now... ummm... trying to learn C# .Net.

You may also be interested in...

Comments and Discussions

QuestionXML USage as Config Pin
ewewewewewe4-May-07 1:58
memberewewewewewe4-May-07 1:58 
Questionwhat is xml mean Pin
primey1-Oct-06 19:45
memberprimey1-Oct-06 19:45 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170424.1 | Last Updated 3 Jul 2006
Article Copyright 2006 by John Conrad
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid