Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > XMLSerialization - appending blocks to existing xml file

Reply
Thread Tools

XMLSerialization - appending blocks to existing xml file

 
 
Frank
Guest
Posts: n/a
 
      03-05-2007
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


 
Reply With Quote
 
 
 
 
sloan
Guest
Posts: n/a
 
      03-06-2007
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




"Frank" <> wrote in message
news:45eca789$0$27061$...
> 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
>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
appending a new element to an existing xml file ofuuzo1@yahoo.no XML 8 03-07-2008 11:31 AM
XmlSerialization Problem =?Utf-8?B?UmFlZCBTYXdhbGhh?= ASP .Net 0 11-28-2004 02:51 PM
XMLSerialization: Sometimes csc.exe freezes on the PermissionSet =?Utf-8?B?QSBwcm9ncmFtbWVyIGRlc3BlcmF0bHkgbmVlZGluZyBoZWxwIQ==?= ASP .Net 0 11-18-2004 11:28 AM
procs/blocks - blocks with procs, blocks with blocks? matt Ruby 1 08-06-2004 01:33 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57