473,748 Members | 8,376 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to append records in exist XMl file?

Greetings

I want to append records in a XML file,I use XMLTextWriter,b ut i found it
only create a XML file,not append records in exist XML file.why?
-------------------------------------------------
XmlTextWriter myXmlTextWrite = new XmlTextWriter(@ "C:\myconfig.xm l");
myXmlTextWrite. WriteStartDocum ent();
myXmlTextWrite. WriteStartEleme nt("Record");
myXmlTextWrite. WriteStartEleme nt("Topic");
myXmlTextWrite. WriteString(XML Topic);
myXmlTextWrite. WriteEndElement ();
myXmlTextWrite. WriteEndElement (); //end Record
myXmlTextWrite. WriteEndDocumen t();
myXmlTextWrite. Flush();
myXmlTextWrite. Close();
=============== =============== =============== ====
i should use XMLDocument?
------------------------------
XmlDocument xmldoc= new XmlDocument();
xmldoc.Load(@"C :\myconfig.xml" );
xmldoc.Document Element.AppendC hild() //????????

Nov 12 '05 #1
2 12908
that's the whole idea (XmlTextWriter has to validate content as XML ...), so
using XmlDoxument makes sense ...
"Matrix" <co*****@163.co m> wrote in message
news:eE******** ********@TK2MSF TNGP10.phx.gbl. ..
Greetings

I want to append records in a XML file,I use XMLTextWriter,b ut i found it
only create a XML file,not append records in exist XML file.why?
-------------------------------------------------
XmlTextWriter myXmlTextWrite = new XmlTextWriter(@ "C:\myconfig.xm l");
myXmlTextWrite. WriteStartDocum ent();
myXmlTextWrite. WriteStartEleme nt("Record");
myXmlTextWrite. WriteStartEleme nt("Topic");
myXmlTextWrite. WriteString(XML Topic);
myXmlTextWrite. WriteEndElement ();
myXmlTextWrite. WriteEndElement (); //end Record
myXmlTextWrite. WriteEndDocumen t();
myXmlTextWrite. Flush();
myXmlTextWrite. Close();
=============== =============== =============== ====
i should use XMLDocument?
------------------------------
XmlDocument xmldoc= new XmlDocument();
xmldoc.Load(@"C :\myconfig.xml" );
xmldoc.Document Element.AppendC hild() //????????

Nov 12 '05 #2
Matrix wrote:
I want to append records in a XML file,I use XMLTextWriter,b ut i found it
only create a XML file,not append records in exist XML file.why?


XML document is tree-like structure, so to append records one has to
rearrange structure, what hardly possible in file on disk.
The only case when XmlWriter can append data to XML file is when it's
not XML document, but XML fragment (XML document with more than single
root element). That's common pattern for writing XML-based log files. As
there is no single root element rule, you can merely append records to
the end of file:

<log time="..." event="..."/>
<log time="..." event="..."/>
<log time="..." event="..."/>

Above is XML fragment, which is easily appendable and can be incpropated
into another document via external entity or just read using
XmlTextReader, which happily supports reading of XML fragments.
See sample at http://www.tkachenko.com/blog/archives/000053.html

--
Oleg Tkachenko [XML MVP, XmlInsider]
http://blog.tkachenko.com
Nov 12 '05 #3

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

Similar topics

3
23956
by: Jonathan Buckland | last post by:
Can someone give me an example how to append data without having to load the complete XML file. Is this possible? Jonathan
2
5784
by: JMCN | last post by:
hi i have a general question regarding append queries in access 97. each week i need to update my table(tblonlinereg) with new or modified records. firstly, i import the text file into my database and then i create a basic append query that appends the new records to the table(tblonlinereg). this works great if the field is greater than the last record appended ( where: tempID > 198 ) but how would i update/append the modifications...
3
2917
by: Larry Rekow | last post by:
As part of a macro, I'm trying to automate appending a table with new records. let's say the table 2 has some new records in it, but also has a lot of identical records to table 1. I would like to append table 1 with all of the new records, and do it unattended in a macro. Is there a way to specify in the append query to only append the
13
4229
by: Lee | last post by:
Hello All, First of all I would like to say thank you for all of the help I have received here. I have been teaching myself Access for about 4 years now and I've always been able to find a solution here - until now. This one is driving me crazy. I am making my first attempt at creating a runtime application. I am using Access 2003 Developer Extensions. Initially I developed the database without planning on creating a runtime app...
1
3036
by: Matrix | last post by:
I want to append records in a XML file,I use XMLTextWriter,but i found it only create a XML file,not append records in exist XML file.why? ------------------------------------------------- XmlTextWriter myXmlTextWrite = new XmlTextWriter(@"C:\myconfig.xml"); myXmlTextWrite.WriteStartDocument(); myXmlTextWrite.WriteStartElement("Record"); myXmlTextWrite.WriteStartElement("Topic"); myXmlTextWrite.WriteString(XMLTopic);...
5
2253
by: solar | last post by:
I have copied a function that appends from table orders2 into table orders1 the row that has the value SubOrder = True in the table orders2. This function finds the highest ordered in the table orders2. But I want to find the highest ordered in the table orders2 instead. In short, I want to append the order from the table orders2 into the table orders1 and this order to get the next highest ordered.Somehow I canot manage it.Can you help...
0
1095
by: RJN | last post by:
Hi I'm using XMlSerailizer to write certain content to file. If the file exists, I'm supposed to append the xml to the file. eg., <EmployeeList> <Employee></Employee> </EmployeeList>
4
7388
by: MN | last post by:
I have to import a tab-delimited text file daily into Access through a macro. All of the data needs to be added to an existing table. Some of the data already exists but may be updated by the imported text file. I can update the data through an update query or append the entire import table through an append query. Is there a way to combine the two so that I can update existing records and append only new records (without duplicating...
3
8075
by: wvmbark | last post by:
First time poster... I just found this forum and it appears there's plenty of people here that could make short work of problem that's been driving me absolutely bonkers for months. Every day we incur numerous service problems “Events”. Each morning we have a global conference call where events which occurred within the previous 24 hours are discussed. Prior to the call, an analyst has to review these events and provide a report, ‘The Morning...
0
8830
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
9541
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9247
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
8242
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
6796
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
6074
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
4874
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3312
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2782
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.