Writing to an XML without overwriting data

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

Join Date: Feb 2009
Posts: 27
Reputation: Tamir09 is an unknown quantity at this point 
Solved Threads: 0
Tamir09 Tamir09 is offline Offline
Light Poster

Writing to an XML without overwriting data

 
0
  #1
Jul 4th, 2009
Ive managed so far with this code that amends data to an xml form, but I need to figure out how to remove the bit of code that amends data rather than overwriting it. Ive messed around with the code to see if I could manipulate it myself to get be able to overwrite data, but I havent been able to, so I ask for help.

  1. ElseIf ComboBox1.Text = "Turbine Data" Then
  2. 'start of first combo box code
  3. Dim filepath As String = My.Application.Info.DirectoryPath & turbdatxml
  4.  
  5. If Dir(filepath) <> "" Then
  6.  
  7. If (TextBox1.Text.Equals("") Or TextBox2.Text.Equals("") Or TextBox3.Text.Equals("") Or TextBox4.Text.Equals("")) Then
  8.  
  9. MsgBox(val_txt, , inval_title)
  10.  
  11. Else
  12. Dim ExistingData As New MyDatum
  13.  
  14. Dim Serializer As New System.Xml.Serialization.XmlSerializer(GetType(MyDatum))
  15.  
  16. If (File.Exists(filepath)) Then '& Not EOF(1)
  17.  
  18. 'Need to find out how to check End of File, and skip this bit of code if file is empty
  19.  
  20. Dim OpenStream As System.IO.FileStream = System.IO.File.Open(filepath, IO.FileMode.Open)
  21.  
  22. 'Protects existing data, to make a list, rather than overwriting data.
  23. ExistingData = Serializer.Deserialize(OpenStream)
  24.  
  25. OpenStream.Close()
  26. Else
  27.  
  28. MsgBox(cre05, , err05)
  29.  
  30. End If
  31.  
  32. Dim NewData As New MyData
  33.  
  34. TextBox1.Focus()
  35. NewData.DateStamp = CDate(Date.Today()) 'DateValue(Now)
  36. NewData.TimeStamp = CDate(TimeString())
  37. 'find out how to display the date and time seperate, not as a stamp
  38. NewData.Gap = gaptext.Text
  39. NewData.Diameter = diatext.Text
  40. NewData.R2 = TextBox1.Text
  41. NewData.VentDiamater = TextBox2.Text
  42. NewData.R1 = TextBox3.Text
  43. NewData.Height = TextBox4.Text
  44.  
  45. ExistingData.Add(NewData)
  46.  
  47. Dim SaveStream As System.IO.FileStream = System.IO.File.Open(filepath, IO.FileMode.Open)
  48. ' IO.FileMode.Create or .Open
  49.  
  50. Serializer.Serialize(SaveStream, ExistingData)
  51.  
  52. SaveStream.Close()
  53.  
  54. MsgBox("Data Saved to " & filepath, , _save)
  55.  
  56. End If
  57.  
  58. Else
  59.  
  60. MsgBox(cre05, , err05)
  61.  
  62. Dim ExistingData As New MyDatum
  63. Dim Serializer As New System.Xml.Serialization.XmlSerializer(GetType(MyDatum))
  64. Dim NewData As New MyData
  65. Dim SaveStream As System.IO.FileStream = System.IO.File.Open(filepath, IO.FileMode.Create)
  66.  
  67. TextBox1.Focus()
  68. NewData.DateStamp = CDate(Date.Today()) 'DateValue(Now)
  69. NewData.TimeStamp = CDate(TimeString())
  70. NewData.Gap = gaptext.Text
  71. NewData.Diameter = diatext.Text
  72. NewData.R2 = TextBox1.Text
  73. NewData.VentDiamater = TextBox2.Text
  74. NewData.R1 = TextBox3.Text
  75. NewData.Height = TextBox4.Text
  76.  
  77. Serializer.Serialize(SaveStream, ExistingData)
  78. SaveStream.Close()
  79. End If
  80. 'End of first combo box code

I need to keep with this original code as far as the serializing of the data is concerned, I just need to remove the 'ExistingData' component from the code, and still be able to write data to the xml.
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 2,612
Reputation: adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of 
Solved Threads: 463
Moderator
adatapost's Avatar
adatapost adatapost is offline Offline
Posting Maven

Re: Writing to an XML without overwriting data

 
0
  #2
Jul 5th, 2009
Tamir09,
I need to keep with this original code as far as the serializing of the data is concerned, I just need to remove the 'ExistingData' component from the code, and still be able to write data to the xml.
Do you want to modify the XML document or your source code?
Failure is not fatal, but failure to change might be. - John Wooden
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 27
Reputation: Tamir09 is an unknown quantity at this point 
Solved Threads: 0
Tamir09 Tamir09 is offline Offline
Light Poster

Re: Writing to an XML without overwriting data

 
0
  #3
Jul 5th, 2009
I would prefer to modify my source code.
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 27
Reputation: Tamir09 is an unknown quantity at this point 
Solved Threads: 0
Tamir09 Tamir09 is offline Offline
Light Poster

Re: Writing to an XML without overwriting data

 
0
  #4
Jul 7th, 2009
Any help would be appreciated...
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 2,612
Reputation: adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of 
Solved Threads: 463
Moderator
adatapost's Avatar
adatapost adatapost is offline Offline
Posting Maven

Re: Writing to an XML without overwriting data

 
0
  #5
Jul 7th, 2009
Use DOM.
Failure is not fatal, but failure to change might be. - John Wooden
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 27
Reputation: Tamir09 is an unknown quantity at this point 
Solved Threads: 0
Tamir09 Tamir09 is offline Offline
Light Poster

Re: Writing to an XML without overwriting data

 
0
  #6
Jul 7th, 2009
Originally Posted by adatapost View Post
Use DOM.
What is DOM? And how will I be able to apply that to my code?
Last edited by Tamir09; Jul 7th, 2009 at 11:49 pm.
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 2,612
Reputation: adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of 
Solved Threads: 463
Moderator
adatapost's Avatar
adatapost adatapost is offline Offline
Posting Maven

Re: Writing to an XML without overwriting data

 
0
  #7
Jul 8th, 2009
Document Object Model - a standard to work with XML document. See the System.XML namespace.

  1. Dim doc as New System.Xml.XmlDocument()
  2. doc.Load("file.xml") 'Load an XML document
  3. ...
  4. ...
  5. doc.Save("file.xml") 'Save the document
Failure is not fatal, but failure to change might be. - John Wooden
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 27
Reputation: Tamir09 is an unknown quantity at this point 
Solved Threads: 0
Tamir09 Tamir09 is offline Offline
Light Poster

Re: Writing to an XML without overwriting data

 
0
  #8
Jul 8th, 2009
Thanks for the suggestions, but my question is how I can change my current code to allow for overwriting my xml data?
Reply With Quote Quick reply to this message  
Reply

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


Thread Tools Search this Thread



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

©2003 - 2009 DaniWeb® LLC