|
-
Jun 21st, 2006, 11:08 AM
#1
Thread Starter
Hyperactive Member
[RESOLVED] [2.0] How to read tag from xmldocument?? SelectSingleNode method ??
I am reading connection string from config.xml file in the project.
The content of the config.xml file is as follows:
<settings>
<Connection>"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\IntradayPricing.mdb;User Id=admin;Password=;"</Connection>
</settings>
And I am reading the <Connection> tag in the code using:
string sConnectionstring = _config.SelectSingleNode("//Connection").InnerText;
where _config is an XMLDocument object and has the config.xml file in its memory.
when I see the value of sConnectionstring variable, I have the following content :
"\"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\IntradayPricing.mdb;User Id=admin;Password=;\""
for some reason the SelectSingNode method is padding an extra \ where ever there is a " character and because of this I am not able to connect to the data base.
How to read a tag from an xmldoc ?
thanks
nath
-
Jun 21st, 2006, 11:26 PM
#2
Re: [2.0] How to read tag from xmldocument?? SelectSingleNode method ??
Unless you want to edit it you shouldn't be using an XmlDocument anyway. The System.Configuration namespace exists specifically for the purpose of interacting with the config file. Having said that, if you're using C# 2.0 then you should be using application settings and not even thinking about the fact that the config file exists. Just go to the Settings tab of the project properties and create a new setting named Connection of type String and enter the connection string as the Value. You then access that value like this:
Code:
myConnection.ConnectionString = Properties.Settings.Default.Connection;
Voila! There's even a special setting type called ConnectionString that you can use, although I've never used it myself so I'm not sure how different to a straight String it is.
Edit: Note that Properties.Settings.Default is equivalent to My.Settings in VB. There is also Properties.Resources.Default that is equivalent to Mt.Resources in VB. Note also that unless you create a resource or a setting the Reasources and Settings properties will not exist.
-
Jun 22nd, 2006, 07:24 AM
#3
Thread Starter
Hyperactive Member
Re: [2.0] How to read tag from xmldocument?? SelectSingleNode method ??
Jm,
Thanks for the reply.
You are true about having connectionstring in the settings of the project.
But in our LAN environment, it is workable only if we store the connectionstring in the config.xml file because when we move from dev network to production network, we need to again change the settings in the project which we are not allowed to do. so by storing the connection string in the config.xml file, we can just change the connection string in xml file and don't have to compile the code.
besides in this project, I am storing lot of sql statements in the config file.
so I thought I would store even the connection string also.
thanks
nath
-
Jun 22nd, 2006, 07:48 AM
#4
Re: [2.0] How to read tag from xmldocument?? SelectSingleNode method ??
When you create settings in the IDE they are stored in the application's config file, which is an XML file and can be edited by hand. You can simply change the values whenever you want and those will be the values that those settings return within your app.
-
Jun 22nd, 2006, 07:53 AM
#5
Re: [2.0] How to read tag from xmldocument?? SelectSingleNode method ??
As an example, I created a brand new C# project and went to the Settings tab and create a new setting of type string. I then opened the app's config file and here's what it looked like:
HTML Code:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<section name="WindowsApplication1.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
</sectionGroup>
</configSections>
<userSettings>
<WindowsApplication1.Properties.Settings>
<setting name="ConnectionString" serializeAs="String">
<value>I created this value in the application Settings</value>
</setting>
</WindowsApplication1.Properties.Settings>
</userSettings>
</configuration>
-
Jun 23rd, 2006, 11:43 AM
#6
Thread Starter
Hyperactive Member
Re: [2.0] How to read tag from xmldocument?? SelectSingleNode method ??
thank You so much Jm
regards
nath
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|