Results 1 to 3 of 3

Thread: test file to xml conversion

  1. #1

    Thread Starter
    New Member
    Join Date
    Feb 2004
    Posts
    4

    test file to xml conversion

    Hello,

    I have just purchased a version of visual basic .net and I am trying to write a vb program that will read in a pipe delimted text file and create an xml page.

    The text file is very simple and is delimited with the pipe symbol.

    The file contains......

    123abc | £235,000
    456def | £345,000
    I would like to produce the following xml sheet from it.

    <properties>
    <property>
    <property_id>abc123</property_id>
    <price>£235,000</price>
    </property>
    <property>
    <property_id>345def</property_id>
    <price>£345,000</price>
    </property>
    </properties>

    If somoene out there has done something like this before and could supply the basic code I could then learn from that and improve on it.

    Many thanks

  2. #2
    Fanatic Member
    Join Date
    Oct 2000
    Location
    Reading, UK
    Posts
    870
    read your text file into a dataset and then you can directly save the dataset as an xml file.

    Nick
    www.vb-tech.com
    .Net Freelance Development
    http://weblog.vb-tech.com/nick
    My blog

  3. #3
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    That's one way . nswan's idea would be even better and faster . However , you might need this code in either ways .

    VB Code:
    1. Sub ReadFile()
    2.         Dim sr As New IO.StreamReader("c:\test.txt")
    3.         While sr.Peek >= 0
    4.             Dim content As String = sr.ReadLine
    5.             Dim contents() As String = content.Split("|".ToCharArray)
    6.             For Each s As String In contents
    7.                 MessageBox.Show(s)
    8.                 'You formatting function here
    9.             Next
    10.  
    11.         End While
    12.     End Sub

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