Click here to Skip to main content
15,892,005 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,

I am reading Data from XML file and my xml file contain more then 10 million rows. My XML file contain duplicate rows. I want to distinct rows from xml and insert it to database.

I have tried to use:
string myXMLfile = System.Configuration.ConfigurationSettings.AppSettings.Get( "ReadFilePath").ToString();

System.IO.FileStream fsReadXml = new System.IO.FileStream(myXMLfile, System.IO.FileMode.Open);
DataSet dsFileRecords = new DataSet();
dsFileRecords.ReadXml(fsReadXml);

DataTable dtUniqRecords = dt.DefaultView.ToTable(true, "ID","Name");

// Insert rows to database from Datatable(dtUniqRecords)


But this method is takes lots of time. Any other methods to get distinct rows?
Posted

The question is not about how you read the file. Parsing it is one thing, finding duplicates is an other one - especially with large dataset. The strategy must depend on what you will do with this data in the future. If this is a one-time task, like find duplicates and forget it (which leads me to suspect serious design flaw), than you might look for some other method, but in general, I suggest following one:
If you already use a local RDBMS, use that if not, chose an embedded edition RDBMS (SQL CE, Firebird embedded, but SQLite would be the best). Let's take SQLite. Create a database and a table with structure meeting the xml record structure, and don't forget to add indexes that will most likely help in finding the record. Now, start parsing the xml, and before inserting the record into the table, issue a select to check if isn't a duplicate. This way, at the and you will have only the unique records in the table. In case of SQLite you have several fine-tuning parameters you can use to optimize this dedicated database for this task. Look here: http://web.utk.edu/~jplyon/sqlite/SQLite_optimization_FAQ.html[^], here: http://www.sqlite.org/pragma.html[^] and probably here too: http://tech.vg.no/2011/04/04/speeding-up-sqlite-insert-operations/[^]
 
Share this answer
 
Refer to this link which explains XmlReader which is the fastest way to read.XmlReader does not load the full XML into memory before using it, which means you can read it from a stream and process it.

XmlReader Class[^]

Regards.. :laugh:
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900