943,882 Members | Top Members by Rank

Ad:
  • VB.NET Discussion Thread
  • Unsolved
  • Views: 1075
  • VB.NET RSS
Jul 4th, 2009
0

Writing to an XML without overwriting data

Expand Post »
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.

vb.net Syntax (Toggle Plain Text)
  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.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Light Poster
Tamir09 is offline Offline
27 posts
since Feb 2009
Jul 5th, 2009
0

Re: Writing to an XML without overwriting data

Tamir09,
Quote ...
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?
Moderator
Reputation Points: 2136
Solved Threads: 1228
Posting Genius
adatapost is offline Offline
6,527 posts
since Oct 2008
Jul 5th, 2009
0

Re: Writing to an XML without overwriting data

I would prefer to modify my source code.
Reputation Points: 10
Solved Threads: 0
Light Poster
Tamir09 is offline Offline
27 posts
since Feb 2009
Jul 7th, 2009
0

Re: Writing to an XML without overwriting data

Any help would be appreciated...
Reputation Points: 10
Solved Threads: 0
Light Poster
Tamir09 is offline Offline
27 posts
since Feb 2009
Jul 7th, 2009
0

Re: Writing to an XML without overwriting data

Use DOM.
Moderator
Reputation Points: 2136
Solved Threads: 1228
Posting Genius
adatapost is offline Offline
6,527 posts
since Oct 2008
Jul 7th, 2009
0

Re: Writing to an XML without overwriting data

Click to Expand / Collapse  Quote originally posted by adatapost ...
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.
Reputation Points: 10
Solved Threads: 0
Light Poster
Tamir09 is offline Offline
27 posts
since Feb 2009
Jul 8th, 2009
0

Re: Writing to an XML without overwriting data

Document Object Model - a standard to work with XML document. See the System.XML namespace.

VB.NET Syntax (Toggle Plain Text)
  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
Moderator
Reputation Points: 2136
Solved Threads: 1228
Posting Genius
adatapost is offline Offline
6,527 posts
since Oct 2008
Jul 8th, 2009
0

Re: Writing to an XML without overwriting data

Thanks for the suggestions, but my question is how I can change my current code to allow for overwriting my xml data?
Reputation Points: 10
Solved Threads: 0
Light Poster
Tamir09 is offline Offline
27 posts
since Feb 2009

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: how to Access Module variable in ToolStripMenuItem_Click Event
Next Thread in VB.NET Forum Timeline: How do i use the keyboard in my code?





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


Follow us on Twitter


© 2011 DaniWeb® LLC