How to speed up the ReadXML?

J

Jason Huang

Hi,

In my C# Windows Form project, I'm testing comparing using the SqlClient
with the ReadXML method.
The ReadXML method will read 2 .xml files, one is 4K, the other one is 3Mb,
both are on my PC's local drive.
However, I found that it takes approximately 9 seconds for the ReadXML
method, while the SqlClient method is about 2 seconds.
Now I have 2 quesitons here:
1. Is it possible to speed up the ReadXML?
2. When will my PC's erase DataSet's ReadXML memory?

Thanks for help.


Jason
 
C

Carl

Jason,

ReadXML must parse the entire XML document before it can represent it
in a relational-like format, which uses a lot resources for large
documents. The SqlClient method will always be faster. There are a
number of ways to improve performance with XML data, see
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnpag/html/scalenetchapt09.asp,
but I'm not sure these recomendations will help ReadXML.

Once your DataSet goes out of scope or you call Dispose() it will be
marked for garbage collection and the memory will be reclaimed.

-Carl
 
N

Nicholas Paldino [.NET/C# MVP]

It should be noted that SqlClient will not always be faster than reading
an XML document. It depends on the size of the data, the structure, etc,
etc. Also, you have to consider the other factors in play here, namely, is
it appropriate to store this information in the database as opposed to a
config file which is most likely stored locally?

On top of that, it should be noted that calling Dispose on the DataSet
will not mark it for garbage collection. The Dispose pattern on the DataSet
is inherited from the MarshalByValueComponent class, and the DataSet does
nothing to override that behavior. The only thing that calling Dispose on
the DataSet does is fire the Disposed event.

Hope this helps.
 

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

Top