Community discussion forum

how to update data in XML file

  • 1 year ago

    hai all...............

    i created one Xml file and i store data in that Xml file through VB.net code........ Now i want to update one record in that XML file how can i do this through coding.....................Thanks in advance.......

  • 1 year ago

    This might help:

    Imports System.Xml

    Module Module1

    Sub Main()

    Dim xmlDoc As New XmlDocument

    Dim xmlNode As XmlNode

    Dim xpathExpr As String

    xmlDoc.LoadXml("<?xml version='1.0'?><root><person age='21'><name>Martin Fowler</name></person><person age='51'><name>Martin Fowler</name></person><person><name>Kent Beck</name></person><person><name>Dave Astels</name></person></root>")

    ' Find a node

    xpathExpr = "/root/person[@age='51' and name='Martin Fowler']"

    xmlNode = xmlDoc.SelectSingleNode(xpathExpr)

    ' Perform an update

    xmlNode.InnerText = "Fred Brooks"

    ' Check this node

    Console.WriteLine(xmlNode.OuterXml)

    Console.ReadLine()

    ' Check the rest of the document

    Console.WriteLine(xmlDoc.OuterXml)

    Console.ReadLine()

    ' Save updated document

    xmlDoc.Save("updated.xml")

    End Sub

    End Module

     

    HTH

     

  • 1 year ago

    Thanq very much Mr.CAMURPH...............

Post a reply

Enter your message below

Sign in or Join us (it's free).

We'd love to hear what you think! Submit ideas or give us feedback