Reading a text file and XML file...

judge

Member
Joined
Dec 7, 2009
Messages
18
Programming Experience
Beginner
I have a text file called template.txt and an XML file called datafile.xml.

Example content of template.txt
"There was a man called $$$placeholder1$$$"

Example content of datafile.xml
<placeholder1>Joe Bloggs<placeholder1 />

Basically what i need to achieve is a console application which when executed, replaces the placeholders in the template.txt file with the relating name from the XML file.

Any help would be greatly appreciated :)

(so far i can search the template.txt file for the text value "$$$placeholder1$$$", along with its character position within the file.)
 
Sorry, I didnt really understand XML too well. However, ive got it to do what i want now using:

Imports System.Xml.XPath

Module Module1

Sub Main()
Dim doc As XPathDocument
Dim nav As XPathNavigator
Dim iter As XPathNodeIterator

doc = New XPathDocument("c:\data_file.xml")
nav = doc.CreateNavigator
iter = nav.Select("CATALOG") 'Your node name goes here
'Loop through the records in that node
While iter.MoveNext
'Get the data we need from the node
Dim iterNews As XPathNodeIterator
nav = iter.Current
iterNews = nav.SelectDescendants(XPathNodeType.Element, False)
'Loop through the child nodes
While iterNews.MoveNext
Console.WriteLine(iterNews.Current.Name & ": " & iterNews.Current.Value)

End While
End While
Console.ReadKey()
End Sub

End Module
 
Is this related to this thread? I don't see how iterating xml nodes is useful for this problem. Adding another root node level in the data doesn't change anything in regard to the previous code since the xpath expression does relative lookups.
 
Youre correct, thats actually not what I wanted to do. Need to use the template.txt file and create a new output file for each group of placeholders in the data_file.xml. Thought I could change the previous code which i posted in order to achieve this, but had no success.

Thanks,
Judge
 
Last edited:
I realise what I have to do is change the function, or to call another function. Just playing around with the function at the min to see what I can achieve.
 
Back
Top