By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,954 Members | 1,248 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,954 IT Pros & Developers. It's quick & easy.

modify value into XML file

P: n/a
Hi,

I've asked yesterday if someone already modify data into XML file using
VB.NET.

In fact, my XML file is like that.

....
<DB>
<DB_Loc>
mytext
</DB_Loc>
</DB>
<SETTINGS>
....
</SETTINGS>
....

I would like to modify my text "mytext" and replace it by some other value.

How can I do this ?
thanks,
Maileen
Nov 21 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Hi Maileen

Without testing...

Dim d As New System.Xml.XmlDocument
d.LoadXml("<DB><DB_Loc>mytext</DB_Loc></DB>")
Dim n As System.Xml.XmlNode = d.SelectSingleNode("//DB/DB_Loc") ' your
example implies that DB is not the root element...
n.InnerText = "A new value"
d.Save("C:\test.xml")

HTH

Nigel Armstrong

"Maileen" wrote:
Hi,

I've asked yesterday if someone already modify data into XML file using
VB.NET.

In fact, my XML file is like that.

....
<DB>
<DB_Loc>
mytext
</DB_Loc>
</DB>
<SETTINGS>
....
</SETTINGS>
....

I would like to modify my text "mytext" and replace it by some other value.

How can I do this ?
thanks,
Maileen

Nov 21 '05 #2

P: n/a
but in your example, i don't load the XML source file
before...everything is done in memory.

before to modify data of node, I want to open the XML file and modify
directly to XML file the value.

Maileen

Nigel Armstrong wrote:
Hi Maileen

Without testing...

Dim d As New System.Xml.XmlDocument
d.LoadXml("<DB><DB_Loc>mytext</DB_Loc></DB>")
Dim n As System.Xml.XmlNode = d.SelectSingleNode("//DB/DB_Loc") ' your
example implies that DB is not the root element...
n.InnerText = "A new value"
d.Save("C:\test.xml")

HTH

Nigel Armstrong

"Maileen" wrote:

Hi,

I've asked yesterday if someone already modify data into XML file using
VB.NET.

In fact, my XML file is like that.

....
<DB>
<DB_Loc>
mytext
</DB_Loc>
</DB>
<SETTINGS>
....
</SETTINGS>
....

I would like to modify my text "mytext" and replace it by some other value.

How can I do this ?
thanks,
Maileen

Nov 21 '05 #3

P: n/a
I've discovered where was the mistake.
I don't know why, but VB wrote the changes into another folder than
where it should be done, so never my xml file was modified even if
folder and file variable where correct.

so code is good.
Maileen

Nigel Armstrong wrote:
Hi Maileen

Without testing...

Dim d As New System.Xml.XmlDocument
d.LoadXml("<DB><DB_Loc>mytext</DB_Loc></DB>")
Dim n As System.Xml.XmlNode = d.SelectSingleNode("//DB/DB_Loc") ' your
example implies that DB is not the root element...
n.InnerText = "A new value"
d.Save("C:\test.xml")

HTH

Nigel Armstrong

"Maileen" wrote:

Hi,

I've asked yesterday if someone already modify data into XML file using
VB.NET.

In fact, my XML file is like that.

....
<DB>
<DB_Loc>
mytext
</DB_Loc>
</DB>
<SETTINGS>
....
</SETTINGS>
....

I would like to modify my text "mytext" and replace it by some other value.

How can I do this ?
thanks,
Maileen

Nov 21 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.