Answered by:
updating XML Child

Question
-
User-379502100 posted
I'm hoping that someone can point me in the right direction.
I have been searching for a way to update a value in a child node but have been unable to find a way that fits the format of the XML file.
In the example below, I need to update the value in childnode(8) from value="341000" to what has been selected from a comboBox "cbTxFreq.Text".
The best I have been able to do is to append data to the childnode.
Is there a method to simply update the Value and save it?
I'm using VB.Net 2008
Thanx in advance
___________________________________________________________________
XML SAMPLE
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<configuration>
<digital type="bool" value="false" />
<dl_map_timer type="int" value="50" />
<pilot_fix type="bool" value="true" />
<adpt_mod type="bool" value="true" />
<broadcast_modulation type="string" value="bpsk_12" />
<cell_radius type="float" value="50" />
<chnl_bw type="float" value="3.5" />
<cyc_prfx type="float" value="0.25" />
<dl_cf type="int" value="3410000" />
</configuration>
____________________________________________________________
Dim MyXML As New XmlDocument()
Dim filename As String = "c:\ObrXMLFile.xml"
MyXML.Load(filename)
Dim MyXMLNode As XmlNode = MyXML.SelectSingleNode("/configuration")
If MyXMLNode IsNot Nothing Then
MyXMLNode.ChildNodes(8).InnerText ="dl_cf=" & "int" & " value=" & cbTxFreq.Text
End If
' Save the Xml.MyXML.Save("c:\ObrXMLFile.xml")
Friday, August 29, 2014 1:01 PM
Answers
-
User-379502100 posted
That help a great deal.
thanx again
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Friday, August 29, 2014 2:30 PM
All replies
-
User-1806150748 posted
I have tried this and it is working.
Dim MyXML As New XmlDocument() Dim filename As String = "C:\ObrXMLFile.xml" MyXML.Load(filename) Dim MyXMLNode As XmlNode = MyXML.SelectSingleNode("/configuration/dl_cf") If MyXMLNode IsNot Nothing Then MyXMLNode.Attributes("value").Value = cbTxFreq.Text ' MyXMLNode.ChildNodes(8).InnerText = "dl_cf=" & "int" & " value=" & "newval" End If ' Save the Xml. MyXML.Save("C:\ObrXMLFile.xml")
Friday, August 29, 2014 1:46 PM -
User-379502100 posted
Works very nice indeed. Thanx
Could you sugest how to use this form to update multipul ChildNodes that fall under the "/configuration" as in the example.
Dim MyXMLNode As XmlNode = MyXML.SelectSingleNode("/configuration")
If MyXMLNode IsNot Nothing ThenMyXMLNode.dl_cf.Attributes("value").Value = cbTxFreq.Text
MyXMLNode.chnl_bw.Attributes("value").Value = cbBW.Text
end ifor somthig like that.
Being new to XML I'm still having problems with proper formating.
Friday, August 29, 2014 2:24 PM -
User-1806150748 posted
yes, you have to select each of nodes like
Dim MyXMLNode As XmlNode = MyXML.SelectSingleNode("/configuration/dl_cf")
and then update values using attribute.
If this helps, please mark this as answer.
Friday, August 29, 2014 2:27 PM -
User-379502100 posted
That help a great deal.
thanx again
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Friday, August 29, 2014 2:30 PM -
User-1806150748 posted
Can you mark , my reply as answer, that will be great help!
Friday, August 29, 2014 2:39 PM