XML Woes - Again

B

bede

I have the following in my config file :
Code:

<configuration>
<appSettings>
<add key="ServerIPAddress" value="127.0.0.14444" />
</appSettings>
</configuration>

To update the node I use the following :
Code:

Dim doc As New XmlDocument() configName = "myconfig.config"
doc.Load(configName ) 'ServerIPAddress
Dim elServerIPAddress As XmlElement =
DirectCast(doc.SelectSingleNode("/
configurationappSettingsadd[@key='ServerIPAddress']"), XmlElement)
If elServerIPAddress IsNot Nothing
Then
elServerIPAddress.SetAttribute("value", Me.txtServerIP.Text)
End If


Which works fine but what I want to know is :

If the node does not exist how do I create it ?

Thanks in Advance folks :)
 
B

bede

I have the following in my config file :
Code:

<configuration>
  <appSettings>
     <add key="ServerIPAddress" value="127.0.0.14444" />
  </appSettings>
</configuration>

To update the node I use the following :
Code:

Dim doc As New XmlDocument() configName = "myconfig.config"
doc.Load(configName ) 'ServerIPAddress
Dim elServerIPAddress As XmlElement =
DirectCast(doc.SelectSingleNode("/
configurationappSettingsadd[@key='ServerIPAddress']"), XmlElement)
If elServerIPAddress IsNot Nothing
Then
   elServerIPAddress.SetAttribute("value", Me.txtServerIP.Text)
End If

Which works fine but what I want to know is :

If the node does not exist how do I create it ?

Thanks in Advance folks :)

No Ideas ??
 

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

Top