Help with updating xml

  • Thread starter Thread starter pauld
  • Start date Start date
P

pauld

Hello -

I have found on freevbcode.com a way to easily read and write to an
xml file via a web form. The URL for this code is
http://www.freevbcode.com/ShowCode.Asp?ID=2789

The only problem I have is that the xml file is overwritten instead of
being appended...is there anyone who can help me fix this so that the
entry is added to the top of the xml instead of replacing the whole
thing?

Thanks so much...

PaulD
 
pauld said:
I have found on freevbcode.com a way to easily read and write to an
xml file via a web form. The URL for this code is
http://www.freevbcode.com/ShowCode.Asp?ID=2789

The only problem I have is that the xml file is overwritten instead of
being appended...is there anyone who can help me fix this so that the
entry is added to the top of the xml instead of replacing the whole
thing?

Use System.Xml.XmlDocument to edit XML documents, or
System.Xml.Linq.XDocument if you have Visual Studio 2008.
With XmlDocument you use it as follows e.g.
Dim doc As New XmlDocument()
doc.Load("file.xml")
Dim foo = doc.CreateElement("foo")
foo.InnerText = "bar"
doc.DocumentElement.InsertBefore(foo, doc.DocumentElement.FirstChild)
doc.Save("file.xml")
With XDocument you use e.g.
Dim doc As XDocument = XDocument.Load("file.xml")
doc.Root.AddFirst(New XElement("foo", "bar"))
doc.Save("file.xml")
or with XML literals you could also use
doc.Root.AddFirst(<foo>bar</foo>)
for the second line
 
Back
Top