0

I want read a large dblp.xml file in c# because its a huge file, which can not load into memory. I query to take some data from this huge file. how can i read/get it.

<phdthesis mdate="2012-04-18" key="phd/tw/Chang2008">
  <author>Fengming Chang</author>
  <title>Learning accuracy from limited data: </title>
  <year>2008</year>
  <school>Tainan, National Cheng Kung Univ.</school>
  <pages>1-67</pages>
  <isbn>978-3-8364-8603-3</isbn>
  <note type="dnb">http://d-nb.info/989267156</note>
</phdthesis>

How can i read from a huge xml file using c# not loading all xml file in memory?

Iłya Bursov
  • 23,342
  • 4
  • 33
  • 57

1 Answers1

0

In .NET 4 - for best performance you should be using XmlReader as it streams the document instead of loading the full thing into memory.

The code you refer to uses XmlReader for the actual querying so should be reasonably quick on large documents.

Sample Code

var reader = XmlReader.Create(filename);
reader.WhitespaceHandling = WhitespaceHandling.None;
while (reader.Read())
{
    // your code here.
}
Cody Gray - on strike
  • 239,200
  • 50
  • 490
  • 574
Yasser Shaikh
  • 46,934
  • 46
  • 204
  • 281
  • There is a reason we block LMGTFY links. Having to obfuscate the link should have been your first clue. If it's a poor quality question, just don't answer it. If it's a duplicate, just vote to close. – Cody Gray - on strike May 06 '14 at 07:56
  • Okay. My bad. Cudnt resist to put it though. Anyways will be careful hence forth :) – Yasser Shaikh May 06 '14 at 08:04