To read, edit and save an XML file you would use an XmlDocument object. You'd call the Load method to load a file and Save to save the modified data back to the file. In between you'd do whatever was necessary to edit the data as you required, e.g. call the AddNode method to add a node.
I'd suggest that you have a look at this first, then follow some of the links from here. If you still have trouble then post back, show us what you've done and tell us what you're having trouble with.
Dim doc As New XmlDocument
doc.Load("C:\Documents and Settings\p068612\Desktop\DVD.xml")
doc.GetElementsByTagName("DVDInfo")
doc.CreateElement("DVDTitle")
doc.InnerText = Me.txttitle.Text
doc is your XML document. You want to set your InnerText property of your element, not your entire XML document.
Dim doc As New XmlDocument
Dim elem1 As XmlElement = doc.CreateElement("DVDTitle")
Dim elem2 As XmlElement = doc.CreateElement("Director")
Dim elem3 As XmlElement = doc.CreateElement("Cast")
Dim elem4 As XmlElement = doc.CreateElement("Description")
Dim elem5 As XmlElement = doc.CreateElement("Rating")
Dim elem6 As XmlElement = doc.CreateElement("Cost")
Dim elem7 As XmlElement = doc.CreateElement("Copies")
Dim elem8 As XmlElement = doc.CreateElement("Rental")
Dim elem9 As XmlElement = doc.CreateElement("image")
Dim text1 As XmlText = doc.CreateTextNode(Me.txttitle.Text)
Dim text2 As XmlText = doc.CreateTextNode(Me.txtdirector.Text)
Dim text3 As XmlText = doc.CreateTextNode(Me.txtcast.Text)
Dim text4 As XmlText = doc.CreateTextNode(Me.txtdescription.Text)
Dim text5 As XmlText = doc.CreateTextNode(Me.txtrating.Text)
Dim text6 As XmlText = doc.CreateTextNode(Me.txtcost.Text)
Dim text7 As XmlText = doc.CreateTextNode(Me.txtcopies.Text)
Dim text8 As XmlText = doc.CreateTextNode(Me.txtRental.Text)
Dim text9 As XmlText = doc.CreateTextNode(Me.Txtimage.Text)
doc.Load("DVD.xml")
doc.GetElementsByTagName("DVDInfo")
doc.DocumentElement.AppendChild(elem1)
doc.DocumentElement.LastChild.AppendChild(text1)
doc.DocumentElement.AppendChild(elem2)
doc.DocumentElement.LastChild.AppendChild(text2)
doc.DocumentElement.AppendChild(elem3)
doc.DocumentElement.LastChild.AppendChild(text3)
doc.DocumentElement.AppendChild(elem4)
doc.DocumentElement.LastChild.AppendChild(text4)
doc.DocumentElement.AppendChild(elem5)
doc.DocumentElement.LastChild.AppendChild(text5)
doc.DocumentElement.AppendChild(elem6)
doc.DocumentElement.LastChild.AppendChild(text6)
doc.DocumentElement.AppendChild(elem7)
doc.DocumentElement.LastChild.AppendChild(text7)
doc.DocumentElement.AppendChild(elem8)
doc.DocumentElement.LastChild.AppendChild(text8)
doc.DocumentElement.AppendChild(elem9)
doc.DocumentElement.LastChild.AppendChild(text9)
doc.Save("DVD.xml")
It then starts adding your nodes to the DVDInfo node. But you have specified no DVD element. Create an XML node called <DVD>, and then append all your elemx and textx to that node, then add that node to your DVDInfo.
It then starts adding your nodes to the DVDInfo node. But you have specified no DVD element. Create an XML node called <DVD>, and then append all your elemx and textx to that node, then add that node to your DVDInfo.
Code:
Dim elem0 As XmlElement = doc.CreateElement("DVD")
I have created the <DVD> Node
But I don't understand where to put it in my code.