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 ?