Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Convert text files to XML - suggestions for newbie

Status
Not open for further replies.

jopaumier

Programmer
Mar 15, 2002
97
US
Hi,

I've been working on the VB6 side of things for a while now, but have been asked to assist someone (a very newbie to VB) who is developing a standalone program with VB .NET to take 8 ASCII files (each with fixed length records) and convert them to XML based on the schema that was provided to us.

We've got some books, but there's a lot of material to sift through. Any suggestions on where to look for more assistance - tutorials, books, specific locations on Microsoft's site, etc..

Seems like it should be straightforward, but when you have to start from little or no knowledge of both VB.NET and XML, it feels overwhelming.

Thanks,
Jim
 
Hi
I hope the following code will help you out
i haven't tested it but its only the logic which i think will run
Regards
Nouman

Imports System
Imports System.IO
Imports System.Collections

Imports System.Xml

Private Sub WriteFromTextFileToXML(ByVal strTextFile as string,ByVal strXMLFile as string)
Dim objReader As New StreamReader(strTextFile ) 'strtextFile like "c:\test.text"
Dim sLine As String = ""
Dim arrText As New ArrayList()
'XML file declaration
Dim dom As New XmlDocument()
Dim inXmlNode As XmlNode
dom.Load(strXMLFile") 'Make an empty XML file in notepad or anywhere first OR if you want to creat an XML file first then you can do it easily with FILE I/O routing in VB .Net
inXmlNode = dom.DocumentElement

Do
sLine = objReader.ReadLine()
If Not sLine Is Nothing Then
arrText.Add(sLine)
End If
Loop Until sLine Is Nothing
objReader.Close()

For Each sLine In arrText
'Now wrting content to the XML file
Dim NewElement As XmlElement
Dim NewTextNode As XmlText
NewElement = dom.CreateElement("MYColumn")
NewElement.SetAttribute("value", sLine)
inXmlNode.AppendChild(NewElement)
Next

End Sub








Nouman Zaheer
Software Engineer
MSR
 
Nouman,

Thank you for the submission. Since I do not have vb.net on my machine, I will pass it on to my colleague. It may be a couple days before we actually implement it (I think he is on yet another project at the moment) and test it out. I'll be back to let you (and the tek-tips community) know how it went.

Jim
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top