473,387 Members | 1,650 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Best way to read a 1GB XML file with C#?

Hello all,

I have a 1GB XML file that I need to read once a day and I would like to get
feedback to find out what is the most efficient way to go about reading this
file. The application reading this is in C# and I am using .NET 2.0.

How can I read it without loading it all at once into memory? Will a simple
XmlDocument and a XmlNodeIterator work?

All feedback is extremely appreciated. Thanks!

Johnny
Nov 22 '05 #1
3 18445
Johnny wrote:
Hello all,

I have a 1GB XML file that I need to read once a day and I would like to get
feedback to find out what is the most efficient way to go about reading this
file. The application reading this is in C# and I am using .NET 2.0.

How can I read it without loading it all at once into memory? Will a simple
XmlDocument and a XmlNodeIterator work?

All feedback is extremely appreciated. Thanks!

Johnny


You probably want to use the XmlReader and not load it all into a
document all at once ( although these days, you may have enough memory
to handle a file that large ). Still, I wouldn't do it.

Then you'd basically read it in node by node ( looking for the end node
) for the data your interested in, and store that as XmlNode, then use
it for whatever you want to do with it.

--
Texeme
http://texeme.com

Nov 22 '05 #2
Using XmlDocument or XmlNodeDocument will parse the entire document upon
loading. For large documents you will need a non cached XmlReader, but you
still have to parse the document yourself.

You can consider generating and using an XmlNameTable to increase
performance:
Efficient Techniques for Modifying Large XML Files
By Dare Obasanjo
http://msdn.microsoft.com/library/de...l/largexml.asp

Object Comparison Using XmlNameTable with XmlReader
http://msdn.microsoft.com/library/de...hXmlReader.asp

ok,
aq

"Elementary Penguin" <si*****@hari.krishna> wrote in message
news:BG***************@newsread3.news.pas.earthlin k.net...
Johnny wrote:
Hello all,

I have a 1GB XML file that I need to read once a day and I would like to get feedback to find out what is the most efficient way to go about reading this file. The application reading this is in C# and I am using .NET 2.0.

How can I read it without loading it all at once into memory? Will a simple XmlDocument and a XmlNodeIterator work?

All feedback is extremely appreciated. Thanks!

Johnny


You probably want to use the XmlReader and not load it all into a
document all at once ( although these days, you may have enough memory
to handle a file that large ). Still, I wouldn't do it.

Then you'd basically read it in node by node ( looking for the end node
) for the data your interested in, and store that as XmlNode, then use
it for whatever you want to do with it.

--
Texeme
http://texeme.com

Nov 22 '05 #3
Johnny,
In addition to the other comments, using an XmlReader might be the safest
way, as you only need to read in the section you need.

The following article identifies some new features in .NET 2.0 with Xml that
might help you.

http://msdn.microsoft.com/library/de...sysxmlvs05.asp

Hope this helps
Jay

"Johnny" <Jo****@discussions.microsoft.com> wrote in message
news:72**********************************@microsof t.com...
Hello all,

I have a 1GB XML file that I need to read once a day and I would like to
get
feedback to find out what is the most efficient way to go about reading
this
file. The application reading this is in C# and I am using .NET 2.0.

How can I read it without loading it all at once into memory? Will a
simple
XmlDocument and a XmlNodeIterator work?

All feedback is extremely appreciated. Thanks!

Johnny

Nov 22 '05 #4

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

Similar topics

4
by: Frank Millman | last post by:
Hi all I need to generate potentially large reports from a database, and I want to offer the option of print preview before actually printing (using wxPython). I figure that the best way to...
136
by: Matt Kruse | last post by:
http://www.JavascriptToolbox.com/bestpractices/ I started writing this up as a guide for some people who were looking for general tips on how to do things the 'right way' with Javascript. Their...
7
by: | last post by:
In the beginning we had Ini files. Later we had registery files. Now have xml files and our read-only myapp.config file. My question now, is what is the best way to store and load user and...
4
by: ESPN Lover | last post by:
Below is two snippets of code from MSDN showing how to read a file. Is one way preferred over the other and why? Thanks. using System; using System.IO; class Test { public static void...
10
by: jojobar | last post by:
Hello, I am trying to use vs.net 2005 to migrate a project originally in vs.net 2003. I started with creation of a "web site", and then created folders for each component of the site. I read...
17
by: | last post by:
I have an app that retrieves data from an Access database. At the moment I have the SQL string as a Const in my app. I understand this is not best practice. I don't want the user to have access to...
11
by: Tom | last post by:
I am planning on adding a Preferences form to my application and using the Property Grid to display the preferences to the user. What do you think would be the best way to save these preferences...
3
by: gordon | last post by:
Hi I am looking to store some details about a user's configuration choices, in particular the place where they have installed some data files, the OS that they use, and their Windows user name. ...
4
by: TC | last post by:
Hey All, I have to read .csv files and display them in a DataGridView. Currently, I'm dumping the data into a DataTable but it's causing problems because the engine is automatically converting...
4
by: Brian | last post by:
HI, I have two sets of data, the largest set of data contains 370 rows... both sets only have two columns. I want to be able to distribute the data with my applaction. The other option, would be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
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,...

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.