Question

Just being curious, what would be the best practice to create/generate XLIFF(even simply xml) file (in my case from Excel data) in C# and .NET 4.5? There are several option available but then I would like to know (preferably discuss) which one would be more preferable option in terms of efficiency.

  • XmlDocument
  • XmlWriter & XmlSerializer
  • XDocument
  • XmlTextWriter
  • So on
Was it helpful?

Solution

If you don't need to have the document in memory use XmlWriter (and not XmlTextWriter) if you want to be able to modify the document after loading use XDocument (Linq to Xml)

You may also want to take a look at the post I wrote some time ago comparing different Xml APIs: http://blogs.msdn.com/b/xmlteam/archive/2011/09/14/effective-xml-part-1-choose-the-right-api.aspx

OTHER TIPS

XmlWriter is probably the quickest, but this is like writing assembly when you could be writing in C#. I'd stay away in terms of readability.

I have no love of XmlTextWriter, in my opinion you may as well stick with XmlWriter.

XmlDocument has a lot of overhead. It's just too slow for almost anything you may want to do.

I don't trust or like XmlSerializer. It always seems to fragile to me. A future developer can unwittingly screw things up just by changing a few class definitions.

XDocument is pretty damn good. I've tried to do speed tests of XmlReader/XmlWriter against XDocument before and the two are often so close in performance, that I'd almost recommend XDocument in all cases. I say almost because XmlReader/XmlWriter is still the technically fastest way to read/write xml I've found.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top