| | |
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 |
.net .net2008 30minutes 2005 2008 access account arithmetic array basic binary bing button buttons center check code combobox component connectionstring crystalreport data database databasesearch datagrid datagridview date design dissertation dissertations dropdownlist excel fade file-dialog filter folder ftp generatetags google hardcopy images input insert intel internet mobile monitor ms net networking objects output panel passingparameters peertopeervideostreaming picturebox picturebox1 port position print printing problem problemwithinstallation project save searchbox searchvb.net select serial shutdown soap survey table tcp temperature text textbox timer timespan toolbox trim update updown user vb vb.net vb.netcode vb.netformclosing()eventpictureboxmessagebox vb2008 vbnet view visual visualbasic visualbasic.net visualstudio visualstudio2008 web winforms wpf year






