开发者

C# XmlDocument for small XML files - weight / performance

I wondering about sense of using XmlDocument class to processing a small XML files. If during the XML file is loading, XmlDocument creates a whole set of object-oriented structure for all XML elements and their relationship, theoretically for small xml files, there is a slight performance d开发者_运维问答ecrease and resources consumption and in the same time, we have clear and easy data management.

I read many articles about the processing of XML files - usualy people suggest using lightweight solutions like XmlTextReader instead XmlDocument for fast forward reading - even for small files. Am I wrong or XmlDocument is not so bad?


You will have to measure it, but even for a small file the I/O will be the main factor.

And how do you want to use the file? That is far more important.

I would never consider an Xml(Text)Reader for small files. The only thing it would optimize is memory usage.


In reply to the comment:

For 100kB, just use XDocument or the older XmlDocument

You can get all your nodes with XElement.Descendants("TAG")

  var xmlData = XDocument.Load(filename);
  var tags = xmlData.Descendants("TAG");
  foreach(var tag in tags) ...


In my opinion this is personal preference. Personally speaking I have used Xmldocument over XmlTextReader as I find it easier to work with. I have moved to use LINQ to Xml now as it uses XDocument which allows easier reading of nodes and elements

have a read of this 5 minute introduction to LINQ to Xml as it is a lot easier to use and to read http://www.hookedonlinq.com/LINQtoXML5MinuteOverview.ashx

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