Hi All;
I have a XML file like the old ini and I want to write to a specific node in it. I have the Microsoft sample (101 VB.NET Samples), it has a project with write and read XML files. Here it is the sample code from it.
VB Code:
Private Sub ModifyElementValue() ' Shows how to modify an element's text value Dim xDoc As New XmlDocument() xDoc.Load(mstrModifyFile) Me.txtXMLDisplay.Text = xDoc.OuterXml Dim xNode As XmlNode Dim xElem As XmlElement Dim xElmntFamily As XmlElement xNode = xDoc.SelectSingleNode("//Person") If Not (xNode Is Nothing) Then xElem = CType(xNode, XmlElement) ' Change "Gerald L. Smith" to "Jerry Smith" xElem.InnerText = "Jerry Smith" Me.txtXMLEdits.Text = xDoc.OuterXml Else Me.txtXMLEdits.Text = String.Format("Family Node was not found. Please try the '{0}' option first.", CMD_CREATE_XML) End If End Sub
I run it and it didn't change the XML element with the new value, I have also another code and it dosen't work too.
VB Code:
Dim xmlList As XmlNodeList Dim xmlDoc As New XmlDocument Try xmlDoc.Load(XMLFileName) xmlList = xmlDoc.GetElementsByTagName(NodeName) If xmlList.Count > 0 Then xmlList(0).InnerText = ValueString End If Catch ex As XmlException End Try
Within the program when runing and debuging the value changed but in the real after I close the application and return to run it again the old value of the element still as it not changed![]()




Reply With Quote