472,989 Members | 2,994 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

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 2399
Hi Jonathan,

You can use XmlTextReader and XmlTextWriter. They're very fast. You can
programmatically 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/
frlrfsystemxmlxmltextwriterclasstopic.asp
http://msdn.microsoft.com/library/de...us/cpref/html/
frlrfsystemxmlxmltextreaderclassnodetypetopic.asp
http://msdn.microsoft.com/library/de...us/cpref/html/
frlrfsystemxmlxmltextwriterclasstopic.asp

The following are some sample code:

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

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

writer.Formatting = Formatting.Indented;

writer.WriteStartDocument();

// Read the file and display each of the nodes.
while (reader.Read())
{
switch (reader.NodeType)
{
case XmlNodeType.Element:
writer.WriteStartElement(reader.Name);
writer.WriteAttributes(reader,false);
if (reader.IsEmptyElement)
writer.WriteEndElement();
break;
//You can have some test statement here to append nodes
if (reader.Name == "????")
{
//TODO: do something
}
case XmlNodeType.Text:
writer.WriteString(reader.Value);
break;
case XmlNodeType.Whitespace:
case XmlNodeType.SignificantWhitespace:
writer.WriteWhitespace(reader.Value);
break;
case XmlNodeType.CDATA:
writer.WriteCData(reader.Value);
break;
case XmlNodeType.Comment:
writer.WriteComment(reader.Value);
break;
case XmlNodeType.EntityReference:
writer.WriteEntityRef(reader.Name);
break;
case XmlNodeType.EndElement:
//You can have some test statement here to append nodes
if (reader.Name == "????")
{
//TODO: do something
}

writer.WriteEndElement();
break;
}
}

writer.WriteEndDocument();
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****@00000000homtail.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.public.dotnet.xml
NNTP-Posting-Host: 82-41-12-138.cable.ubr02.edin.blueyonder.co.uk 82.41.12.138Path: TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFT NGP10.phx.gbl
Xref: TK2MSFTNGXA01.phx.gbl microsoft.public.dotnet.xml:7123
X-Tomcat-NG: microsoft.public.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
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...
1
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...
17
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...
4
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...
2
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...
2
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...
8
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...
2
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>...
0
by: ghafarifar | last post by:
How I appending a new node to am existing xml file? help?
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
4
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...
3
SueHopson
by: SueHopson | last post by:
Hi All, I'm trying to create a single code (run off a button that calls the Private Sub) for our parts list report that will allow the user to filter by either/both PartVendor and PartType. On...

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.