December 7th, 2009, 06:05 PM
Parsing XML in C# Dot Net
Using VS2008, .net 3.5
I'm working on an app that will potentially parse thousands of XML files. What I'm working on is actually a rewrite of a Java application that I've already written and has been in production for some time now. Everything I've read says that the .net implementation of DOM and SAX/pull parsing is slower than Java, but there performance hit that I'm seeing is ridiculous.
In benchmarking tests that I've run with my previous Java implementation vs. two implementations of .net parsing are stark and disappointing. I'm hoping that I'm doing something wrong and that all the 50lb heads in this forum might be able to save the day. A benchmark I ran today had my Java implementation finish parsing at 15 seconds where my best .net implementation ran for 95 seconds.
The two implementations I've tried include using
1) ...xmlDoc.GetElementsByTagName(...) and a bunch of if statements to grab the nodes I'm looking for.
2) using LINQ to query the xml file(s) for the info I need to grab.
As you might assume, LINQ is the faster of the two implementations. I just started down a third route of trying XMLTextReader, and just reading through the entire file was still slow (that's not doing anything with the data).
I've been searching the interwebs to no avail...Anybody have a definitive answer on what the FASTEST XML parsing implementation is? I'm open to third-party solutions as well. I'm at my wits end on this...
December 7th, 2009, 06:48 PM
Re: Parsing XML in C# Dot Net
http://msdn.microsoft.com/en-us/vstudio/aa700841.aspx. Don't believe everything you read, especially if it relates to older versions of the software you're using.
Everything I've read says that the .net implementation of DOM and SAX/pull parsing is slower than Java,
If you want help you're going to have to show the C# and Java code you used for your fastest implementation. A 1.86ghz core2duo machine can chomp xml at a rate of > 76MB/sec using XmlReader. If you can't match that on similar hardware, something is going horribly wrong.
For all your .NET bittorrent needs
NOTE: My code snippets are just
snippets. They demonstrate an idea which can be adapted by you to solve your problem. They are not 100% complete and fully functional solutions equipped with error handling.
Tags for this Thread
Click Here to Expand Forum to Full Width
This is a Codeguru.com survey!