Find and replace a text in XML using VB.net
I have a XML file. Inside t开发者_开发百科he XML file where ever I find the string as ("C:\Results\test1_01") I need to replace it with ("B:\final\test1_01") and save it. Please guide me for this.
Thanks in advance,
Try
Dim fOut as StreamWriter = New StreamWriter("Output.xls")
Using sr As StreamReader = New StreamReader("YourXMLFile.xml")
Dim line As String
Do
line = sr.ReadLine()
fOut.WriteLine(Line.Replace("C:\Results\test1_01","B:\final\test1_01"))
Loop Until line Is Nothing
sr.Close()
fOut.Close()
End Using
Catch E As Exception
' Let the user know what went wrong.
Console.WriteLine("The file could not be read:")
Console.WriteLine(E.Message)
End Try
精彩评论