Help with updating xml

Help with updating xml

am 13.01.2008 15:44:25 von 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

Re: Help with updating xml

am 13.01.2008 16:15:48 von Martin Honnen

pauld wrote:

> 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(bar)
for the second line


--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/

Re: Help with updating xml

am 13.01.2008 16:29:29 von Martin Honnen

Martin Honnen wrote:

>> 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.

Here are links to the MSDN sections, DOM/XmlDocument is here:
,
LINQ/XDocument is here:


--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/