Results 1 to 2 of 2

Thread: VB.NET: Append string to Xml file

Threaded View

  1. #1

    Thread Starter
    Addicted Member toytoy's Avatar
    Join Date
    Jul 2004
    Posts
    230

    VB.NET: Append string to Xml file

    Hi

    Say i receive one string full of Xml tags ...

    Example: "<Person>John</Person><Item>Pen</Item><Amount>4</Amount>"


    How to save and append these tags to my xml files..

    They told me to use appendChild method.. maybe i am not quite sure with string....... i save the string two times instead..
    I am using VB.NET....
    Code:
     Dim myDoc As New Xml.XmlDocument
     Dim myXml As String
      myXml = "<Person>John</Person><Item>Pen</Item> _  
     <Amount>4</Amount>
    
      myDoc.LoadXml(myXml)
    
      Dim root As XmlNode = myDoc.DocumentElement
    
      Dim person As XmlElement = myDoc.CreateElement("Person")
      person.InnerText = John
    
      Dim itemy As XmlElement = myDoc.CreateElement("Item")
      item.InnerText = pen
    
      Dim amount As XmlElement = myDoc.CreateElement("Amount")
      amount.InnerText = 4
    
      root.AppendChild(person)
      root.AppendChild(item) 
      root.AppendChild(amount)
      myDoc.Save("1.xml")
    How to solve this so that it will append to the xml whenever i receive a string...

    Thanks.
    Last edited by toytoy; Dec 3rd, 2004 at 08:15 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width