This program is supposed to import data from a text file (2 items on each row in the text file) into an array, and export the data into a XML file.
I am not able to create the array correctly, and make the program loop through the array to create the xml file.
Please help of how to enhance this script including the code. I would need somebody to show me how the array, and the loop should be created.
Thanks for any help.
Module Module1
Sub Main()
Console.WriteLine("Converting text file to XML.")
CreateFile()
End Sub
Private Sub CreateFile()
Dim strFields(2) As String
Dim strLine As String
Dim objReader As IO.TextReader
objReader = IO.File.OpenText("Inventory2.txt")
'Import Text File
Do While objReader.Peek > -1
strLine = objReader.ReadLine
strFields = strLine.Split(ControlChars.Tab)
Loop
'Export into a XML file
Dim objXMLFile As XmlTextWriter
objXMLFile = New XmlTextWriter("xmlInventory.xml", Nothing)
objXMLFile.Formatting = Formatting.Indented
objXMLFile.Indentation = 4
objXMLFile.IndentChar = Convert.ToChar(" ")
objXMLFile.WriteStartDocument()
objXMLFile.WriteStartElement("Inventory")
Dim i As Integer
i = 0
For i = 0 To strFields.Length
objXMLFile.WriteStartElement("Location")
objXMLFile.WriteAttributeString("format", "string")
objXMLFile.WriteString(strFields(0))
objXMLFile.WriteEndElement()
objXMLFile.WriteStartElement("Product")
objXMLFile.WriteAttributeString("format", "string")
objXMLFile.WriteString(strFields(1))
objXMLFile.WriteEndElement()
i += 1
Next i
objXMLFile.Close()
End Sub
End Module