Need Help TXT to XML Converter

Please support our VB.NET advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Sep 2009
Posts: 10
Reputation: ktkevin1222 is an unknown quantity at this point 
Solved Threads: 0
ktkevin1222 ktkevin1222 is offline Offline
Newbie Poster

Re: Need Help TXT to XML Converter

 
0
  #11
Sep 18th, 2009
Thing is my time varies in each line and I have hundreds of lines and lots of files. I uploaded an example so you can see exactly how many lines the file contains. Thank you for your support so far! I will add rep to you most likely when we have this worked out.
Attached Files
File Type: txt example.txt (37.8 KB, 3 views)
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 3,224
Reputation: sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of 
Solved Threads: 574
Sponsor
sknake's Avatar
sknake sknake is offline Offline
.NET Enthusiast

Re: Need Help TXT to XML Converter

 
0
  #12
Sep 19th, 2009
  1. Imports System.IO
  2. Imports System.Text
  3.  
  4. Public Class frmReadFile
  5.  
  6.  
  7. Private Shared Sub TxtToXML(ByVal inFile As String, ByVal outFile As String)
  8. Dim sr As New StreamReader(inFile)
  9.  
  10. Dim sb As New StringBuilder()
  11.  
  12. Do While sr.Peek() >= 0
  13. Dim line As String = sr.ReadLine()
  14. Dim fields() As String = line.Split(New [Char]() {","c}, System.StringSplitOptions.None)
  15.  
  16. sb.AppendLine("<CuePoint>")
  17. sb.AppendLine(" <Time>" & fields(0).Trim() & "</Time>")
  18. sb.AppendLine(" <Type>event</Type>")
  19. sb.AppendLine(" <Name>Marker " & fields(1).Trim() & "</Name>")
  20. sb.AppendLine(" <Parameters>")
  21. sb.AppendLine(" <Parameter>")
  22. sb.AppendLine(" <Name />")
  23. sb.AppendLine(" <Value>" & fields(2).Trim() & "</Value>")
  24. sb.AppendLine(" </Parameter>")
  25. sb.AppendLine(" </Parameters>")
  26. sb.AppendLine("</CuePoint>")
  27. Loop
  28.  
  29. sr.Close()
  30. sr.Dispose()
  31.  
  32. Dim result As String = sb.ToString()
  33. If (File.Exists(outFile)) Then
  34. File.Delete(outFile)
  35. End If
  36. File.WriteAllText(outFile, sb.ToString())
  37. End Sub
  38.  
  39. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  40. 'This is since I don't have your file. Change this to the path on YOUR machine
  41. TxtToXML("C:\dotnetwin\example.txt", "C:\dotnetwin\example.xml")
  42. MessageBox.Show("Done")
  43. End Sub
  44. End Class

It ran in under a second. Doesn't this do what you want?
Scott Knake
Custom Software Development
Apex Software, Inc.
Reply With Quote Quick reply to this message  
Join Date: Sep 2009
Posts: 10
Reputation: ktkevin1222 is an unknown quantity at this point 
Solved Threads: 0
ktkevin1222 ktkevin1222 is offline Offline
Newbie Poster

Re: Need Help TXT to XML Converter

 
0
  #13
Sep 19th, 2009
Thank you so much! (had to fix one thing in script and that was switch fields 0 and 2) I was looking to find a command that did what (& fields(0).Trim() &) does.

One last thing. During the conversion is it possible to make the thing change a line such as (" <Time>" & fields(2).Trim() & "</Time>") to go from 1.3107711 to 1310 (cut off 7711 and take out decimal)? I need this done for each time value.

I know what i typed may look confusing so if need be i can clarify.
Last edited by ktkevin1222; Sep 19th, 2009 at 6:03 pm.
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 3,224
Reputation: sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of 
Solved Threads: 574
Sponsor
sknake's Avatar
sknake sknake is offline Offline
.NET Enthusiast

