Private Sub btnAdd_Click(sender As Object, e As EventArgs) Handles btnAdd.Click Try If IO.File.Exists("contactlist.xml") Then Dim xmlDoc As New XmlDocument() xmlDoc.Load("contactlist.xml") Dim mainNode As XmlNode = xmlDoc.DocumentElement Dim newOp As XmlNode = xmlDoc.CreateElement("contact") 'Create elements and append them to the main document node' Dim subNode As XmlNode = xmlDoc.CreateElement("name") subNode.InnerText = txtName.Text newOp.AppendChild(subNode) subNode = xmlDoc.CreateElement("address") subNode.InnerText = txtAddress.Text newOp.AppendChild(subNode) subNode = xmlDoc.CreateElement("place") subNode.InnerText = txtPlace.Text newOp.AppendChild(subNode) subNode = xmlDoc.CreateElement("phone") subNode.InnerText = txtPhone.Text newOp.AppendChild(subNode) subNode = xmlDoc.CreateElement("email") subNode.InnerText = txtEmail.Text newOp.AppendChild(subNode) 'append child node to main node and save' mainNode.AppendChild(newOp) xmlDoc.Save("contactlist.xml") Else Dim XmlSet As New XmlWriterSettings() XmlSet.Indent = True ' Initialize the XmlWriter. Dim XmlWrite As XmlWriter = XmlWriter.Create("contactlist.xml", XmlSet) With XmlWrite ' create the XML file .WriteStartDocument() .WriteComment("XML Database.") .WriteStartElement("Contacts") .WriteStartElement("contact") ' write the tags and the entry into the tags .WriteStartElement("name") .WriteString(txtName.Text.ToString()) .WriteEndElement() .WriteStartElement("address") .WriteString(txtAddress.Text.ToString()) .WriteEndElement() .WriteStartElement("place") .WriteString(txtPlace.Text.ToString()) .WriteEndElement() .WriteStartElement("phone") .WriteString(txtPhone.Text.ToString()) .WriteEndElement() .WriteStartElement("email") .WriteString(txtEmail.Text.ToString()) .WriteEndElement() ' close entry .WriteEndElement() .WriteEndDocument() .Close() End With End If Catch ex As Exception MessageBox.Show(ex.Message) End Try
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)