XMLSerialization - appending blocks to existing xml file

F

Frank

Hi,

Let's say I have a file named myFile.xml

Within that file I have blocks of data which I'd like to add at different
times during the day.

e.g.

<LogEntry>
<Stuff> stuff here </Stuff>
<LogEntryDate>date time here</LogEntryDate>
</LogEntry>
....
<LogEntry>
<Stuff> stuff here </Stuff>
<LogEntryDate>date time here</LogEntryDate>
</LogEntry>


Now, I'd like to use XMLSerialization, but when appending I get the <xml...>
line which I don't want after the first entry.

<?xml version="1.0" encoding="utf-8"?>

Is there a way to use XMLSerializer so that when appending, this line is not
added?

Here is my current code, which creates the file if it doesn't exist,
otherwise appends the next chunk of xml.

XmlSerializer ser = new XmlSerializer(typeof(MyClass));


bool bAppend = true;

TextWriter writer = new StreamWriter(strUsageLogFileName, bAppend );

ser.Serialize(writer, this);

writer.Close();



Thanks for any tips,

Frank
 
S

sloan

You want to serialize a Collection of objects.

Then , unforunately, you'll have to:

Unserialize the xml to the collection.
Collection.Add(new objectOfYourType);
Serialize and Save.

See some collection xml serialization at:

http://sholliday.spaces.live.com/blog/
9/21/2005
XmlSerialization with IDictionary and CollectionBase Objects
 

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

Members online

No members online now.

Forum statistics

Threads
473,997
Messages
2,570,240
Members
46,830
Latest member
HeleneMull

Latest Threads

Top