Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to parse very huge XML Files in C#? [duplicate]

Tags:

c#

parsing

xml

I am working with dblp XML files. I actually want to parse the dblp.xml file and want to extract the usefull information for my further processing in some project. And that XML File is very huge (1.1 GB) and I am unable to even open this file.

Kindly guide me if you have C# parser for dblp.xml or you can guide me regarding this, or about how can we parse huge xml files.

like image 351
Bilal Ahmed Yaseen Avatar asked Apr 02 '13 18:04

Bilal Ahmed Yaseen


2 Answers

Use XML reader instead of XML dom. XML dom stores the whole file in memory which is totally useless:

http://msdn.microsoft.com/en-us/library/system.xml.xmlreader.aspx

like image 50
Gergo Szekeres Avatar answered Oct 07 '22 16:10

Gergo Szekeres


You need to use XmlReader

It represents a reader that provides fast, noncached, forward-only access to XML data. Won't load all the data into memory, supposed to be used with large sets of data. Other built in.NET solutions keep the full generated object graph.

XmlReader in action (by Jon Skeet)

like image 44
illegal-immigrant Avatar answered Oct 07 '22 15:10

illegal-immigrant