Ok my code:
What im trying to do is to change the xnod.value so that each time the loop occurs, it adds one to the loop. Sounds easy, but a number of things have stopped me from doing this so far.
VB.NET:
Imports System.IO
Imports System.Text.RegularExpressions
Imports System.Xml
Module Module1
Private Sub ReadXML(ByVal xnod As XmlNode)
Dim xnodWorking As XmlNode
Dim strValue As String = CType(xnod.Value, String)
Dim oFile As System.IO.File
Dim oRead As System.IO.StreamReader
oRead = oFile.OpenText("C:\template.txt")
Dim LineIn As String
Dim temporarytext As String
If Len(strValue) > 0 Then
While oRead.Peek <> -1
temporarytext = ""
LineIn = oRead.ReadLine() 'read line from template file
Dim oWrite As System.IO.StreamWriter
oWrite = oFile.CreateText("C:\newtesttempfile.txt") 'create new txt file
oWrite.WriteLine(LineIn) 'write line from template file to txt file
oWrite.Close()
'replace the $ph$'s with xnod.value
temporarytext = Regex.Replace _
(IO.File.ReadAllText("c:\newtesttempfile.txt"), "\${3}(?<name>.+?)\${3}", [B][U][SIZE="4"][COLOR="Red"]xnod.Value[/COLOR][/SIZE][/U][/B]) 'the xnod.value is not changing - need to get it to change
Dim oWrite2 As IO.TextWriter
oWrite2 = IO.File.AppendText("c:\output.txt")
Console.WriteLine(temporarytext)
oWrite2.WriteLine(temporarytext)
oWrite2.Close()
End While
End If
If xnod.HasChildNodes Then
xnodWorking = xnod.FirstChild
Do Until IsNothing(xnodWorking)
ReadXML(xnodWorking)
xnodWorking = xnodWorking.NextSibling
Loop
End If
End Sub
Sub Main()
Dim xmlData As New XmlDocument
xmlData.Load("c:\data_file3.xml")
Dim xnod As XmlNode = xmlData.DocumentElement
ReadXML(xnod)
Console.ReadKey()
End Sub
End Module
What im trying to do is to change the xnod.value so that each time the loop occurs, it adds one to the loop. Sounds easy, but a number of things have stopped me from doing this so far.
Last edited by a moderator: