| | |
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.
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
![]() |
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?
Views: 420 | Replies: 7
| Thread Tools | Search this Thread |
Tag cloud for VB.NET
.net .net2008 2005 2008 access account application array arrays basic bing button buttons c# center check checkbox code convert crystalreport data database datagrid datagridview date design designer dissertation dissertations dropdownlist excel fade file-dialog filter ftp generatetags google gridview hardcopy images inline input insert installer intel internet listview mobile monitor net networking objects output panel passingparameters picturebox port position print printing problem read remove save searchbox searchvb.net select serial shutdown soap sorting studio survey table tcp temperature text textbox time timer timespan toolbox trim update user validation vb vb.net vb.netformclosing()eventpictureboxmessagebox vb2008 vbnet visual visualbasic visualbasic.net visualstudio2008 web webbrowser winforms wpf year






