943,949 Members | Top Members by Rank

Ad:
  • VB.NET Discussion Thread
  • Unsolved
  • Views: 1533
  • VB.NET RSS
Dec 9th, 2008
0

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

Expand Post »
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..
Similar Threads
Reputation Points: 10
Solved Threads: 0
Light Poster
lerkei is offline Offline
36 posts
since Jan 2008
Dec 11th, 2008
0

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

This code may help:
VB Syntax (Toggle Plain Text)
  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.
Reputation Points: 27
Solved Threads: 0
Newbie Poster
NEo4 is offline Offline
10 posts
since Dec 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in VB.NET Forum Timeline: VB 2008 compile error
Next Thread in VB.NET Forum Timeline: complete records between two dates





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC