tags:

views:

888

answers:

5

C# XML Reading hanging out

Hi Friends,I have a 100 MB XML File.Got suggestions from linked in that In C# XMLReader is the best for reading XML File..But when i use that reader for reading of size 100 MB XML File,its reading but some times hanging...could any body help how to proceed with XML reader with out stucking..?

A: 

if your file is that big maybe the desing could be wrong. unless you are using the file as a whole Database, i not goinf to recomend to split the files into chunks since it may screw the markup

XML Files approach is:

  • do not require you to store data redundantly.
  • can be accessed via standard XML APIs
  • Data is universally understandable and portable
  • Slow and memory hungry
  • do not allow advanced locking, synchronization and concurrency control
  • do not have any support for transactions

If you want is ease of use and ability to transfer data easily between multiple applications than XML files approach seems right.

If on the other hand you are performance conscious, you should go for database approach.

SqlServer supports for the xml data type and XPath ,XQuery statement.

For details see:

http://technet.microsoft.com/en-us/library/ms175024.aspx

Oscar Cabrero
hi Oscar Cabrero,Thanks for the valueble comments.Here we are not using database.My requirement is i have to pare 100 MB XML File and show it in userinterface very fast.Thanks,sivaramakrishna popuri
sivaramakrishna
A: 

You might first want to look at the design of your application. Must all the data be in the one XML file? Could you segment the data into several files and then load just the one that you needed? Whatever solution you get, processing a 100MB XML file is going to be costly

Conrad
Hi Conard,Thanks for the comment.We have all the data in one XML File.we cant segment as it was already designed for something else...Your suggestions are welcome if you have any...
sivaramakrishna
A: 

Displaying 100MB of XML in a RichTextBox is going to be very costly in terms of memory. Without some extremely clever treatment of this problem, I'd venture that this would take up an antisocially large amount of memory. You might want to consider paging your output to reduce the strain on the RichTextBox.

spender
A: 

Hosam Aly makes a good point is his comment that if you just want to display the XML, there is no real need to parse it.

Something as simple as:

 using(Stream stream = File.OpenRead(xmlFileName)) {
      richTextBox.LoadFile(stream, RichTextBoxStreamType.PlainText);
 }

Note that reading 100MB is still going to take a while. If you really want to make the UI responsive while the XML file is being loaded, you will probably want to take a different approach and use a BackgroundWorker to load your file chunks/lines at a time and insert this into the RichTextBox.

Ants
A: 

I take your premise of using an XMLReader as a meaning you would like to parse the XML in some way. If that is the case, it sounds like you should concern yourself with the following points:

  • How is the data given to the XMLReader? You should aim to load it into memory before passing it to the XMLReader
  • Review your settings in the XMLReaderSettings
  • Be sure that you are able to output for 200 Mb worth of characters to your application without it hanging.
Steen