Click here to Skip to main content
15,867,330 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I'm pretty new, I was wondering how I can add new elements to my code instead of constantly changing the same one. My code just allows me to edit the same element instead of being able to make a new element. My goal is making a contacts application using xml but I'm unsure on how to do it.

What I have tried:

VB
Private Sub btnAdd_Click(sender As Object, e As EventArgs) Handles btnAdd.Click
        Dim xWriter As XmlWriterSettings = New XmlWriterSettings()
        
        xWriter.Indent = True
        
        Dim xw As XmlWriter = XmlWriter.Create("contactlist.xml", xWriter)
        

        xw.WriteStartDocument()
        

        xw.WriteStartElement("contacts")
       

        xw.WriteStartElement(txtName.Text)
        
        xw.WriteElementString("name", txtName.Text)
       
        xw.WriteElementString("address", txtAddress.Text)
        
        xw.WriteElementString("place", txtPlace.Text)
        
        xw.WriteElementString("phone", txtPhone.Text)
        
        xw.WriteElementString("email", txtEmail.Text)
        
        xw.WriteEndElement()
        

        xw.WriteEndElement()
        
        xw.WriteEndDocument()
        

        xw.Flush()
        
        xw.Close()
Posted
Updated 15-Jun-21 20:20pm
v3
Comments
Richard Deeming 16-Jun-21 4:33am    
I strongly recommend you change your username if you want to be taken seriously. Currently you look like either an immature child, or a troll.

If I understand the situation correctly, I think it would be easier to work with XmlDocument rather than using a XmlWriter to write the content.

With XmlDocument you can create/modify/delete the content and when needed you can save or load the document to disk.

For more information, have a look at XmlDocument Class (System.Xml) | Microsoft Docs[^]
 
Share this answer
 
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900