sde Posted November 10, 2005 Posted November 10, 2005 Here is my xml file: configs.xml <configs> <config name="foo"> <path>c:\mypath</path> </config> <config name="bar"> <path>c:\anotherpath</path> </config> </configs> How can I get the info of 1 node by name, modify the path, and write it back to the xml file? Quote codenewbie
VagabondSW Posted November 11, 2005 Posted November 11, 2005 The short answer (the one I have time for now) is that you have to use XML DOM, which loads the entire document into memory, allows you to make edits, then writes it back to disk. The other option is to download the samples from Dino Esposito's book, Applied XML Programming for Microsoft .NET. Review the XmlReadWriter project under the Chap04 folder. Quote "Never ascribe to malice that which can adequately be explained by incompetence." -- Napolean Bonaparte
jo0ls Posted November 11, 2005 Posted November 11, 2005 Theres a bit here too: http://msdn.microsoft.com/msdnmag/issues/05/11/BasicInstincts/default.aspx Quote
TheBeliever Posted November 17, 2005 Posted November 17, 2005 (edited) Private Sub frmReadWriteXML_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim xml_Document As New XmlDocument Dim xml_Node As XmlNode Dim strFilePath As String Dim strNewVal As String 'XML file path strFilePath = "c:\temp\females.xml" 'New value for the Node. strNewVal = "Scarlett Johansson" 'She became 21 yesterday. 'Load document - place it into memorty. xml_Document.Load(strFilePath) 'Select node. xml_Node = xml_Document.SelectSingleNode("//Name") 'When node excist then write, otherwise do nothing. If xml_Node Is Nothing Then 'Node not found. Else 'Node found - change content. xml_Node.InnerText = strNewVal 'Save document - write to harddisk. xml_Document.Save(strFilePath) End If 'Release resources. xml_Document = Nothing End Sub End Class I used this code for the same problems you asked for. Parts of this code comes from Visual Basic.NET Database programming by Rod Stephens. Apoligize for my not perfect English and good luck with your program. :) Edited January 10, 2006 by PlausiblyDamp Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.