473,407 Members | 2,314 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

XMLSerialization - appending blocks to existing xml file

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>
<Stuffstuff here </Stuff>
<LogEntryDate>date time here</LogEntryDate>
</LogEntry>
....
<LogEntry>
<Stuffstuff 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
Mar 5 '07 #1
1 3913
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" <Fr***@yahoo.comwrote in message
news:45***********************@roadrunner.com...
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>
<Stuffstuff here </Stuff>
<LogEntryDate>date time here</LogEntryDate>
</LogEntry>
...
<LogEntry>
<Stuffstuff 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


Mar 6 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: raca | last post by:
I am trying to create a generic SOA ServiceInvoker that will accept an XML string that will be used to deserialize an object generated by XSDObjectGen. The hierarchy goes like this:...
2
by: Cat | last post by:
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
1
by: ofuuzo1 | last post by:
Hei, I am having issue using DOM to appending a new xml file (new.xml) to another existing xml file (old.xml) without deleting the existing items in old.xml. I would like to have the new...
1
by: ofuuzo1 | last post by:
Hi, Is there anyway I can append a new element to an existing xml without first loading the existing file into a variable, adding the new element into the variable and saving it by overwriting the...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.