add data to an existing xml file


/ Published in: VB.NET
Save to your folder(s)

This code snippet is used to add data to an existing xml file


Copy this code and paste it in your HTML
  1. Dim xmlfile As New ConfigXmlDocument
  2. 'loading our xmal
  3. xmlfile.Load(Server.MapPath("~/app_data/winners.xml"))
  4. 'creating tages
  5. Dim theWinnersTag As XmlElement = xmlfile.CreateElement("winners")
  6. Dim theWinnerTag As XmlElement = xmlfile.CreateElement("winner")
  7. Dim theNameTag As XmlElement = xmlfile.CreateElement("name")
  8. Dim theEmailTag As XmlElement = xmlfile.CreateElement("email")
  9. Dim theTelTag As XmlElement = xmlfile.CreateElement("tel")
  10. Dim theqnoTag As XmlElement = xmlfile.CreateElement("qno")
  11.  
  12. 'create informaiton that goes into the tages
  13. Dim theNameText As XmlText = xmlfile.CreateTextNode(lblwinner_name.Text)
  14. Dim theEmailText As XmlText = xmlfile.CreateTextNode(lblwinner_email.Text)
  15. Dim theTelText As XmlText = xmlfile.CreateTextNode(lblwinner_tel.Text)
  16. Dim theqnoText As XmlText = xmlfile.CreateTextNode(lblwinner_qno.Text)
  17.  
  18. 'append the textnode to elements tages
  19. theNameTag.AppendChild(theNameText)
  20. theEmailTag.AppendChild(theEmailText)
  21. theTelTag.AppendChild(theTelText)
  22. theqnoTag.AppendChild(theqnoText)
  23.  
  24. 'appent all the information to the winners tage
  25. theWinnerTag.AppendChild(theNameTag)
  26. theWinnerTag.AppendChild(theEmailTag)
  27. theWinnerTag.AppendChild(theTelTag)
  28. theWinnerTag.AppendChild(theqnoTag)
  29.  
  30. 'now we are going to add thewinnerstag to the document element which is the root element (winnners)
  31. xmlfile.DocumentElement.AppendChild(theWinnerTag)
  32.  
  33. 'now we are going to save the xml file
  34. xmlfile.Save(Server.MapPath("~/app_data/winners.xml"))

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.