使用VB.net查找并替换XML中的文本

时间:2011-06-22 10:42:42

标签: vb.net

我有一个XML文件。在我找到字符串的XML文件中(“C:\ Results \ test1_01”)我需要用(“B:\ final \ test1_01”)替换它并保存它。请指导我这个。

提前致谢,

1 个答案:

答案 0 :(得分:2)

       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