| | |
Writing to an XML without overwriting data
Please support our VB.NET advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Feb 2009
Posts: 27
Reputation:
Solved Threads: 0
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.
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.
vb.net Syntax (Toggle Plain Text)
ElseIf ComboBox1.Text = "Turbine Data" Then 'start of first combo box code Dim filepath As String = My.Application.Info.DirectoryPath & turbdatxml If Dir(filepath) <> "" Then If (TextBox1.Text.Equals("") Or TextBox2.Text.Equals("") Or TextBox3.Text.Equals("") Or TextBox4.Text.Equals("")) Then MsgBox(val_txt, , inval_title) Else Dim ExistingData As New MyDatum Dim Serializer As New System.Xml.Serialization.XmlSerializer(GetType(MyDatum)) If (File.Exists(filepath)) Then '& Not EOF(1) 'Need to find out how to check End of File, and skip this bit of code if file is empty Dim OpenStream As System.IO.FileStream = System.IO.File.Open(filepath, IO.FileMode.Open) 'Protects existing data, to make a list, rather than overwriting data. ExistingData = Serializer.Deserialize(OpenStream) OpenStream.Close() Else MsgBox(cre05, , err05) End If Dim NewData As New MyData TextBox1.Focus() NewData.DateStamp = CDate(Date.Today()) 'DateValue(Now) NewData.TimeStamp = CDate(TimeString()) 'find out how to display the date and time seperate, not as a stamp NewData.Gap = gaptext.Text NewData.Diameter = diatext.Text NewData.R2 = TextBox1.Text NewData.VentDiamater = TextBox2.Text NewData.R1 = TextBox3.Text NewData.Height = TextBox4.Text ExistingData.Add(NewData) Dim SaveStream As System.IO.FileStream = System.IO.File.Open(filepath, IO.FileMode.Open) ' IO.FileMode.Create or .Open Serializer.Serialize(SaveStream, ExistingData) SaveStream.Close() MsgBox("Data Saved to " & filepath, , _save) End If Else MsgBox(cre05, , err05) Dim ExistingData As New MyDatum Dim Serializer As New System.Xml.Serialization.XmlSerializer(GetType(MyDatum)) Dim NewData As New MyData Dim SaveStream As System.IO.FileStream = System.IO.File.Open(filepath, IO.FileMode.Create) TextBox1.Focus() NewData.DateStamp = CDate(Date.Today()) 'DateValue(Now) NewData.TimeStamp = CDate(TimeString()) NewData.Gap = gaptext.Text NewData.Diameter = diatext.Text NewData.R2 = TextBox1.Text NewData.VentDiamater = TextBox2.Text NewData.R1 = TextBox3.Text NewData.Height = TextBox4.Text Serializer.Serialize(SaveStream, ExistingData) SaveStream.Close() End If '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.
Tamir09,
Do you want to modify the XML document or your source 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.
Failure is not fatal, but failure to change might be. - John Wooden
Document Object Model - a standard to work with XML document. See the System.XML namespace.
VB.NET Syntax (Toggle Plain Text)
Dim doc as New System.Xml.XmlDocument() doc.Load("file.xml") 'Load an XML document ... ... doc.Save("file.xml") 'Save the document
Failure is not fatal, but failure to change might be. - John Wooden
![]() |
Similar Threads
- data to be displayed in xml (PHP)
- Reading and writing to XML file with ActionScript (IT Professionals' Lounge)
- Reading and writing to XML file with ActionScript (Graphics and Multimedia)
- Help with Reading/Editing/Writing XML data in .NET (XML, XSLT and XPATH)
- Display xml data in message box (VB.NET)
- Writing mp3 files to data files (OS X)
- Listview Data to XML or file (VB.NET)
- XML and hyperlink as one of the data (RSS, Web Services and SOAP)
Other Threads in the VB.NET Forum
- Previous Thread: how to Access Module variable in ToolStripMenuItem_Click Event
- Next Thread: How do i use the keyboard in my code?
| Thread Tools | Search this Thread |
"crystal .net .net2005 30minutes 2008 access add application arithmetic array assignment basic binary box button buttons center click code combo combobox component connectionstring convert cpu data database databasesearch datagrid datagridview design dissertation dissertations dissertationthesis dosconsolevb.net editvb.net employees excel exists firewall folder image images isnumericfuntioncall login math memory mobile module ms msaccess mssqlbackend mysql navigate net opacity pan peertopeervideostreaming picturebox picturebox1 port print printpreview problemwithinstallation project record regex reports" reuse right-to-left save savedialog search serial sorting sqldatbase storedprocedure string temp textbox timer txttoxmlconverter updown useraccounts usercontol usercontrol vb vb.net vb.netcode vb.nettoolboxvisualbasic2008sidebar vbnet view vista visual visualbasic visualbasic.net visualstudio web wpf xml






