How to parse app.config using ConfigurationManager?
Posted
by Amokrane
on Stack Overflow
See other posts from Stack Overflow
or by Amokrane
Published on 2010-05-10T16:26:16Z
Indexed on
2010/05/10
16:34 UTC
Read the original article
Hit count: 350
I was using a certain method for parsing my app.config file. Then I was told that using ConfigurationManager is better and simpler. But the thing is I don't know how to do it with ConfigurationManager.
My original code looked like this:
XmlNode xmlProvidersNode;
XmlNodeList xmlProvidersList;
XmlNodeList xmlTaskFactoriesList;
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load("app.config");
xmlProvidersNode = xmlDoc.DocumentElement.SelectSingleNode("TaskProviders");
xmlProvidersList = xmlProvidersNode.SelectNodes("TaskProvider");
foreach (XmlNode xmlProviderElement in xmlProvidersList)
{
if (xmlProviderElement.Attributes.GetNamedItem("Name").Value.Equals(_taskProvider))
{
xmlTaskFactoriesList = xmlProviderElement.SelectNodes("TaskTypeFactory");
foreach (XmlNode xmlTaskFactoryElement in xmlTaskFactoriesList)
{
if (xmlTaskFactoryElement.Attributes.GetNamedItem("TaskType").Value.Equals(_taskType))
{
taskTypeFactory = xmlTaskFactoryElement.Attributes.GetNamedItem("Class").Value;
}
}
}
}
What would be the equivalent using ConfigurationManager? (Because all I can see is how to get keys not nodes..)
Thanks
© Stack Overflow or respective owner