Results 1 to 4 of 4

Thread: Read Text/Write XML

Threaded View

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2000
    Location
    Tennessee
    Posts
    279

    Read Text/Write XML

    I want to read a comma de-limited text file and and rewrite it as an XML file. The text file is set up as follows:

    FirstName,LastName,AddressLine1, etc.

    I thought I could read the text file, insert the values into a struct, and then write the values to an XML file. Here's an example:

    Structure Person
    Public FName As String
    Public LName As String
    Public AddressLine1 As String
    End Structure

    Dim record As Person = New Person()
    Dim sr As StreamReader = New StreamReader(textfilename)

    While sr.Peek() > -1
    record.FName = Mid(sr.ReadLine, 3, 8)
    record.LName = Mid(sr.ReadLine, 11, 7)
    record.AddressLine1 = Mid(sr.ReadLine, 21, 21)
    End While

    sr.Close()


    I was attempting to write the XML file like this:

    Dim xtw As XmlTextWriter = New XmlTextWriter(xmlfilename, Nothing)

    With xtw
    .WriteStartDocument(False)
    .WriteStartElement("Person")
    .WriteElementString("FirstName", DP.FName)
    .WriteElementString("LastName", DP.LName)
    .WriteElementString("AddressLine1", DP.AddressLine1)
    .WriteEndElement()
    .Flush()
    .Close()
    End With

    I have a couple of problems. First, all that is being written to the xml file is the first name value and the xml tags. Secondly, I need to do this for a large text file. Can I read the entire file into memory and then write it?

    Any help would be appreciated.
    Last edited by Dman; Jul 28th, 2004 at 08:01 AM.
    A cynic knows the price of everything but the value of nothing.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width