Return to Snippet

Revision: 48825
at July 11, 2011 06:42 by tabook22


Initial Code
Dim xmlfile As New ConfigXmlDocument
        'loading our xmal
        xmlfile.Load(Server.MapPath("~/app_data/winners.xml"))
        'creating tages
        Dim theWinnersTag As XmlElement = xmlfile.CreateElement("winners")
        Dim theWinnerTag As XmlElement = xmlfile.CreateElement("winner")
        Dim theNameTag As XmlElement = xmlfile.CreateElement("name")
        Dim theEmailTag As XmlElement = xmlfile.CreateElement("email")
        Dim theTelTag As XmlElement = xmlfile.CreateElement("tel")
        Dim theqnoTag As XmlElement = xmlfile.CreateElement("qno")

        'create informaiton that goes into the tages
        Dim theNameText As XmlText = xmlfile.CreateTextNode(lblwinner_name.Text)
        Dim theEmailText As XmlText = xmlfile.CreateTextNode(lblwinner_email.Text)
        Dim theTelText As XmlText = xmlfile.CreateTextNode(lblwinner_tel.Text)
        Dim theqnoText As XmlText = xmlfile.CreateTextNode(lblwinner_qno.Text)

        'append the textnode to elements tages
        theNameTag.AppendChild(theNameText)
        theEmailTag.AppendChild(theEmailText)
        theTelTag.AppendChild(theTelText)
        theqnoTag.AppendChild(theqnoText)

        'appent all the information to the winners tage
        theWinnerTag.AppendChild(theNameTag)
        theWinnerTag.AppendChild(theEmailTag)
        theWinnerTag.AppendChild(theTelTag)
        theWinnerTag.AppendChild(theqnoTag)

        'now we are going to add thewinnerstag to the document element which is the root element (winnners)
        xmlfile.DocumentElement.AppendChild(theWinnerTag)

        'now we are going to save the xml file
        xmlfile.Save(Server.MapPath("~/app_data/winners.xml"))

Initial URL

                                

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

Initial Title
add data to an existing xml file

Initial Tags
xml, aspnet

Initial Language
VB.NET