Appending to XML files

C

Cat

How do you go about appending data from a dataset to an existing xml file? I
know you can use WriteXML but this writes over any data already existing in
the specified file..

Cat
 
H

Hans Kesting

Cat said:
How do you go about appending data from a dataset to an existing xml file? I
know you can use WriteXML but this writes over any data already existing in
the specified file..

Cat

I think the easiest way would be to read the file into an XmlDocument,
append the data where you want, and then write it out.
Due to the syntax of xml files you can't just "append" to the file without
violating the validity.

Hans Kesting
 
J

Jon Skeet [C# MVP]

Cat said:
How do you go about appending data from a dataset to an existing xml file? I
know you can use WriteXML but this writes over any data already existing in
the specified file..

Due to the nature of XML, you *can't* append data to an existing
(valid) document and end up with a new (valid) document - there can
only be one root element, and that *must* be closed to be a valid
document.

There are various ways of approaching the problems this causes, such as
creating many XML files which are periodically merged into a single
file containing all the same data.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top