Linq or XmlReader

C

CSharper

I have a project where I need to read a decent size (5MB) files for
processing. I have two of them, one of them I need to iterate through
a collection (using Linq) and find associated elements in the other
XML file. Can I use Linq in both the situation (since coding is easy)
or use XMLReader for one and Linq for other? If I remember correctly,
for Linq to work XML has to be loaded in the memory.
Thanks,
 
M

Martin Honnen

CSharper said:
I have a project where I need to read a decent size (5MB) files for
processing. I have two of them, one of them I need to iterate through
a collection (using Linq) and find associated elements in the other
XML file. Can I use Linq in both the situation (since coding is easy)
or use XMLReader for one and Linq for other? If I remember correctly,
for Linq to work XML has to be loaded in the memory.

Yes, LINQ builds an in memory tree model of your XML so its memory
consumption grows with the size of the XML. On the other hand 5MB does
not sound that large these days for parsing files in a Windows desktop
application.

You can also combine XmlReader and LINQ to XML using the XNode.ReadFrom
method:
http://msdn.microsoft.com/en-us/library/system.xml.linq.xnode.readfrom.aspx
 
M

Martin Honnen

CSharper said:
I have a project where I need to read a decent size (5MB) files for
processing. I have two of them, one of them I need to iterate through
a collection (using Linq) and find associated elements in the other
XML file. Can I use Linq in both the situation (since coding is easy)
or use XMLReader for one and Linq for other? If I remember correctly,
for Linq to work XML has to be loaded in the memory.

Yes, LINQ builds an in memory tree model of your XML so its memory
consumption grows with the size of the XML. On the other hand 5MB does
not sound that large these days for parsing files in a Windows desktop
application.

You can also combine XmlReader and LINQ to XML using the XNode.ReadFrom
method:
http://msdn.microsoft.com/en-us/library/system.xml.linq.xnode.readfrom.aspx
 
P

Paul

Why not create a model structure to represent the xml data and create a DAL
using XMLReader. You can then carry out BLL on the model objects when
loaded. There is a good chance you can use the model structure elsewhere
too.

XML is a datasource as much as any database is, even if that XML is the
result of an HTTP POST or FTP.

Also when you are doing set operations you may find a dictionary far easier
to use and probably although I have never tested it far quicker than
constantly iterating though lists for matches. Even if you just create an
index of a list using a dictionary during population of the list.

You may also want to consider integration services on SQL Server. Once the
data is in a temp DB it can probably churn the data far more efficiently
than any code you could write.

Just some alternative options to Linq. Easy code but less performant by a
magnitude.
 
P

Paul

Why not create a model structure to represent the xml data and create a DAL
using XMLReader. You can then carry out BLL on the model objects when
loaded. There is a good chance you can use the model structure elsewhere
too.

XML is a datasource as much as any database is, even if that XML is the
result of an HTTP POST or FTP.

Also when you are doing set operations you may find a dictionary far easier
to use and probably although I have never tested it far quicker than
constantly iterating though lists for matches. Even if you just create an
index of a list using a dictionary during population of the list.

You may also want to consider integration services on SQL Server. Once the
data is in a temp DB it can probably churn the data far more efficiently
than any code you could write.

Just some alternative options to Linq. Easy code but less performant by a
magnitude.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

linq versus BindingSource. 19
LINQ or DataSet? 2
Looking for samples of parsing xml with linq dump to database table 8
Parsing XML 13
linq vs lambda 2
LINQ to XML 2
Linq or dictionary 5
Linq without DBML 2

Top