How to extract attribute values from the Web.config XML file
source link: https://www.codesd.com/item/how-to-extract-attribute-values-from-the-web-config-xml-file.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
How to extract attribute values from the Web.config XML file
I have a web.config file and i want to retrieve the connection string value of particular key name.
<connectionStrings>
<add name="abc" connectionString="Server=(local);Initial Catalog=abc;Integrated Security=SSPI;Max Pool Size=25" providerName="System.Data.SqlClient" />
<add name="cde" connectionString="Server=(local);Initial Catalog=cde; Integrated Security=SSPI;Max Pool Size=50" providerName="System.Data.SqlClient" />
</connectionStrings>
I know i can fetch the connection string by configurationManager but i want to get that through XML reader. Presently i am using
XDocument document = XDocument.Load(fullPath);
var connectionString = from c in document.Descendants(connectionStrings)
select c ;
I am getting both the connection string. but i want to get specific "abc" connection string. can you please help me out.
XDocument document = XDocument.Load(fullPath);
var connectionString = from c in document.Descendants("connectionStrings").Descendants("add")
where c.Attribute("name").Value == "abc"
select c;
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK