Jimmy Collins
Jimmy Collins

Reputation: 3304

Quickest/best way to read XML

I need to read potentially large (~300mb) XML files, and edit some of the nodes. Basically I need to:

What's the best way to approach this in C#? Which XML classes should I use to find and edit the nodes I need to change?

TIA

Upvotes: 6

Views: 1544

Answers (4)

vtd-xml-author
vtd-xml-author

Reputation: 3377

VTD-XML is the only XML parsing lib that supports a feature called incremental update. It is also memory efficient and performant. But it requires you to download it as a third party lib.

Upvotes: 4

vlad
vlad

Reputation: 4778

you can use Linq-to-XML. in short, read with XDocument, parse and add data with Linq. This will not be the fastest code, but will probably be the quickest to write.

If you have memory constraints, you will probably have to parse it manually (i.e. load only part of it in memory, process that part, replace it in the file)

Upvotes: 3

Benny Jobigan
Benny Jobigan

Reputation: 5304

If it's a fairly simple operation similar to find-and-replace, you could try treating it as a normal text file instead of an xml document. I imagine that might be faster than all the xml parsing.

Upvotes: 2

Jon Egerton
Jon Egerton

Reputation: 41559

From my experience of transforming some very large (2GB+) xml files (don't ask!) I found xsl transforms to be the quickest - The engines involved are heavily optimised for such tasks, compare to any manual looping etc you might try.

Upvotes: 3

Related Questions