473,659 Members | 2,540 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Appending Node to Large XML File

I have a large XML file, that is too large to read in to XmlDocument.

I need to append data to this XML file without creating a new file, since I
don't want to have two copies of the large file on the server.

I've not seen any example that works so far, even with google. Can anyone
help ?
Nov 12 '05 #1
1 2449
Hi Jonathan,

You can use XmlTextReader and XmlTextWriter. They're very fast. You can
programmaticall y delete the old file if you don't want to keep two large
files.

To start you can read through some documentations here:
http://msdn.microsoft.com/library/de...us/cpref/html/
frlrfsystemxmlx mltextwritercla sstopic.asp
http://msdn.microsoft.com/library/de...us/cpref/html/
frlrfsystemxmlx mltextreadercla ssnodetypetopic .asp
http://msdn.microsoft.com/library/de...us/cpref/html/
frlrfsystemxmlx mltextwritercla sstopic.asp

The following are some sample code:

//reader the Large Xml file using XmlTextReader
XmlTextReader reader = new XmlTextReader(@ "C:\Test\LargeX mlFile.xml");

//XmlTextWriter to write Large XML File
XmlTextWriter cdocWriter = new
XmlTextWriter(@ "C:\Test\LargeX mlFile_New.xml" , Encoding.UTF8);

writer.Formatti ng = Formatting.Inde nted;

writer.WriteSta rtDocument();

// Read the file and display each of the nodes.
while (reader.Read())
{
switch (reader.NodeTyp e)
{
case XmlNodeType.Ele ment:
writer.WriteSta rtElement(reade r.Name);
writer.WriteAtt ributes(reader, false);
if (reader.IsEmpty Element)
writer.WriteEnd Element();
break;
//You can have some test statement here to append nodes
if (reader.Name == "????")
{
//TODO: do something
}
case XmlNodeType.Tex t:
writer.WriteStr ing(reader.Valu e);
break;
case XmlNodeType.Whi tespace:
case XmlNodeType.Sig nificantWhitesp ace:
writer.WriteWhi tespace(reader. Value);
break;
case XmlNodeType.CDA TA:
writer.WriteCDa ta(reader.Value );
break;
case XmlNodeType.Com ment:
writer.WriteCom ment(reader.Val ue);
break;
case XmlNodeType.Ent ityReference:
writer.WriteEnt ityRef(reader.N ame);
break;
case XmlNodeType.End Element:
//You can have some test statement here to append nodes
if (reader.Name == "????")
{
//TODO: do something
}

writer.WriteEnd Element();
break;
}
}

writer.WriteEnd Document();
writer.Flush();
writer.Close();
reader.Close();

Hope this helps!
--
Yingzi Le
LongHorn SDK Team

This posting is provided "AS IS" with no warranties, and confers no rights.

--------------------
From: "Jonathan Taylor" <jo****@0000000 0homtail.com>
Subject: Appending Node to Large XML File
Date: Fri, 20 May 2005 13:18:24 +0100
Lines: 9
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2900.2527
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2527
X-RFC2646: Format=Flowed; Original
Message-ID: <#6************ **@TK2MSFTNGP10 .phx.gbl>
Newsgroups: microsoft.publi c.dotnet.xml
NNTP-Posting-Host: 82-41-12-138.cable.ubr02 .edin.blueyonde r.co.uk 82.41.12.138Path: TK2MSFTNGXA01.p hx.gbl!TK2MSFTN GP08.phx.gbl!TK 2MSFTNGP10.phx. gbl
Xref: TK2MSFTNGXA01.p hx.gbl microsoft.publi c.dotnet.xml:71 23
X-Tomcat-NG: microsoft.publi c.dotnet.xml

I have a large XML file, that is too large to read in to XmlDocument.

I need to append data to this XML file without creating a new file, since Idon't want to have two copies of the large file on the server.

I've not seen any example that works so far, even with google. Can anyone
help ?


Nov 12 '05 #2

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

Similar topics

2
3059
by: jimmyfishbean | last post by:
Hi, I am using VB6, SAX (implementing IVBSAXContentHandler). I need to extract binary encoded data (images) from large XML files and decode this data and generate the appropriate images onto disk. My XML files have the following structure: <?xml version="1.0" encoding="utf-8" ?> <imagepla xmlns:dt="urn:schemas-microsoft-com:datatypes">
1
4236
by: Novice | last post by:
Hey all, I've read a few articles about speed and XML processing - so I just want to make sure that I'm using the right strategy for what I want to achieve. I have an XML file that I'm appending to every time a user submits their information. Right now I'm using XMLDocument (Load and Save) in conjuncture with XmlElement objects.
17
1827
by: Grant Austin | last post by:
I have a linked list where each node holds a couple numbers a char and a const char array. I use strcpy to take an char array argument passed to my insert function to copy the string into the new node. To some of these entries 0a(line feed?) is being appended. I've looked through the faq and googled but haven't found much info that applies. The code follows this post(in a bit I'll split it into multiple
4
18174
by: Jesper Stocholm | last post by:
I have a database class that maintains data about customers i my system. The basic XML for this looks like: <Chunk> <Vendor> <Database/> </Vendor> </Chunk> When a user is to be registrered in the system, XML like this is created
2
2240
by: tony.collings | last post by:
I started a thread here : http://groups.google.co.uk/group/microsoft.public.cmserver.general/browse_thread/thread/29d63077144004a9/c3888efdcb7338f6?hl=en#c3888efdcb7338f6 About creating an Email function to email authors when the Review Date has expired on their page. I've managed to now achieve a significant proportion of the work by writing out the details to an XML file and reading them back. However I'm a little stuck on Amending...
2
3184
by: Shaurya Vardhan | last post by:
Hi, On Appending a child in XML Node, I am having error, "Run-time exception thrown : System.ArgumentException - The node to be inserted is from a different document context." How to resolve this ? I am attaching image of error message. Thanx & Regards, Shaurya Vardhan
8
1885
by: David Thielen | last post by:
Hi; I need to be able to create a single xml node in utf-8 and do it efficiently as this is called a lot (reason below). What is the best way to do this? I need to end up with a string like "<node attr1='dave'>hi there</node>" where &"<>' are all encoded and chars > 127 are turned into utf-8. I then write this to a file (and what is the best way to do that)?
2
1338
by: Svein Erik | last post by:
I'm creating a program which is to be used in soccer-cups. I'm going to use a xml-file to store some values, the xml file looks like this: <?xml version="1.0" encoding="utf-8" ?> <root> <player> <playername></playername> <matchesPlayed></matchesPlayed> <matchesWon></matchesWon> <matchesLost></matchesLost>
0
962
by: ghafarifar | last post by:
How I appending a new node to am existing xml file? help?
0
8341
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
8851
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
8751
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
7360
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...
0
4176
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...
0
4342
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2759
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
1982
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1739
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.