473,698 Members | 2,404 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

XMLSerializatio n - 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>d ate time here</LogEntryDate>
</LogEntry>
....
<LogEntry>
<Stuffstuff here </Stuff>
<LogEntryDate>d ate time here</LogEntryDate>
</LogEntry>
Now, I'd like to use XMLSerializatio n, 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(t ypeof(MyClass)) ;
bool bAppend = true;

TextWriter writer = new StreamWriter(st rUsageLogFileNa me, bAppend );

ser.Serialize(w riter, this);

writer.Close();

Thanks for any tips,

Frank
Mar 5 '07 #1
1 3952
You want to serialize a Collection of objects.

Then , unforunately, you'll have to:

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

See some collection xml serialization at:

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


"Frank" <Fr***@yahoo.co mwrote 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>d ate time here</LogEntryDate>
</LogEntry>
...
<LogEntry>
<Stuffstuff here </Stuff>
<LogEntryDate>d ate time here</LogEntryDate>
</LogEntry>
Now, I'd like to use XMLSerializatio n, 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(t ypeof(MyClass)) ;
bool bAppend = true;

TextWriter writer = new StreamWriter(st rUsageLogFileNa me, bAppend );

ser.Serialize(w riter, 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
1445
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: Requests...Request (1..n)... Payload (1)... PayloadCollection (1) ... Payload (0...n) I have the knowledge about the root object Responses which I can create directly. However I don't know what is the type for Request and Payload (These will be versioned...
2
3594
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
1472
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 <itemsappend at the end of existing items at the old.xml. How can I do that? I am using php5 Thanks! Ofuuzo
1
3784
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 existing file name? Thanks Ofuuzo
0
8675
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8604
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9029
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8862
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7729
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6521
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5860
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4370
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
2331
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.