Re: Need Help TXT to XML Converter

 
0
  #14
Sep 19th, 2009
decimal.Parse("1.3107711").ToString("F4") should do the trick
Scott Knake
Custom Software Development
Apex Software, Inc.
Reply With Quote Quick reply to this message  
Join Date: Sep 2009
Posts: 10
Reputation: ktkevin1222 is an unknown quantity at this point 
Solved Threads: 0
ktkevin1222 ktkevin1222 is offline Offline
Newbie Poster

Re: Need Help TXT to XML Converter

 
0
  #15
Sep 19th, 2009
Ok I understand what decimal.Parse will do and the i believe (F4) will only leave 4 numbers but is there anyway i can do this to every time value?
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 3,224
Reputation: sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of 
Solved Threads: 574
Sponsor
sknake's Avatar
sknake sknake is offline Offline
.NET Enthusiast

Re: Need Help TXT to XML Converter

 
0
  #16
Sep 19th, 2009
  1. sb.AppendLine(" <Time>" & decimal.Parse(fields(0).Trim()).ToString("F4") & "</Time>")
Scott Knake
Custom Software Development
Apex Software, Inc.
Reply With Quote Quick reply to this message  
Join Date: Sep 2009
Posts: 10
Reputation: ktkevin1222 is an unknown quantity at this point 
Solved Threads: 0
ktkevin1222 ktkevin1222 is offline Offline
Newbie Poster

Re: Need Help TXT to XML Converter

 
0
  #17
Sep 19th, 2009
That is almost what Im looking for. this last part I couldn't figure out. I need to have the same format except also get rid of the decimal. It seems obvious but i can't figure it out.

Also I need to convert 52.000000 to 0, 160.000000 to 1, and 271.000000 to 2. Haven't been able to do a convert or replace command correctly.
Last edited by ktkevin1222; Sep 19th, 2009 at 9:47 pm.
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 3,224
Reputation: sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of 
Solved Threads: 574
Sponsor
sknake's Avatar
sknake sknake is offline Offline
.NET Enthusiast

Re: Need Help TXT to XML Converter

 
0
  #18
Sep 20th, 2009
How are you doing the math here?
0-99 = 0
100-199 = 1
200-299 = 2 ?

If so:
  1. Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
  2. Dim lst As New List(Of String)
  3. lst.Add("52.000000")
  4. lst.Add("160.000000")
  5. lst.Add("271.000000")
  6. For Each s In lst
  7. Dim i1 As Integer = GetInteger(Decimal.Parse(s))
  8. Console.WriteLine("Original Value: {0}", s)
  9. Console.WriteLine("New Value: {0:F0}", i1)
  10. Next
  11. End Sub
  12.  
  13. Private Shared Function GetInteger(ByVal someDecimal As Decimal) As Integer
  14. If (someDecimal <= 0) Then
  15. Return 0
  16. End If
  17. Return Convert.ToInt32(Math.Floor(someDecimal / 100))
  18. End Function

Results in:
  1. Original Value: 52.000000
  2. New Value: 0
  3. Original Value: 160.000000
  4. New Value: 1
  5. Original Value: 271.000000
  6. New Value: 2
Scott Knake
Custom Software Development
Apex Software, Inc.
Reply With Quote Quick reply to this message  
Join Date: Sep 2009
Posts: 10
Reputation: ktkevin1222 is an unknown quantity at this point 
Solved Threads: 0
ktkevin1222 ktkevin1222 is offline Offline
Newbie Poster

Re: Need Help TXT to XML Converter

 
0
  #19
Sep 20th, 2009
well i don't know about the math that's just how the code comes out. I need the xml to have the replaced values though and I need the time to not have the decimal.
Last edited by ktkevin1222; Sep 20th, 2009 at 12:05 pm.
Reply With Quote Quick reply to this message  
Reply

Tags
text, txttoxmlconverter, vb2008, xml

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the VB.NET Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC