reading a specific data in .txt file to put in specific tag in xml in vb.net

Reply

Join Date: Jan 2008
Posts: 36
Reputation: lerkei is an unknown quantity at this point 
Solved Threads: 0
lerkei lerkei is offline Offline
Light Poster

reading a specific data in .txt file to put in specific tag in xml in vb.net

 
0
  #1
Dec 9th, 2008
reading a specific data in .txt file to put in specific tag in xml in vb.net..pls help..

sample: BL% PHP 103025 and so on...
NL%
..
..

BL% and NL% are indicators where data should be placed in a specific segment in xml
PHP must be placed inside <currency></currency> tag..
103025 must be placed inside <amount></amount> tag..
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
Posts: 10
Reputation: NEo4 is an unknown quantity at this point 
Solved Threads: 0
NEo4 NEo4 is offline Offline
Newbie Poster

Re: reading a specific data in .txt file to put in specific tag in xml in vb.net

 
0
  #2
Dec 11th, 2008
This code may help:
  1. Private Sub Form1_Load(ByVal sender As System.Object, _
  2. ByVal e As System.EventArgs) _
  3. Handles MyBase.Load
  4. Dim filename As String = "afile.txt" ' Your file name/path
  5. Dim filereader As New System.IO.StreamReader(filename) ' Open the file for reading
  6. Dim readline As String
  7. Dim data As String
  8. Dim dataparts(1) As String
  9.  
  10. While Not filereader.EndOfStream
  11. readline = filereader.ReadLine ' Reads a line from the text file
  12.  
  13. Select Case readline.Substring(0, 3) ' Reads the first 3 Characters of the line
  14. Case "BL%"
  15. data = readline.Substring(4) ' Reads the data in front of 'BL%'
  16. dataparts = data.Split(" ") ' Breaks the data into two and store them in the dataparts array
  17. ' Add your codes for writing the data to the XML file in the 'BL%' segment between the currency and amount tag here
  18.  
  19. Case "NL%"
  20. data = readline.Substring(4)
  21. dataparts = data.Split(" ")
  22. ' Add your codes for writing the data to the XML file in the 'NL%' segment here
  23. End Select
  24. End While
  25.  
  26. End Sub

I am assuming that you already know how to add the data to XML file(if you don't, you may learn it here) and that the data from text file you are reading from is stored in this way:
BL% PHP 103025
NL% Tag1 Tag2
Last edited by NEo4; Dec 11th, 2008 at 4:00 am.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the VB.NET Forum


Views: 1011 | Replies: 1
Thread Tools Search this Thread



Tag cloud for VB.NET
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2010 DaniWeb® LLC