Newbie: Read/write XML file

A

Adriano

hello,

I have the following XML file (config.xml):

********
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<dbSettings>
<add key="dbhost" value="SQLSERVER" />
<add key="dbuser" value="user" />
<add key="dbpass" value="pass" />
<add key="dbname" value="Northwind" />
</appSettings>
</configuration>

********
Can anyone send me the code for reading and modifying that values please,

thanks in advance,
Adriano
 
J

Jared

First, the name of the config file should be applicationname.exe.config for
this to work. if you leave the name config.xml you will have to provide all
the reading and writing functionality yourself.

Secondly, your xml is not well formed. You have an opening <dbSettings> and
a closing <appSettings>. The config file should is case sensitive (all xml
is case sensitive) and needs to be in the format of :

<configuration>
<appSettings>
<add key="mykey" value="myvalue" />
</appSettings>
</configuration>

I thought there was a method that was declared as shared, but, I couldn't
find it. If anyone know it I'm sure they will post. I don't think your
program was meant to alter the .config file directly, so, there aren't any
strait-forward methods of modifying your custom settings. You can however
create an instance of xmldocument and make the changes yourself.

' Reading the settings
Dim Reader As New Configuration.AppSettingsReader
Dim host As String = Reader.GetValue("dbhost", GetType(System.String))
Dim user As String = Reader.GetValue("dbuser", GetType(System.String))
etc...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top